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

Scripting Path Operations (Subtract, Intersect, Exclude)

Community Beginner ,
Sep 20, 2016 Sep 20, 2016

Copy link to clipboard

Copied

Has anyone had any luck figuring out how to make a script or even an action with using different Path Operations with the drawing tool?

Long story short, I need to change a vector shape on a Shape Layer to Exclude AFTER it's already drawn. That change doesn't show up when recording an Action or even as an event in the Script Listener log. Am I out of luck?

TOPICS
Actions and scripting

Views

1.3K

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
Adobe
Community Expert ,
Sep 20, 2016 Sep 20, 2016

Copy link to clipboard

Copied

Am I out of luck?

No, but it’s a bit complicated – the Path can not be changed per se but a new one with the amended settings can be created.

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 ,
Sep 21, 2016 Sep 21, 2016

Copy link to clipboard

Copied

Yes, this is why I said I needed to change it after it is drawn. It is a complex shape layer I am trying to draw with an action (the wifi icon from an iPhone status bar.

The consecutive rings are the easy part but to trim them into the pie shape is the hard part. Well hard to do it and keep it clean.

I gotten to the point where the best way to do it is to first create the pie shape as a custom shape and then draw the custom shape as an intersecting shape. Great! But now I can't reliably remove that custom shape as the deletion of it works by the number of which position it is given in the Custom Shape palette and not by whatever name you give it.

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 ,
Sep 21, 2016 Sep 21, 2016

Copy link to clipboard

Copied

Why do you have to remove the custom shape? As long as you create custom shape with unique names you can use the one you want by name.  You can manually delete the custom excess custom shape sometime in the future when convenient using the preset manager to select the shapes and delete them one at a time or all at once or in groups.

JJMack

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 ,
Sep 21, 2016 Sep 21, 2016

Copy link to clipboard

Copied

I'd prefer to remove the custom shape so there isn't an additional new shape created every time someone uses the Action/Script (just a small portion of a much larger Action/Script creating some custom iPhone screen templates). This may be used across a large team of users who can't necessarily be depended upon to go in and remove them later by any means no matter how simple.

While the wifi icon is trivial in our use case, figuring this out will help me solve some issues I am having creating other elements with vector shapes.

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 ,
Sep 21, 2016 Sep 21, 2016

Copy link to clipboard

Copied

It would be nice to be able to delete a shapes by name however shapes need not have unique names and shapes can be loaded more than once. Even deleting a shape by location in the loaded shapes list does not mean you have deleted all loaded version of that shape. Some thing are hard to automate in Photoshop when names need not be unique. The logic needed becomes complex for things with identical  names may be quite different.

JJMack

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 ,
Sep 21, 2016 Sep 21, 2016

Copy link to clipboard

Copied

Thanks, JJ. I was reading a post of yours from a year or so ago where you had mentioned doing a time stamp into the name of your custom shape to make sure it was given a unique name. I take it you didn't also delete that custom shape after?

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 ,
Sep 21, 2016 Sep 21, 2016

Copy link to clipboard

Copied

I had the same problem you have even with unique names you can not delete defined shaped by name.  When I get the shape defined the way I want  I delete all the others with the same name and have time stamps and remove the timestamp from the shape I want to keep using the preset manager.

For me It is easier then trying to program a solution.  If I knew JavaScript and understood action manager interface.  I might have tried. There may get and array of defines shapes and delete the one you want to delete.  With the Preset manager I can  Ctrl+Click on shapes I want to delete throughout  the shown icons matrix to highlight the one I want to delete then with a single click on the delete button they all will be deleted.

I'm just a hacker I hack at things I want.

JJMack

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 ,
Sep 21, 2016 Sep 21, 2016

Copy link to clipboard

Copied

Yes, this is why I said I needed to change it after it is drawn. It is a complex shape layer I am trying to draw with an action (the wifi icon from an iPhone status bar.

The consecutive rings are the easy part but to trim them into the pie shape is the hard part. Well hard to do it and keep it clean.

I gotten to the point where the best way to do it is to first create the pie shape as a custom shape and then draw the custom shape as an intersecting shape. Great! But now I can't reliably remove that custom shape as the deletion of it works by the number of which position it is given in the Custom Shape palette and not by whatever name you give it.

Would you mind illustrating what you are talking about with screenshots?

Once again: It is possible within a Script to create a Path with amended settings and, if necessary, replace an existing Path with that new Path.

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
Enthusiast ,
Sep 22, 2016 Sep 22, 2016

Copy link to clipboard

Copied

LATEST

Hi Timmy

Hope this helps you to explore better what you want.

I had sucess to get my pathItems created by script and it was really surprising to find out that this is something very fast for photoshop to precess.

Here is some code I removed from my work just to get some tools you can explore

Note: you have to pay attentions about the order and the logic when using SHAPEADD  SHAPESUBTRACT  SHAPEXOR  SHAPEINTERSECT

Hope it helps.

// example of a scripted pathItem passed to Fill layer

var xOrig = activeDocument.width.value/6;

var yOrig = activeDocument.height.value/6;

var ww = activeDocument.width.value/2;

var hh = activeDocument.height.value/2;

//

app.preferences.rulerUnits = Units.PIXELS;

app.rulerUnits = Units.PIXELS;

// IMPORTANT ro have resolution = 72

activeDocument.resizeImage(undefined, undefined, 72, ResampleMethod.NONE );

//

var lineSubPathArray_ArraysALL = [];

//

// external reactangle SHAPEADD

var Grid_L = [[xOrig,yOrig], [ww+xOrig,yOrig], [ww+xOrig,hh+yOrig], [xOrig,hh+yOrig]];

var lineSubPathArray_L = new SubPathInfo();

lineSubPathArray_L.closed = true;

lineSubPathArray_L.operation = ShapeOperation.SHAPEADD; // SHAPEADD  SHAPESUBTRACT  SHAPEXOR  SHAPEINTERSECT

lineSubPathArray_L.entireSubPath = lineArr (Grid_L);

lineSubPathArray_ArraysALL.push(lineSubPathArray_L);

//

var newLinePercent = 0.5;

var colocacao = hh*newLinePercent+yOrig;

// central Horizontal line

line_sub(true, xOrig , colocacao, ww, colocacao, 1, 0.2); // last argument: [0-1] short-long line

//

colocacao = ww*newLinePercent+xOrig;

// central Vertical line

line_sub(false, colocacao , yOrig, colocacao, hh, 1, 0.33); // last argument: [0-1] short-long line

//

// example of a script drawing path / I draw it first, then I runned a script to gete these values and than I eused them here

var human = [[PointKind.SMOOTHPOINT,16.5671641791045,15,16.5435895846699,11.7002597284079,16.5872744047564,17.8148319428525],

[PointKind.SMOOTHPOINT,13.2537313432836,3.33333333333333,13.3528439119587,-0.28107584338843,12.9381663113006,14.8412698412698],

[PointKind.SMOOTHPOINT,22.2735251952284,3.46852228902127,22.2735251952284,14.8970937175927,22.2735251952284,-1.13465231415333],

[PointKind.SMOOTHPOINT,19.8805970149254,15,19.8805970149254,17.276065937832,19.8805970149254,10.8625916991569],

[PointKind.SMOOTHPOINT,27.6119402985075,18.8888888888889,41.227159415735,36.0757051655919,25.1265530775343,15.7515252390243],

[PointKind.SMOOTHPOINT,33.6865671641791,47.7777777777778,30.9253731343284,38.7037037037037,36.4477611940299,56.8518518518519],

[PointKind.CORNERPOINT,25.4029850746269,28.8888888888889,25.4029850746269,28.8888888888889,25.4029850746269,28.8888888888889],

[PointKind.SMOOTHPOINT,29.8208955223881,97.7777777777778,21.9054726368159,81.4814814814815,37.7363184079602,114.074074074074],

[PointKind.CORNERPOINT,17.6716417910448,60,17.6716417910448,60,17.6716417910448,60],

[PointKind.SMOOTHPOINT,7.17910447761194,97.2222222222222,1.28855721393035,112.962962962963,13.0696517412935,81.4814814814815],

[PointKind.SMOOTHPOINT,11.044776119403,28.8888888888889,5.89054726368159,37.037037037037,3.86567164179105,53.8888888888889],

[PointKind.SMOOTHPOINT,2.2089552238806,47.7777777777778,-1.28855721393035,56.6666666666667,5.70646766169154,38.8888888888889],

[PointKind.SMOOTHPOINT,8.28358208955224,18.8888888888889,10.7423973932026,15.2152772396634,-1.33855608967749,33.2649173987156]];

var alt = hh*0.07;

var lineArray = [];

for (i = 0; i < human.length; i++) {

    lineArray = new PathPointInfo;

    lineArray.kind = human[0];

    var _X = xOrig + alt*1.5 + (alt*human[1])/100;

    var _Y = yOrig + hh*0.085 + (alt*human[2])/100;

    lineArray.anchor = [ _X, _Y];

    var LX = xOrig + alt*1.5  + (alt*human[3])/100;

    var LY = yOrig + hh*0.085 + (alt*human[4])/100;

    lineArray.leftDirection =  [ LX, LY];

    var RX = xOrig + alt*1.5  + (alt*human[5])/100;

    var RY = yOrig + hh*0.085 + (alt*human[6])/100;

    lineArray.rightDirection =  [ RX, RY];

}

var lineSubPathArray = new SubPathInfo();

lineSubPathArray.closed = true;

lineSubPathArray.operation = ShapeOperation.SHAPESUBTRACT;

lineSubPathArray.entireSubPath = lineArray;

lineSubPathArray_ArraysALL.push(lineSubPathArray);

//

var myPathItem = activeDocument.pathItems.add("myPath", lineSubPathArray_ArraysALL);

// combine all subPaths in one

var desc2 = new ActionDescriptor();

var ref1 = new ActionReference();

ref1.putEnumerated( charIDToTypeID( "Path" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );

desc2.putReference( charIDToTypeID( "null" ), ref1 );

executeAction( stringIDToTypeID( "combine" ), desc2, DialogModes.NO );

//

// Creates a new filllayer from my path myPath:

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  "), 255.000000); // Red

desc91.putDouble(charIDToTypeID("Grn "), 0.000000); // Green

desc91.putDouble(charIDToTypeID("Bl  "), 0.000000); // Blue

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

//

///////////// This will delete the workPath

myPathItem.remove();

//////////////////

// naming the new fill layer containing the path

activeDocument.activeLayer.name = "My New Path Layer";

activeDocument.activeLayer.opacity = 50;

//

function line_sub (direction ,x ,y ,w ,h, thickness, decimalSize) {

    var R = (thickness == undefined) ? 0.1 : thickness;

    var less = (direction) ? w*(decimalSize/2) : h*(decimalSize/2);

    var RT = (direction) ? [[ x+less+1, y-R ], [ w+x-less-2, y-R ], [ w+x-less-2 , y+R ], [ x+less+1 , y+R]] : [[ x-R, y+less+1 ], [ x+R , y+less+1], [ x+R, h+y-less-2], [ x-R , h+y-less-2]];

    var lineSubPathArray = new SubPathInfo();

    lineSubPathArray.closed = true;

    lineSubPathArray.operation = ShapeOperation.SHAPEXOR; // SHAPEADD  SHAPESUBTRACT  SHAPEXOR  SHAPEINTERSECT

    lineSubPathArray.entireSubPath = lineArr (RT);

    lineSubPathArray_ArraysALL.push(lineSubPathArray);

}

//

function lineArr (arr) {

    var lineArray = [];

    for (i = 0; i < 4; i++) {

        lineArray = new PathPointInfo;

        lineArray.kind = PointKind.CORNERPOINT;

        lineArray.anchor = arr;

        lineArray.leftDirection = lineArray.anchor;

        lineArray.rightDirection = lineArray.anchor;

    }

    return lineArray;

}

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