Copy link to clipboard
Copied
I am prompting the user asking how many volumes their document has based on that input I would like a dynamic control panel. The user will be prompted to type in how many "volumes" they have. So if they enter 4 then it will create a user panel requesting them to fill in 4 different panel information text fields.
Here is a mock up...
Here is my best attempt at the code....that doesn't work....
var howManyVols = prompt("How many volumes?", "", "Number of Volumes");
howManyVols = parseFloat(howManyVols);
var volArray = [];
for (var i = 0; i < howManyVols; i++){
volArray.push(i+1);
}
function multiVolInfoGUI() {
var gui = new Window("dialog", "Volume Information");
gui.alignChilren = ["fill", "fill"];
gui.orientation = "column";
var panelGroup = createGroup(gui, "row");
var partNumVols = [];
var changeLevelVols = [];
// Left Panel Group Fields
var leftInfoPanel = createPanel(panelGroup, "");
for (var i = 0; i < volArray.length; i++){
partNumVols[volArray] = createTextField(leftInfoPanel, "Volume " + (i+1) + " Part Number:", "XXX-XXXX");
changeLevelVols[volArray] = createTextField(leftInfoPanel, "Volume " + (i+1) + " Change Level:", "XX");
}
}
var buttons = createGroup(gui, "row");
// Confirm button
var confirmBtn = createButton(buttons, "Confirm", function()
}
var gui = multiVolInfoGUI();
gui.show();
and the functions....
// Function to build panel
function createPanel(parent, title) {
// Create Panel
var panel = parent.add("panel", undefined, title);
panel.orientation = "column";
// Return panel
return panel;
}
// Function to create button
function createButton(parent, title, onClick) {
// Create Button
var button = parent.add("button", undefined, title);
if (onClick !== undefined) button.onClick = onClick;
// Return button
return button;
}
// Function to create field in panel
function createTextField(parent, title, content) {
// Create a group for title and field
var group = createGroup(parent, "column");
group.alignChildren = 'left';
// Create title
var title = group.add("statictext", undefined, title);
var field = group.add("edittext", undefined, content);
field.preferredSize = [200, 23];
// Return the field as its all you'll use
return field;
}
// Function to organize the panel layout
function createGroup(parent, orientation) {
// Create Group
var group = parent.add("group");
group.orientation = orientation;
// Return Group
return group;
}
Message was edited by: Corey Wolfe ooops....wrong code
Copy link to clipboard
Copied
There are several issues at play here.. Many typos and bugs jump out right away.
On line 27, you try to create a confirm button, but your function definition is incomplete and there is no closing paren for the createButton function call.
on line 31 you set the variable equal to the return value of the function multiVolInfoGui(); This function does not return a value, so the variable 'gui' is left undefined.
because gui is undefined, errors occur in your functions because the parameter 'parent' is undefined.
I'm sure there's more, but it's hard to keep debugging without going through and fixing each problem as i find it. You've got a really good start here, and you're doing a great job abstracting the process of creating elements for your GUI. You just have some implementation issues. I don't believe you can return a window object as you attempt to do in the multiVolInfoGui() function. You should declare the variable 'gui' as a script global variable, then treat multiVolInfoGui() as a void function that simply adds children to the global window object.
Am i making any sense?
Copy link to clipboard
Copied
This is super helpful! I am not a programmer.... So I try to find code and modify it to the best of my ability. So... info like you have stated is helpful with learning. I will continue working on this and see if I can fix typos and such. Thank you williamadowling
Copy link to clipboard
Copied
Not a problem. I'm glad to help. I wasn't a programmer either until i received TONS of help from people on this forum, so if i can do my part to pay that forward, i'll gladly do so.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now