Good day! I have a script that does some work based on data from csv files. When working with a script, a user can upload several files sequentially (i.e., after finishing working with one file, I need to make it so that the user can load another without closing the script window). The csv files have a different structure and a different number of fields (this is controlled by the user) - it seemed to me convenient to show them using a listbox with headers. Before the user specifies the file, I open the form with an empty listbox object (just to reserve a place for it in the form): After reading and processing the csv file, I create a new listbox object using the buildList() function. To do this, I delete the previously created testList object from the form, then load a new one in its place. And at this moment i have a problem with ScriptUI: If I do not delete the object, then the listbox will display normally (but old instances will be preserved): It is clear that i can rewrite the function so that for each csv file a new instance of the window is loaded in which a listbox with the necessary parameters will be immediately generated, but in my case this is inconvenient for the user. I trying to understand - is this a bug of ScriptUI or am I doing something wrong? (the example is simplified, just to demonstrate the problem) #target photoshop
var parsedCSV = [["TestField1", "TestField2", "060", "070", "080", "090"], ["TestField3", "TestField4", "145"], ["TestField5", "TestField6", "361"]]
var w = new Window("dialog"),
oldList = w.add('listbox', [0,0,520,200]),
bn = w.add("button", undefined, "test")
bn.onClick = function () {
w.remove (oldList) // problem here, i'm trying also w.remove (w.children[0])
buildList(parsedCSV)
}
w.show ()
function buildList (list) {
var columns=0,
wordLen={}
for (var i=0; i<list.length; i++){
if (list[i].length>columns) columns = list[i].length
for (var n=0; n<list[i].length; n++){
if (wordLen[n]=undefined) {
wordLen[n] = list[i][n].length
} else {
if (list[i][n].length > wordLen[n]) wordLen[n] =list[i][n].length
}
}
}
var props = { numberOfColumns: columns, showHeaders: true, columnTitles: [], columnWidths: [] }
for (var i=0; i<columns; i++){
props.columnTitles.push(String(i+1))
props.columnWidths.push(wordLen[i]*12)
}
newList = w.add("listbox", [0, 0, 520, 200], undefined, props)
for (var i = 0; i < list.length; i++) {
var cur = list[i]
newList.add("item", cur[0])
for (var n = 1; n < cur.length; n++) {
newList.items[i].subItems[n - 1].text = cur[n];
}
}
w.layout.layout(true)
}
... View more