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

Create clipping path from current layer's vector- or layermask?

Explorer ,
Jun 13, 2019 Jun 13, 2019

Copy link to clipboard

Copied

Hi!

I am having a bit of trouble with finding good sources of how to convert the current layer's vector- or layermask into a clipping path via Javascript.

I only found one reference in the scripting reference (apart from the index) - page 139;

MethodParameter type
Returns
What it does

makeClippingPath

([flatness])

number [0.2..100]Makes this the clipping path for this document. flatness tells the PostScript printer how to approximate curves in the path.

I have tried this to select the Vector Mask;

makeActiveByName("Canvas");

activeDocument.pathItems.getByName('Canvas Vector Mask').select(); 

But when I add this;

activeDocument.pathItems.getByName('Canvas Vector Mask').makeClippingPath(0.2);

I get this;

Capture.PNG

I am aware that I should probably convert the Vector mask to a path before creating the clippingpath, but am unable to find relevant info on that issue as well.

TL;DR: How do I create a Clipping path from a Vector- or Layermask through Javascript?

If you can help me closer to the solution of the problem; Thank you!

TOPICS
Actions and scripting

Views

1.0K

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

Community Expert , Jun 14, 2019 Jun 14, 2019

Not sure if this helps or not... the following cleaned SL code will duplicate the selected (shape?) path and set it to a clipping path with a 0.2 flatness value:

// =======================================================

make();

function make() {

  var c2t = function (s) {

  return app.charIDToTypeID(s);

  };

  var s2t = function (s) {

  return app.stringIDToTypeID(s);

  };

  var descriptor = new ActionDescriptor();

  var reference = new ActionReference();

  var reference2 = new ActionReference();

  referenc

...

Votes

Translate

Translate
Adobe
Community Expert ,
Jun 14, 2019 Jun 14, 2019

Copy link to clipboard

Copied

Not sure if this helps or not... the following cleaned SL code will duplicate the selected (shape?) path and set it to a clipping path with a 0.2 flatness value:

// =======================================================

make();

function make() {

  var c2t = function (s) {

  return app.charIDToTypeID(s);

  };

  var s2t = function (s) {

  return app.stringIDToTypeID(s);

  };

  var descriptor = new ActionDescriptor();

  var reference = new ActionReference();

  var reference2 = new ActionReference();

  reference.putClass( s2t( "path" ));

  descriptor.putReference( c2t( "null" ), reference );

  reference2.putEnumerated( s2t( "path" ), s2t( "path" ), s2t( "vectorMask" ));

  reference2.putEnumerated( s2t( "layer" ), s2t( "ordinal" ), s2t( "targetEnum" ));

  descriptor.putReference( s2t( "from" ), reference2 );

  executeAction( s2t( "make" ), descriptor, DialogModes.NO );

}

// =======================================================

set();

function set() {

  var c2t = function (s) {

  return app.charIDToTypeID(s);

  };

  var s2t = function (s) {

  return app.stringIDToTypeID(s);

  };

  var descriptor = new ActionDescriptor();

  var descriptor2 = new ActionDescriptor();

  var reference = new ActionReference();

  var reference2 = new ActionReference();

  reference.putProperty( s2t( "path" ), s2t( "clippingPath" ));

  descriptor.putReference( c2t( "null" ), reference );

  reference2.putEnumerated( s2t( "path" ), s2t( "ordinal" ), s2t( "targetEnum" ));

  descriptor2.putReference( s2t( "path" ), reference2 );

  descriptor2.putDouble( s2t( "flatness" ), 0.200000 ); // flatness value

  descriptor.putObject( s2t( "to" ), s2t( "clippingPathEPS" ), descriptor2 );

  executeAction( s2t( "set" ), descriptor, 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
Explorer ,
Jun 18, 2019 Jun 18, 2019

Copy link to clipboard

Copied

Well, I cannot for the life figure out why or how - but it does indeed do what I want i to do. Hah... I'll need to take a closer look at this.

Thank you immensely much, Stephen_A_March - take care - hope you will have a fantastic day!

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 ,
Jun 19, 2019 Jun 19, 2019

Copy link to clipboard

Copied

LATEST

Your welcome, that's the "beauty" of Script Listener/Action Manager recorded code... even when cleaned via the Clean SL script, it can still be esoteric!

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