Reputation: 1647
Photoshop scripting API getting me struggled. It's not dev-friendly at all. But still I believe, that there is a way to get layer object when I have layer id?
All I want to do is to duplicate selected layers to a new document. Layers might be nested within groups.
Upvotes: 0
Views: 2215
Reputation: 51847
You're right, such a simple action shouldn't be so complicated. Try this:
var curDoc = app.activeDocument;
var newDoc = app.documents.add(curDoc.width,curDoc.height,curDoc.resolution);//add a new doc with the same dimensions as the active one
app.activeDocument = curDoc;//set the original doc as active
try {
var curLayer = newDoc.activeLayer;//get a reference to the new document's current layer
curDoc.activeLayer.duplicate(newDoc,ElementPlacement.PLACEATBEGINNING);//dupliate the active layer from the original doc to the new/copy doc
} catch(e) { alert(e); }
If it helps, Photshop ships with a reference(which should be in PHOTOSHOP_INSTALL_FOLDER/Scripting/Documents
) and/or the Object Model Viewer (visible under the Help menu in ExtendScriptToolkit).
Upvotes: 1