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

[JSX] Issue creating shape from subpathitem

Community Expert ,
Jan 08, 2024 Jan 08, 2024

Copy link to clipboard

Copied

I am creating a workpath out of a selection, and trying to convert that to a shape. Consider the path drawn by selection.makeWorkPath(.5) below. 

brianp311_0-1704772092897.png

Not sure why the tolerance is so low on the right top portion of the head. If I attempt to draw a shape out of this path, using the following function, the lines connect horizontally, since there's no path points where the ought to be. I'm doing some image resizing first; I leave at original dimensions, I get more full path points. 

The function I'm calling is: 

DrawShape(doc.pathItems[0].subPathItems[0].pathPoints, newColor.rgb);

Draw Shape function is defined below (from the forums): 

function DrawShape(args, color) {
    
    var doc = app.activeDocument;
    var y = args.length;
    var i = 0;
    
    var lineArray = [];
    
    for (i = 0; i < y; i++) {
        lineArray[i] = new PathPointInfo();
        lineArray[i].kind = args[i].kind;
        lineArray[i].anchor = args[i].anchor;
        lineArray[i].leftDirection = lineArray[i].anchor;
        lineArray[i].rightDirection = lineArray[i].anchor;
    }
    var lineSubPathArray = new SubPathInfo();
    lineSubPathArray.closed = true;
    lineSubPathArray.operation = ShapeOperation.SHAPEADD;
    lineSubPathArray.entireSubPath = lineArray;
    var myPathItem = doc.pathItems.add("myPath", [lineSubPathArray]);
    

    var desc88 = new ActionDescriptor();
    var ref60 = new ActionReference();
    ref60.putClass(stringIDToTypeID("contentLayer"));
    desc88.putReference(charIDToTypeID("null"), ref60);
    var desc89 = new ActionDescriptor();
    var desc90 = new ActionDescriptor();
    var desc91 = new ActionDescriptor();
    desc91.putDouble(charIDToTypeID("Rd  "), color.red); // R
    desc91.putDouble(charIDToTypeID("Grn "), color.green); // G
    desc91.putDouble(charIDToTypeID("Bl  "), color.blue); // B
    var id481 = charIDToTypeID("RGBC");
    desc90.putObject(charIDToTypeID("Clr "), id481, desc91);
    desc89.putObject(charIDToTypeID("Type"), stringIDToTypeID("solidColorLayer"), desc90);
    desc88.putObject(charIDToTypeID("Usng"), stringIDToTypeID("contentLayer"), desc89);
    executeAction(charIDToTypeID("Mk  "), desc88, DialogModes.NO);
    
    myPathItem.remove();
}

 

TOPICS
Actions and scripting

Views

222

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 , Jan 08, 2024 Jan 08, 2024

Could you please post the resulting file? 

I am not sure what the problem is; if you want shorter curve-segments have you tried a lower Tolerance-pixel-value? 

 

Please try 

        lineArray[i].leftDirection = args[i].leftDirection;
        lineArray[i].rightDirection = args[i].rightDirection;

 

Votes

Translate

Translate
Adobe
Community Expert ,
Jan 08, 2024 Jan 08, 2024

Copy link to clipboard

Copied

Could you please post the resulting file? 

I am not sure what the problem is; if you want shorter curve-segments have you tried a lower Tolerance-pixel-value? 

 

Please try 

        lineArray[i].leftDirection = args[i].leftDirection;
        lineArray[i].rightDirection = args[i].rightDirection;

 

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 ,
Jan 09, 2024 Jan 09, 2024

Copy link to clipboard

Copied

Changing to left and right direction worked! I assumed they would be the same values as the incoming path point, but guess not. Thank you! I guess I was referring to anchor, and not the anchor's line directions. Duh! 

 

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 ,
Jan 09, 2024 Jan 09, 2024

Copy link to clipboard

Copied

LATEST

If performance time is an issue you could switch from DOM-code to AM-code. 

AM-code may look terrible/incomprehensible but it usually performs faster. 

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