Help with duplicating and naming

Community Beginner ,
Jul 19, 2021 Jul 19, 2021

Copy link to clipboard

Copied

Hello guys! 

I just started learning scripting and I have this code, i dont remmeber from where I got it. anyway, this script stack all the open documents into one document as layers, my problem is all the layers have the name Background, I would like to include the orginlan document name in this script. I try to use:

 

var docName = app.activeDocument.name

 

and I try adding docName with the dupicate function but it does not work.

can someone help please 🙂

Thanks in advance

 

var doc = activeDocument = app.documents[0];
var docName = activeDocument.name;

doc.layers[0].isBackgroundLayer = false;
var docNumber = app.documents.length;
for (var i = 1; i < docNumber; i++) {
    var nextDoc = activeDocument = app.documents[1];
    nextDoc.activeLayer.duplicate(doc.layers[0], ElementPlacement.PLACEBEFORE); + docName;
    nextDoc.close(SaveOptions.DONOTSAVECHANGES);

 

TOPICS
SDK

Views

58

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

correct answers 1 Correct Answer

Adobe Community Professional , Jul 19, 2021 Jul 19, 2021
Change your for loop to: for(var i = 1; i < docNumber; i++) { nextDoc = activeDocument = documents[1]; nextDoc.activeLayer.name = nextDoc.name nextDoc.activeLayer.duplicate(doc.layers[0], ElementPlacement.PLACEBEFORE) nextDoc.close(SaveOptions.DONOTSAVECHANGES) }

Likes

Translate

Translate
Adobe Community Professional ,
Jul 19, 2021 Jul 19, 2021

Copy link to clipboard

Copied

Change your for loop to:

 

for(var i = 1; i < docNumber; i++) {
	nextDoc = activeDocument = documents[1]; nextDoc.activeLayer.name = nextDoc.name
	nextDoc.activeLayer.duplicate(doc.layers[0], ElementPlacement.PLACEBEFORE)
	nextDoc.close(SaveOptions.DONOTSAVECHANGES)
}

 

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
community guidelines
Community Beginner ,
Jul 19, 2021 Jul 19, 2021

Copy link to clipboard

Copied

LATEST

It Works perfectly Thanks a lot! 

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