Copy link to clipboard
Copied
I'm working on a script that duplicates a layer many times and adds a "set matte effect" to the new layers. I'm also copying all the effects from the source layer and pasting them to the new layers using the executeCommand method. I would like to have the set matte to be the first effect so that dropshadows etc would work correctly. Even when I add the set matte in code first and then do the paste executeCommand, the set matte effect ends up being the last effect. Is there a fix for this? Or is there a way to reorder the effects in the Effect Parade? PropertyIndex doesn't help as it is read only.
Thanks!
If you have a variable pointed at your Set Matte effect, I think you can use:
myEffect.moveTo(1)
Copy link to clipboard
Copied
If you have a variable pointed at your Set Matte effect, I think you can use:
myEffect.moveTo(1)
Copy link to clipboard
Copied
That works pefectly. Cheers!
Copy link to clipboard
Copied
Actually I ran into a new problem. Is there any limitations where in code one can call the executeCommand? When I moved the copying into a dedicated function the executeCommand call began to crash. Is the executeCommand blocking code? When I had the paste command in other section in code the effects were pasted somehow also on shapelayers that did not even exist at that point in code.
function copyLayerEffects(sourceLayer, targetLayer) {
// is there anything to copy
if( sourceLayer.property("ADBE Effect Parade").numProperties !== 0 ) {
// select the effects
for(var i = 1; i <= sourceLayer.property("ADBE Effect Parade").numProperties; i++){
sourceLayer.property("ADBE Effect Parade").property(i).selected = true;
}
// copy command
alert(app); // is not undefined
alert(app.findMenuCommandId("Copy with Property Links")); // alerts code 10310
app.executeCommand(app.findMenuCommandId("Copy with Property Links")); // crashes
// remove effects from the new layer because they get duplicated when the source is cloned
while(targetLayer.property("ADBE Effect Parade").numProperties !== 0){
targetLayer.property("ADBE Effect Parade").property(1).remove();
}
// paste command
app.executeCommand(app.findMenuCommandId("Paste"));
}
}
Copy link to clipboard
Copied
Because the commands in the Edit Menu like Copy and Paste are so context sensitive (depend heavily on what's currently selected and which panel is active) -- and often aren't even legal (when the command would be dimmed out in the menu), you need to make sure your code is setting everything up exactly as expected by the command. Frankly, I avoid using app.executeCommand() unless there is no other way to accomplish what I need to do.
Copy link to clipboard
Copied
Ok, that makes sense. The focus must shift somewhere else and it causes the crash. I can understand why you'd avoid using it. Thanks again!