Copy link to clipboard
Copied
I've got a UI dialog written and I included a button for "more options". This button makes available options that are rarely needed (so i didn't want them available all the time so they could accidentally be changed).
What I tried to do was have that button's onClick function close the dialog, and then re-run the function that calls the dialog and feeds it a different argument.
The problem is, when i click the more options button, it doesn't close the original dialog, it just creates a new instance on top of it. The dialog doesn't actually close until the full script finishes executing... How do I do what I'm trying to do?
Here's the function that creates my UI dialog..
function arguments are:
info = garment's information layer. this layer holds the textframes that will be altered by this dialog.
opts = whether or not to include textFrames that are typically static in nature and shouldn't be changed unless there are extenuating circumstances.
opts is set to false upon initial execution and will only be "true" after the user clicks the "more options" button in the dialog.
//firstFunction Function Description
//create a scriptUI dialog to prompt user for input of all textFrames on the info layer for the current document;
function createDialog(info,opts)
{
//create a new dialog
var title = "Enter the info for " + info.parent.name;
var w = new Window("dialog", title);
w.alignChildren = "left";
var topTxt = w.add("statictext", undefined, "Enter the appropriate information below:");
var descTxt = w.add("statictext", undefined, "Change the fields if necessary. Otherwise, leave them as they are.")
var framesAdded = [];
var frameNames = [];
//loop the textFrames and create a group for each
for(var txt = info.textFrames.length-1;txt >-1; txt --)
{
var thisFrame = info.textFrames[txt];
if(!opts && (thisFrame.name == "Garment Code" || thisFrame.name == "Garment Description" || thisFrame.name == "Fabric Type"))
{
continue;
}
else if(opts && thisFrame.name == "Fabric Type")
{
continue;
}
var newGroup = w.add("group");
if(thisFrame.name.indexOf("rder") > -1)
{
//thisFrame is the order number and team name
var onContents = thisFrame.contents.substring(0,thisFrame.contents.indexOf(" "));
var onFrameTxt = newGroup.add("statictext", undefined, "Order Number");
framesAdded["Order Number"] = newGroup.add("edittext", undefined, onContents);
framesAdded["Order Number"].characters = 20;
framesAdded["Order Number"].alignment = "right";
frameNames["Order Number"] = "Order Number";
var newNewGroup = w.add("group");
var tnContents = thisFrame.contents.substring(thisFrame.contents.indexOf(" ") +1, thisFrame.contents.length)
var tnFrameTxt = newNewGroup.add("statictext", undefined, "Team Name");
framesAdded["Team Name"] = newNewGroup.add("edittext", undefined, tnContents);
framesAdded["Team Name"].characters = 20;
frameNames["Team Name"] = "Team Name";
}
else if(thisFrame.name == "Mockup Initials")
{
var miContents = thisFrame.contents.substring(0, thisFrame.contents.indexOf(" "));
var frameTxt = newGroup.add("statictext", undefined, thisFrame.name);
framesAdded[thisFrame.name] = newGroup.add("edittext", undefined, miContents);
framesAdded[thisFrame.name].characters = 20;
frameNames[thisFrame.name] = thisFrame.name;
}
else
{
var frameTxt = newGroup.add("statictext",undefined, thisFrame.name);
framesAdded[thisFrame.name] = newGroup.add("edittext", undefined, thisFrame.contents);
framesAdded[thisFrame.name].characters = 20;
frameNames[thisFrame.name] = thisFrame.name;
}
}
//add submit and cancel and more options buttons
var btnGroup = w.add("group");
var submit = btnGroup.add("button", undefined, "Submit");
submit.onClick = function()
{
for (var fa in framesAdded)
{
var thisFrame = framesAdded[fa];
var frameName = frameNames[fa];
//if this frame is the mockup initials frame, get the date and append it to the contents
if(frameName == "Mockup Initials")
{
var date = getDate();
info.textFrames[frameName].contents = thisFrame.text + " " + date;
}
else if(frameName == "Order Number")
{
info.textFrames["Order Number"].contents = thisFrame.text + " " + framesAdded["Team Name"].text
}
else if(frameName == "Team Name")
{
continue;
}
else
{
info.textFrames[frameName].contents = thisFrame.text;
}
}
w.close();
}
var cancel = btnGroup.add("button", undefined, "Cancel");
cancel.onClick = function()
{
w.close();
}
if(!opts)
{
//button to open up the ability to change generally static text frames such as garment description and garment code
var moreOptions = btnGroup.add("button", undefined, "More Options");
moreOptions.onClick = function()
{
w.close();
createDialog(info,true);
}
}
else
{
//button to close the ability to change generally static text frames
var lessOptions = btnGroup.add("button", undefined, "Less Options");
lessOptions.onClick = function()
{
w.close();
createDialog(info,false);
}
}
w.show();
}
I think something about dialogs and how they close makes it do this for you when you try to launch one and hope to close the previous one.
Instead, how would you like to change up your existing dialog dynamically?
This code here uses the layout.layout(true) command to fit the window when you've added or removed something.
#target illustrator
function test(){
function myWindow(){
var w = new Window("dialog", "Test");
var label = w.add("statictext", undefined, "Experiment");
var checkBox = w
...Copy link to clipboard
Copied
I think something about dialogs and how they close makes it do this for you when you try to launch one and hope to close the previous one.
Instead, how would you like to change up your existing dialog dynamically?
This code here uses the layout.layout(true) command to fit the window when you've added or removed something.
#target illustrator
function test(){
function myWindow(){
var w = new Window("dialog", "Test");
var label = w.add("statictext", undefined, "Experiment");
var checkBox = w.add("checkbox", undefined, "Show Extra Options");
var optElem = null;
var grp = w.add("group", undefined, "");
var grp_1 = grp.add("group"); // little trick here: put at least 2 elements inside a group, or it will not shrink when the inner element is dynamically removed
var btnOk = w.add("button", undefined, "Ok");
checkBox.onClick = function(){
if(this.value){
optElem = grp.add("dropdownlist", undefined, ["Choose Option", "Option 1", "Option 2", "3rd Option"]);
optElem.selection = optElem.items[0];
w.layout.layout(true);
} else {
optElem.parent.remove(optElem);
optElem = null;
grp.hide();
grp.show();
w.layout.layout(true);
}
}
if(w.show() == 2){
return null;
} else {
if(optElem == null){
return "Options were not activated";
} else {
return optElem.selection.text;
}
};
};
var res = myWindow();
if(res != null){
alert(res);
}
};
test();
Copy link to clipboard
Copied
ok. So this wasn't exactly what i needed, but it lead me in the right direction. I had some trouble with it because the groups/statictexts/edittexts i was adding were being added dynamically so it got confusing when trying to call certain groups by name.
I ended up just creating all of the groups that might be necessary and setting the "disabled" property conditionally. This way the user can see them but they're not editable until the more options button is pressed.
It's not perfect, but i got there. Thanks for your help yet again, Silly-V
Copy link to clipboard
Copied
Sounds like you found your own way. Other than the enabled property, you can do visibility to hide certain elements.
I actually prefer this approach to using tab groups, because tab groups show up all sorts of different on all different versions, so instead I use radio buttons to show and hide groups which are in a "stacked" orientation.
Copy link to clipboard
Copied
I tried using the visibility method as well, but i didn't like that it left a gap. The space was still allocated for the group even if the group was hidden. so it looked sloppy