Skip to main content
Dreamer Art
Known Participant
April 3, 2020
Answered

listbox script can't perform multiple delete for CompItem

  • April 3, 2020
  • 1 reply
  • 998 views

Hi,

This is my second post about the Listbox script. I am new here, so please bear me more. In the first post justintaylor help me a lot and I am very grateful to him and all the professionals in the community for their support. I ask the professionals to develop and correct my script to learn more from you.

 

(function(){
    $.win = new Window("palette");
    var win = $.win;
    win.text = "Link";
    win.orientation = "column";
    win.alignChildren = ["center", "top"];
    win.spacing = 10;
    win.margins = 16;
    var listbox1 = win.add("listbox", undefined, undefined, { name: "listbox1", multiselect: true, columnTitles: "Max", showHeaders: true });
    listbox1.preferredSize.width = 136;
    listbox1.preferredSize.height = 208;
    var button1 = win.add("button", undefined, undefined, { name: "button1" });
    button1.text = "Search";
    var button2 = win.add("button", undefined, undefined, { name: "button2" });
    button2.text = "Delete";
    win.show();
    var myNewArray = [];
    button1.onClick = function Search() {
        var compsArray = new Array();
        var myProj = app.project;
        myNewArray = [];
        listbox1.removeAll();
        for (var i = 1; i <= myProj.numItems; i++) {
            if (myProj.item(i) instanceof CompItem) {
                myNewArray = compsArray[compsArray.length] = myProj.item(i);
                listbox1.add("item", myNewArray.name);
            }
        }
    }
    button2.onClick = function deletecomps() {
            if (listbox1.selection.text = myNewArray.name) {
            myNewArray.remove();
        }
    }
})();

 

 This a screenshot of the script in AE.

This topic has been closed for replies.
Correct answer Tomas Sinkunas

What is it you are trying to achieve with this code? It's not quite clear.

In case you need to select list box items and remove then from the list along with compositions from project panel, here's a working snippet

 

button1.onClick = function Search() {
	listbox1.removeAll();
	for (var i = 1; i <= app.project.numItems; i++) {
		var projectItem = app.project.item(i);
		if (projectItem instanceof CompItem) {
			var listboxItem = listbox1.add("item", projectItem.name);
			listboxItem.id = projectItem.id;
		}
	}
};

button2.onClick = function deletecomps() {
	for (var i = listbox1.selection.length - 1; i >= 0; i--) {
		var listboxItem = listbox1.selection[i];
		var composition = app.project.itemByID(listboxItem.id);

		if (composition) {
			listboxItem.parent.remove(listboxItem);
			composition.remove();
		}
	}
};

1 reply

Tomas Sinkunas
Legend
April 3, 2020

Your if statement is broken. You need to use double or triple quotes:

if (listbox1.selection.text = myNewArray.name) {

Dreamer Art
Known Participant
April 3, 2020

It is not working.