Copy link to clipboard
Copied
I'm trying to add a way to update a subitem in a listbox using editText
I have two columns, Column one is to reference my layer, Column two is to reference a value.
My array will always sequentially go in order, but my value will always change. So I want to include to the expression below. That if I fill out
var input = win.add ("edittext");
input.active = true;
then hit the add item button, it will at the item plus the sub item we have given a value in editText
it will add it to column two if I hit add item.
Then say I got the number wrong and I want to change that value. If I highlight the row. Refill out
var input = win.add ("edittext");
input.active = true;
then hit the insert button.
It will update it.
I've seen scripts that just us insert via editText and scripts that use just arrays. I haven't found an example that allows the two, but so far i have this that i've patched with other peoples code. I tried addingsubItems[0].text in relevant areas, but it just crashed.
var testArr = [];
startGUI();
function startGUI() {
// Main Window
var win = new Window( "palette", "Test Listbox", undefined, { resizeable:true } );
win.orientation = "column";
win.alignChildren = ["fill", "fill"];
// Listbox Group
var grpListbox = win.add('group');
grpListbox.alignChildren = ['fill', 'fill'];
var myListbox = addListBox (grpListbox, testArr);
// add ListBox
function addListBox(container, testArr) {
var listbox = container.add("listbox", undefined, testArr,
{
numberOfColumns: 2,
showHeaders: true,
columnTitles: ['Bar', 'Value']
});
return listbox;
}
var input = win.add ("edittext");
input.active = true;
var b = win.add ("button", undefined, "Insert", {name: "ok"});
// BTN: Add Items To Array
var addItem = win.add("button", undefined, "Add Item");
addItem.onClick = function() {
testArr.push ('Bar' + " " + (testArr.length + 1));
grpListbox.remove(grpListbox.children[0]);
myListbox = addListBox (grpListbox, testArr);
win.layout.layout(true);
//updateListboxArray(myListbox);
//$.writeln (testArr.length + " " + myListbox.items.length);
}
// BTN: Clear Listbox
var removeAllItems = win.add("button", undefined, "Clear Listbox");
removeAllItems.onClick = function() {
// Clear the array
testArr = [];
updateListboxArray(myListbox);
}
// Update listbox items
function updateListboxArray(listbox) {
// Clear listbox first
listbox.removeAll();
// Create new listbox items from array
var i = 0;
while (listbox.items.length < testArr.length) { listbox.add ("item", testArr); i++;}
}
// Quit BTN
win.quitBtn = win.add("button", undefined, "Close");
win.quitBtn.onClick = function() {
win.close();
}
// Window Settings
win.onResizing = function () { this.layout.resize(); };
win.onShow = function () { win.layout.resize(); };
win.center();
win.show();
}
I know in theory that it works, as I tried changing a paragraph to this and this works to add editText, I just can't seem to combine the two with a subitem.
// BTN: Add Items To Array
var addItem = win.add("button", undefined, "Add Item");
var input = win.add("editText", undefined)
addItem.onClick = function() {
testArr.push (input.text);
grpListbox.remove(grpListbox.children[0]);
myListbox = addListBox (grpListbox, testArr);
win.layout.layout(true);
//updateListboxArray(myListbox);
//$.writeln (testArr.length + " " + myListbox.items.length);
}
With a litte messing around today I managed to resolve it. Thanks UQg, you pointed me in the right direction when I thought I already was. So i decided to start from scratch and rebuild and I now have it working. Next, I need to add a button to clear the Listbox and a button to apply the value to my layer that is labelled Bar1, Bar2 etc.
// Window
var w = new Window ("palette", "Title", undefined, {resizeable:true});
var testArr = [];
//Listbox
var myList = w.add ("listbox", [0,0,200,150], [], {
a
...Copy link to clipboard
Copied
The syntax to add items to a bicolumn listbox is :
myListBox.add("item", col1String).subItems[0].text = col2String;
And for more columns:
var x = myListBox.add("item", col1String);
x.subItems[0].text = col2String;
x.subItems[1].text = col3String;
// etc
You can also set the value for the 'columnWidths' creation property so that the listbox is not created with ridiculously small size, for instance:
columnWidths: [100, 300],
Xavier
Copy link to clipboard
Copied
I understand what you've said and thank you for the quick response.
The issue I am having is my listbox needs to use an array for column one and a editable text box for column two. My example below is what the end result would look like, but 'Value' can be altered.
Bar (Column 1) | Value (Column 2)
Bar 1 | 75
Bar 2 | 50
Bar 3 | 66
Bar 4 | 24
Bar 5 | 86
I can get the above code to add via the edit text, but won't include the array. Or I can use the array but I can't get the editable text to work, when I include for example what you have put x.subItems[0].text = col2String; into the equation, nothing works.
I needs Column 1 to work as an array when I hit Add Item, because I want that part to be automated, then my script will know which layer it belongs to in my after effects project, but because you may want 1 or 20, I don't want the clutter of 20 rows when you may only want 3, hence the Add Item button
But value though needs to be changeable via 'input.text'.
I'm probably best off starting from scratch again, but that is what I'm trying to accomplish
Copy link to clipboard
Copied
With a litte messing around today I managed to resolve it. Thanks UQg, you pointed me in the right direction when I thought I already was. So i decided to start from scratch and rebuild and I now have it working. Next, I need to add a button to clear the Listbox and a button to apply the value to my layer that is labelled Bar1, Bar2 etc.
// Window
var w = new Window ("palette", "Title", undefined, {resizeable:true});
var testArr = [];
//Listbox
var myList = w.add ("listbox", [0,0,200,150], [], {
alignment: ['top','left'],
multiline:true,
multiselect:true,
numberOfColumns:2,
showHeaders: true,
columnTitles: ['Bar','value']
});
var input = w.add ("edittext");
input.active = true;
var b = w.add ("button", undefined, "Insert", {name: "ok"});
b.onClick = function () {
insert_item (myList, input.text);
input.text = "";
input.active = true;
}
// Allows more items to be added, otherwise you can only go up to two rows.
function insert_item (list_obj, new_item)
{
var new_item = testArr.push ((testArr.length + 1));
var myItem = list_obj.add ("item", "Bar" + " " + new_item);
myItem.subItems[0].text = (input.text);
}
w.show();
Copy link to clipboard
Copied
How can I get the value of all subitems?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now