Copy link to clipboard
Copied
Let's say I have several repeated elements in my window. Would it be possible to use a for or while loop to create these elements and then assign each of them different names that can be accessed by other parts of the script? The bold section of the statement is extremely important.
Here's some example code. I'd prefer not make 24 of these and change all the values by hand when there's a clear formula for it:
dlg.BCV_Resolution_Text_1 = dlg.add('statictext',[BCV_Dropdown_x_Position(4),BCV_Dropdown_y_Position(1),BCV_Dropdown_x_Max(5),BCV_Dropdown_y_Max(2)], BCV_Resolution_Function(dlg.Dropdownlist1.selection+0));
dlg.Dropdownlist1.addEventListener ("change", function (j) {BCV_If_Exists(dlg.Dropdownlist1.selection+0,0);});
dlg.BCV_Resolution_Text_2 = dlg.add('statictext',[BCV_Dropdown_x_Position(4),BCV_Dropdown_y_Position(2),BCV_Dropdown_x_Max(5),BCV_Dropdown_y_Max(3)], BCV_Resolution_Function(dlg.Dropdownlist2.selection+0));
dlg.Dropdownlist2.addEventListener ("change", function (j) {BCV_If_Exists(dlg.Dropdownlist2.selection+0,1);});
dlg.BCV_Resolution_Text_3 = dlg.add('statictext',[BCV_Dropdown_x_Position(4),BCV_Dropdown_y_Position(3),BCV_Dropdown_x_Max(5),BCV_Dropdown_y_Max(4)], BCV_Resolution_Function(dlg.Dropdownlist3.selection+0));
dlg.Dropdownlist3.addEventListener ("change", function (j) {BCV_If_Exists(dlg.Dropdownlist3.selection+0,2);});
I'd rather just have a for loop just the first two lines of code, but I don't know how I would change the "dlg.BCV_Resolution_Text_#" to a different value with each iteration. It's the same problem for "dlg.Dropdownlist#".
Copy link to clipboard
Copied
Yes, you can. you need to create an array for the controls and use that rather than the normal dlg.BCV... that you have in your above script. The issue is that to reference the control items, you have to use the array then select the proper array item number to access that control.
Here's an example I created that is along the lines of the batch renumber ui. The user can keep adding lines of text to be inserted into the border of an image. So it uses an array to keep track of the control elements.
Copy link to clipboard
Copied
I'm not quite sure that I understand exactly how that would work. Would you mind providing me with a small amount of example code so I can get a feel for how it would work?
Copy link to clipboard
Copied
Here's a short sample that creates a UI with 4 groups, each containing a checkbox that turns off and on the dropdownlist. In the on click function, you have to refer to the control using "this" and any other control in relation to "this". So the dropdownlist is the second control in the group, so to enable it you would have to refer to it as the second child of the parent group or this.parent.children[1].
var ckArray = new Array();
var dpArray = new Array();
var gpArray = new Array();
var dpList = ['Mon','Tues','Wed','Thur','Fri','Sat','Sun'];
var dlg = new Window('dialog','Array Test');
for(var i=0;i<5;i++){
gpArray = dlg.add('group');
ckArray = gpArray.add('checkbox',undefined,'Enable Dropdownlist');
ckArray.value = true;
dpArray = gpArray.add('dropdownlist',undefined,dpList);
ckArray.onClick = function(){
if(this.value){this.parent.children[1].enabled = true}
else{this.parent.children[1].enabled = false}
}
}
dlg.show()