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

remove() ShapeLayers by name

Community Beginner ,
Apr 11, 2020 Apr 11, 2020

Copy link to clipboard

Copied

Hi,
How can I remove all form layers in an entire project by name.
I understand that this should be a script.
I used ".remove ()", but unfortunately this isn't really a problem I know much about.
Please help)

 

app.activeDocument.layers.getByName('123').Remove();

TOPICS
Scripting

Views

548

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
community guidelines
LEGEND ,
Apr 12, 2020 Apr 12, 2020

Copy link to clipboard

Copied

Huh? What does this have to do with After Effects? Your syntax is completely wrong to begin with and would only be relevant for PS or AI.

 

Mylenium

Votes

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
community guidelines
Community Expert ,
Apr 12, 2020 Apr 12, 2020

Copy link to clipboard

Copied

You have to loop through all the items in the project bin, looking for comps, then loop backwards through each comp looking for layers named "123" and remove them:

 

var myComp;
for (var i = 1; i <= app.project.numItems; i++){
	if (app.project.item(i) instanceof CompItem){
		myComp = app.project.item(i);
		for (var j = myComp.numLayers; j > 0; j--){
			if (myComp.layer(j).name == "123"){
				myComp.layer(j).remove();
			}
		}
	}
}

Votes

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
community guidelines
Explorer ,
Apr 12, 2020 Apr 12, 2020

Copy link to clipboard

Copied

If you want to delete only the ShapeLayers, you have to add an extra check to Dan's snippet:

 

var myComp;
for (var i = 1; i <= app.project.numItems; i++){
	if (app.project.item(i) instanceof CompItem){
		myComp = app.project.item(i);
		for (var j = myComp.numLayers; j > 0; j--){
			if (myComp.layer(j).name == "123" &&
                            myComp.layer(j) instanceof ShapeLayer){
				myComp.layer(j).remove();
			}
		}
	}
}

Votes

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
community guidelines
Community Beginner ,
Apr 13, 2020 Apr 13, 2020

Copy link to clipboard

Copied

LATEST

andreip14565073,

exactly what is needed. You are God of JS)
Thank you so much!

Votes

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
community guidelines
Community Beginner ,
Apr 13, 2020 Apr 13, 2020

Copy link to clipboard

Copied

wow, it is Great! Thank you very very much)

Votes

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
community guidelines