Hi,
are rename scripts capable of using dialogs? I want to pop up a dialog with some radio buttons and an edit control for choosing some options and rename the files appropriately.
Is there an example script available?
cu,
Michael
Hi,
are rename scripts capable of using dialogs? I want to pop up a dialog with some radio buttons and an edit control for choosing some options and rename the files appropriately.
Is there an example script available?
cu,
Michael
I think they can, but if the aim is to use the script with the Rename dialog, then scripts can add extra inputs to the main dialog, which is better than popping up a second dialog (and also allows the preview to work).
If the aim is to use the script without the Rename dialog, then writing it as a normal script which renames the files itself, rather than as a rename script which runs inside of the Rename dialog (whether it appears or not) may make more sense.
Thanks Leo for you reply!
I already added an edit to the standard rename dialog which works perfectly btw. , however, I start renaming from the toolbar using my script without any interaction and from time to time the default value must be beforehand.
Right now this means I have to open the standard dialog, enter a new value and start renaming the files.
Quite a bit slow for certain purposes, hence I though about adding a popup that reminds or forces me to think about the default value.
Anyway, maybe I can just use a simple standard popup for entering an integer value, is this an option to go? So there is no need for creating a complex dialog with the dialog editor?
Is this object available within a JScript, too: https://www.gpsoft.com.au/help/opus12/index.html#!Documents/Scripting/simpledialogsandpopupmenus.htm
Replying myself. So I did a little more coding and finally got this code which pops up a dialog to enter a value.
Unfortunately this popup appears for each file selected in the lister but I tried to accomplish two things with the code:
For 1) I tried to set the entered value back to the custom property as well as for 2) and remove the appropriate checkbox - to no avail of course because getNewNameData.custom is read-only.
function OnGetNewName(getNewNameData)
{
var name = getNewNameData.newname_stem_m;
var ext = getNewNameData.newname_ext_m;
var yrs = getNewNameData.custom.years;
if (getNewNameData.Item.Is_Dir)
return name;
if (getNewNameData.custom.popup)
{
var dlg = DOpus.Dlg;
dlg.window = DOpus.Listers(0);
dlg.message = "Enter Years of Warranty";
dlg.title = "Warranty";
dlg.buttons = "OK|Cancel";
dlg.defvalue = yrs;
dlg.max = 2;
var ret = dlg.show;
if (ret == 0)
return name;
//fetch user input
yrs = dlg.input;
if (yrs > 0)
{
//save user input and prevent popup from appearing again
//getNewNameData.custom.years = yrs;
//getNewNameData.custom.popup = false;
}
}
if (yrs > 0)
{
var warranty = String(name).match(/\[\d+.*\]/);
if (warranty)
name = name.replace(warranty,"");
else
name = name + " ";
name = name + "[" + yrs +" Jahre Garantie]";
}
return name + ext;
}
function OnGetCustomFields(getFieldData)
{
getFieldData.fields.popup = true;
getFieldData.field_labels("popup") = "Show Popup";
getFieldData.fields.years = 2;
getFieldData.field_labels("years") = "Warranty in Years";
}
Use global variables for that. They won't be reset between each file.
I played with global vars to no avail, used this script, but either I get a freeze or the popup appears many times.
Guess I did not fully understand the usage of global vars, right?
function OnGetNewName(getNewNameData)
{
var name = getNewNameData.newname_stem_m;
var ext = getNewNameData.newname_ext_m;
var yrs = 2;
if (DOpus.Vars.Exists("WarrantInYears"))
yrs = DOpus.Vars.Get("WarrantInYears");
if (!DOpus.Vars.Exists("WarrantyYearsPopup"))
{
DOpus.Vars("WarrantYearsPopup").persist = true;
DOpus.Vars.Set("WarrantYearsPopup", true);
}
if (getNewNameData.Item.Is_Dir)
return name;
if (DOpus.Vars("WarrantyYearsPopup") = true)
{
var dlg = DOpus.Dlg;
dlg.window = DOpus.Listers(0);
dlg.message = "Enter Years of Warranty";
dlg.title = "Warranty";
dlg.buttons = "OK|Cancel";
dlg.defvalue = yrs;
dlg.max = 2;
var ret = dlg.show;
if (ret == 0)
return name;
DOpus.Vars.Set("WarrantYearsPopup", false);
//fetch user input
yrs = dlg.input;
if (yrs > 0)
{
DOpus.Vars("WarrantInYears") = yrs;
}
}
if (yrs > 0)
{
var warranty = String(name).match(/\[\d+.*\]/);
if (warranty)
name = name.replace(warranty,"");
else
name = name + " ";
name = name + "[" + yrs +" Jahre Garantie]";
}
return name + ext;
}
function OnGetCustomFields(getFieldData)
{
}
I forgot about the Opus variables that can be global to the process. Sorry, I didn't mean those, but I can see why it was confusing!
If you declare one or more normal JScript vars in your script, before the function body, anything you put in there will persist between function calls. So you can store a flag or the values from the first time the dialog opens in there, and then use them the next time the function is called.
e.g.
var x = "";
function OnGetNewName(getNewNameData)
{
if (x == "")
{
// ... ask for x ...
x = ...;
}
// ... use x ...
}
Unfortunately this gives me a x not defined in above line. Of course I changed the vars name to my needs, but this does not change the error message.
Sorry, foget it! This works perfectly, had a typo in my variable name
Edit: not entirely perfect yet, because sometimes it happens that my popup disappears into the background and the progress dialog pops up. I cannot abort this action anymore and have to terminate DO with the task manager.
Edit2: remove the this last line from my script and so far no freeze again.
var dlg = DOpus.Dlg;
//dlg.window = DOpus.Listers(0);
Let's see how this performs in live scenarios later on.