Skip to main content
Participating Frequently
January 29, 2014
Question

Copy Shape Attributes & Layer Style from one layer & paste to another?

  • January 29, 2014
  • 1 reply
  • 1611 views

I don't know Photoshop scripting and wanted a script to copy both the Shape Attributes and Layer Style from one layer, and then another script to paste them to a different layer.

I used the ScriptingListener plugin to record these and they do work, but with a problem. If the vector shape has layer styles it will work fine, but if the the shape I'm copying doesn't have any layer styles then it shows an error (as it's trying to copy layer styles that aren't there).

Is it possible for a script to detect whether layer styles are present, and if not ignore that and just copy/paste the shape attributes? Or could the script 'try' to copy layer styles but 'fail silently' if none are applied to a layer, and then just copy/paste only the shape attributes?

This topic has been closed for replies.

1 reply

c.pfaffenbichler
Community Expert
Community Expert
January 29, 2014

A try-clause seem to be an option.

try {

}

catch (e) {}

Checking for Layer Styles is possible, too.

var ref = new ActionReference();

ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

var layerDesc = executeActionGet(ref);

var hasLayerFx = layerDesc.hasKey(stringIDToTypeID('layerEffects'));

if (hasLayerFx == true) {alert ("layer effects")}

else {alert ("no layer effects")};

Participating Frequently
January 29, 2014

Thanks! The try-clause thing stops me from getting the error messge

I'm not sure how to use the 'checking for Layer Styles' part. Does it check for Layer Styles and copy them if they're present and ignore/not try to copy if they're not present?

Now that it's working (without an error message), when copying if Layer Styles aren't present on the layer being copied, is it possible to delete Layer Styles (or set Layer Styles to none) on the layer where you're pasting?

c.pfaffenbichler
Community Expert
Community Expert
January 29, 2014

I'm not sure how to use the 'checking for Layer Styles' part. Does it check for Layer Styles and copy them if they're present and ignore/not try to copy if they're not present?

It just checks, you can then have the Script do different things depending on the outcome.