• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Clipping Mask

Community Beginner ,
Dec 02, 2011 Dec 02, 2011

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

TOPICS
Actions and scripting

Views

4.4K

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

Guru , Dec 02, 2011 Dec 02, 2011

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'

...

Votes

Translate

Translate
Adobe
Community Expert ,
Dec 02, 2011 Dec 02, 2011

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.

Votes

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
Explorer ,
Jun 29, 2022 Jun 29, 2022

Copy link to clipboard

Copied

LATEST

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.

Votes

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 ,
Dec 02, 2011 Dec 02, 2011

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 );

Votes

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 Expert ,
Dec 02, 2011 Dec 02, 2011

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.

Votes

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
Guru ,
Dec 02, 2011 Dec 02, 2011

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.

Votes

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 ,
Dec 02, 2011 Dec 02, 2011

Copy link to clipboard

Copied

I guess Your version is much simpler then mine, thanks for all the help

Votes

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
Participant ,
Aug 29, 2018 Aug 29, 2018

Copy link to clipboard

Copied

This is useful man, thanks!

Votes

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