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

How to create a Vectormask with JS?

New Here ,
Aug 16, 2009 Aug 16, 2009

Hi there,

I am trying to create a vectormask with JavaScript but the ExtendScript Toolkit throws me everytime an error.

This is my Code:

var PfadPunkte = new Array(); addPointToArray(PfadPunkte,10,10); addPointToArray(PfadPunkte,110,10); addPointToArray(PfadPunkte,110,35); addPointToArray(PfadPunkte,10,35); var neuerPfad = new SubPathInfo(); neuerPfad.operation=ShapeOperation.SHAPEXOR; neuerPfad.closed=true; neuerPfad.entireSubPath=PfadPunkte; var link = activeDocument.pathItems.add("link", Array(neuerPfad)); link.kind=PathKind.VECTORMASK;

Has someone an idea what i am doing wrong?

Best regards, Andreas

TOPICS
Actions and scripting
2.2K
Translate
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 , Aug 16, 2009 Aug 16, 2009

Sorry, I skipped past the vectormask part and only looked at the code. You can not create a mask with the scripting DOM. You will need to use scriptlistner. Something like this will make a vector mask to the active layer using the selected( active ) path.

    var desc = new ActionDescriptor();
        var ref = new ActionReference();
        ref.putClass( charIDToTypeID( "Path" ) );
    desc.putReference( charIDToTypeID( "null" ), ref );
        var maskRef = new ActionReference();
        maskRef.put

...
Translate
Adobe
Engaged ,
Aug 16, 2009 Aug 16, 2009

What error do you get?

I don't have your function addPointToArray() to test it.

Translate
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 ,
Aug 16, 2009 Aug 16, 2009

Yes, it is hard to tell what is wrong without that function. Here is an example that works without functions,

// create a document reference to work with
var doc = app.activeDocument;
//define the path
var lineArray = new Array();
lineArray[0] = new PathPointInfo;
lineArray[0].kind = PointKind.CORNERPOINT;
lineArray[0].anchor = Array(100, 100);//top left
lineArray[0].leftDirection = lineArray[0].anchor;
lineArray[0].rightDirection = lineArray[0].anchor;
lineArray[1] = new PathPointInfo;
lineArray[1].kind = PointKind.CORNERPOINT;
lineArray[1].anchor = Array(200, 100);//top right
lineArray[1].leftDirection = lineArray[1].anchor;
lineArray[1].rightDirection = lineArray[1].anchor;
lineArray[2] = new PathPointInfo;
lineArray[2].kind = PointKind.CORNERPOINT;
lineArray[2].anchor = Array(200, 2900);//bottom right
lineArray[2].leftDirection = lineArray[2].anchor;
lineArray[2].rightDirection = lineArray[2].anchor;
lineArray[3] = new PathPointInfo;
lineArray[3].kind = PointKind.CORNERPOINT;
lineArray[3].anchor = Array(100, 2900);//bottom left
lineArray[3].leftDirection = lineArray[3].anchor;
lineArray[3].rightDirection = lineArray[3].anchor;
var lineSubPathArray = new Array();
lineSubPathArray[0] = new SubPathInfo();
lineSubPathArray[0].operation = ShapeOperation.SHAPEADD;
lineSubPathArray[0].closed = true;
lineSubPathArray[0].entireSubPath = lineArray;
// now make the path
var myPathItem = doc.pathItems.add("myPath", lineSubPathArray);

Translate
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
Engaged ,
Aug 16, 2009 Aug 16, 2009

I was about to work something up without that function also. As usual, you (or xbytor) beat me to it.

I'd still like to see the coding for that function as the problem could be (I suspect is) within there.

Translate
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 ,
Aug 16, 2009 Aug 16, 2009

I, like Xbytor, have a code library. I use mine to keep functions and examples. So I didn't have to create the example, I just copy and paste.

I too think that the function is the problem. That and the operation property of the SubPathInfo is required. The guide seems to say it's only needed it there is already another subpath but I find it doesn't work without setting this property even with a new path.

Translate
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
New Here ,
Aug 16, 2009 Aug 16, 2009

I am sorry. I forgot to copy this function. Here it is:

function addPointToArray(parray, x, y) {      var idx = parray.length;      parray[idx] = new PathPointInfo;      parray[idx].kind = PointKind.SMOOTHPOINT;      parray[idx].anchor = Array(x, y);      parray[idx].leftDirection = parray[idx].anchor;
     parray[idx].rightDirection = parray[idx].anchor;

}

This function isn't from me, I found it on a website and tried to use it. For normal path it works fine.

Translate
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
New Here ,
Aug 16, 2009 Aug 16, 2009

@Michael L Hale

Your example creates just a normal path. I am searching for a method to create a vectormask. Do you have an example for this too?

Translate
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 ,
Aug 16, 2009 Aug 16, 2009

Sorry, I skipped past the vectormask part and only looked at the code. You can not create a mask with the scripting DOM. You will need to use scriptlistner. Something like this will make a vector mask to the active layer using the selected( active ) path.

    var desc = new ActionDescriptor();
        var ref = new ActionReference();
        ref.putClass( charIDToTypeID( "Path" ) );
    desc.putReference( charIDToTypeID( "null" ), ref );
        var maskRef = new ActionReference();
        maskRef.putEnumerated( charIDToTypeID( "Path" ), charIDToTypeID( "Path" ), stringIDToTypeID( "vectorMask" ) );
    desc.putReference( charIDToTypeID( "At  " ), maskRef );
        var pathRef = new ActionReference();
        pathRef.putEnumerated( charIDToTypeID( "Path" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
    desc.putReference( charIDToTypeID( "Usng" ), pathRef );
executeAction( charIDToTypeID( "Mk  " ), desc, DialogModes.NO );

Translate
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
New Here ,
Aug 16, 2009 Aug 16, 2009
LATEST

@Michael L Hale

That's it. If the DOM doesn't give it tu us, that's a way I can go. I will take this code and put it in a function.

Thank you all for helping

Best regards,

Andreas

Translate
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
Engaged ,
Aug 16, 2009 Aug 16, 2009

This one seems to work for me....

function addPointToArray(parray, x, y) {
     var idx = parray.length;

     parray[idx] = new PathPointInfo;
     parray[idx].kind = PointKind.SMOOTHPOINT;
     parray[idx].anchor = Array(x, y);
     parray[idx].leftDirection = parray[idx].anchor;
     parray[idx].rightDirection = parray[idx].anchor;
}
var PfadPunkte = new Array();
addPointToArray(PfadPunkte,10,10);
addPointToArray(PfadPunkte,110,10);
addPointToArray(PfadPunkte,110,35);
addPointToArray(PfadPunkte,10,35);
var neuerPfad = new Array();
neuerPfad[0] = new SubPathInfo();
neuerPfad[0].operation=ShapeOperation.SHAPEXOR;
neuerPfad[0].closed=true;
neuerPfad[0].entireSubPath=PfadPunkte;
var link = app.activeDocument.pathItems.add("link",neuerPfad);
link.kind=PathKind.VECTORMASK;

Translate
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
Engaged ,
Aug 16, 2009 Aug 16, 2009

OOPS! My bad. It gave me an error on the vectormask part like Michael said.

I kinda skipped over that part when testing it out.

Translate
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 ,
Aug 16, 2009 Aug 16, 2009

I think the javascript guide is unclear about path.kind. It can return any of the PathKind constants. But you can only set NORMALPATH or CLIPPINGPATH.

Translate
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