Highlighted

remove active comp

Explorer ,
May 21, 2020

Copy link to clipboard

Copied

Hi,

I am trying to remove the active comp from my project using JavaScript but it doesn't really work. It executes the script but instead of removing it, it's just switching the order....Not sure what I am doing wrong. Can anyone share what is the correct way to delete a comp from a project?

app.project.activeItem.remove.CompItem;

Thank you very much! 

I figured something that works in the meantime. If anyone has a better solution, please share. My working code below:

function deleteComp(){
for (var i = 1; i <= app.project.numItems; i ++) {
    if ((app.project.item(i) instanceof CompItem) && (app.project.item(i).name === 'myComp')) {
        app.project.item(i).remove();
        break;
    }
}
}

 Thanks

TOPICS
Scripting

Views

595

Likes

Translate

Translate

Report

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

remove active comp

Explorer ,
May 21, 2020

Copy link to clipboard

Copied

Hi,

I am trying to remove the active comp from my project using JavaScript but it doesn't really work. It executes the script but instead of removing it, it's just switching the order....Not sure what I am doing wrong. Can anyone share what is the correct way to delete a comp from a project?

app.project.activeItem.remove.CompItem;

Thank you very much! 

I figured something that works in the meantime. If anyone has a better solution, please share. My working code below:

function deleteComp(){
for (var i = 1; i <= app.project.numItems; i ++) {
    if ((app.project.item(i) instanceof CompItem) && (app.project.item(i).name === 'myComp')) {
        app.project.item(i).remove();
        break;
    }
}
}

 Thanks

TOPICS
Scripting

Views

596

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
May 21, 2020 0
Explorer ,
May 21, 2020

Copy link to clipboard

Copied

I figured something that works in the meantime. If anyone has a better solution, please share. My working code below:

function deleteComp(){
for (var i = 1; i <= app.project.numItems; i ++) {
    if ((app.project.item(i) instanceof CompItem) && (app.project.item(i).name === 'myComp')) {
        app.project.item(i).remove();
        break;
    }
}
}

 Thanks

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 21, 2020 0
Guide ,
May 21, 2020

Copy link to clipboard

Copied

Try this:

 

var myItem = app.project.activeItem;
if (myItem && myItem instanceof CompItem ) myItem.remove();

 

Dan

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 21, 2020 1
Explorer ,
May 21, 2020

Copy link to clipboard

Copied

Thank you Dan!

Would this work if I want to actually target a specific comp name?

I know my initial question was about removing the active comp but I realized that I actually need to select which comp I want to remove....sorry for any confusion.

Thank you again!

A.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 21, 2020 0
Guide ,
May 21, 2020

Copy link to clipboard

Copied

You can't directly access a comp by name--you have to loop through the items looking for a comp with that name. So what you came up with looks pretty good..

 

Dan

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 21, 2020 0
Explorer ,
May 22, 2020

Copy link to clipboard

Copied

I think you should pass the comp name as parameter to the function, so you don't need to change the function every time you need another composition deleted.

 

function deleteComp(compName) {
    for (var i = 1; i <= app.project.numItems; i++) {
        if (app.project.item(i) instanceof CompItem && app.project.item(i).name === compName) {
            app.project.item(i).remove();
            break;
        }
    }
}

 This way, you can use this function multiple times in your project, to delete different comps. Like this:

deleteComp("First one");

deleteComp("Second one");

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 22, 2020 1