Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

listbox script can't perform multiple delete for CompItem

Explorer ,
Apr 03, 2020 Apr 03, 2020

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.

Test 2.jpg

TOPICS
Scripting
959
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Apr 04, 2020 Apr 04, 2020

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 = project
...
Translate
Advocate ,
Apr 03, 2020 Apr 03, 2020

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

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 03, 2020 Apr 03, 2020

It is not working.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 03, 2020 Apr 03, 2020

I am very greatful for your time and effort Tomas_Sinkunas 😉

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Apr 04, 2020 Apr 04, 2020

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();
		}
	}
};
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 06, 2020 Apr 06, 2020
LATEST

Thanks for gods of coding

It is working  ;-))))))))

I am really a novice and using it for my personal use... 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines