Copy link to clipboard
Copied
Hi,
I want to create Clipping Mask on some of the layers, to merge them with other ones. I looked throughout the whole Adobe Photoshop Scripting Guide and JavaScript Guide, but find no answer.
What I want to do is simply move the scheme : Duplicate Layer -> move it over some other layer -> Craete Clipping Mask -> Merge Clipping Mask (on the layer below).
Is it even possible? If not, pls let me now is it a different way to achieve this goal?
Im using Adobe Photoshop CS5 and writing in jsx.
Sincerly,
Maciej Siwek
Artifex Mundi
The answer is in the guide. To duplicate a layer you use the duplicate method. Duplicate allow you to move as well as dupe but if you still need to move the layer you use the move method. To make a layer part of a clipping group you set it's groured property to true. And to merge you use the merge method. So if I had a document with three layers named top. middle, and bottom.
...// dupe and move the layer name bottom so it is above top
var dupedLayer = app.activeDocument.artLayers.getByName( 'bottom'
Copy link to clipboard
Copied
Quite easily possible (provided the layers can be identified unambiguously, I guess).
Layer has the method duplicate (relativeObject: Object, insertionLocation: ElementPlacement).
ArtLayer the method merge() and the property grouped (set it to true to clipping mask with the underlying Layer).
When working in ExtendScript Toolkit check out Help > Object Model Viewer to get an overview about the various classes’ Properties and Methods.
Copy link to clipboard
Copied
One additional wrinkle: you can't merge down if the mask layer happens to be a shape (LayerKind.SOLIDFILL). Those will need to be rasterized before merging, which is also an ArtLayer method.
Copy link to clipboard
Copied
I found the answer on my own, but thanks You.
My solution was to, using ScriptListener, find an appropriate ID. My code snippet for that:
//-- currentLayer is a layer which should be clipped to, and burnLayer is the one that will be clipped --
// Duplicate the layer and place it before current
var burnDuplicate = burnLayer.duplicate(currentLayer, ElementPlacement.PLACEBEFORE);
docRef.activeLayer = burnDuplicate;
// Create a Clipping Mask
var createClippingMask = charIDToTypeID ("GrpL");
executeAction( createClippingMask, undefined, DialogModes.NO );
// Merge Clipping Mask
docRef.activeLayer = currentLayer;
var mergeClippingMask = charIDToTypeID( "Mrg2" );
executeAction( mergeClippingMask, undefined, DialogModes.NO );
Copy link to clipboard
Copied
The ActionDescriptor code is supposed to be faster, I think, but with such small parts I doubt the benefit is significant.
Still, you could use the Object Model Viewer to look up the methods and properties available in the DOM.
Copy link to clipboard
Copied
The answer is in the guide. To duplicate a layer you use the duplicate method. Duplicate allow you to move as well as dupe but if you still need to move the layer you use the move method. To make a layer part of a clipping group you set it's groured property to true. And to merge you use the merge method. So if I had a document with three layers named top. middle, and bottom.
// dupe and move the layer name bottom so it is above top
var dupedLayer = app.activeDocument.artLayers.getByName( 'bottom' ).duplicate( app.activeDocument.artLayers.getByName( 'top' ), ElementPlacement.PLACEBEFORE );
// make it part of a clipping group with the layer below
dupedLayer.grouped = true;
// merge with the layer below
dupedLayer.merge();
If you wanted more layers in the clipping group you repeat the grouped = true step as needed. If there are more than one layer in the clipping group you could merge each layer in the group down until there are no more grouped layers. Or you could find the base layer and apply the merge to that layer. When you merge the base layer of a clipping group it merges the group not merge down.
EDIT: c.pfaffenbichler beat me to this. And agree, it is easy and in the object model viewer ( or scripting guide ). The only part that is not covered by the guide is how merge can either merge down or merge group depending on if the layer being merged is the base of a clipping group.
Copy link to clipboard
Copied
I guess Your version is much simpler then mine, thanks for all the help
Copy link to clipboard
Copied
This is useful man, thanks!