Copy link to clipboard
Copied
Can javascript execute menu commands such as pathfinder options?
Copy link to clipboard
Copied
No.
JET
Copy link to clipboard
Copied
is there a way to get the same functionality -- for example to subtract one shape from another?
Copy link to clipboard
Copied
That depends upon what you mean exactly. The various Pathfinders do very different things.
For example, if you have two paths selected, and one path fully surrounds the other, the SubtractFromShapeArea Pathfinder does essentially the same thing as making a Compound Path. You can use Javascript to create a Compound Path.
But if the two paths are only partially overlapping, the SubtractFromShapeArea Pathfinder "punches" only the shape of their intersection out of the bottom-most path. To do that with Javascript would require figuring out where the segments of the two paths intersect, and essentially building a new path point-by-point.
I'm not saying that can't be done, but since the Javascript model does not provide any pre-built function for determining whether paths collide or overlap, or for finding points of path intersections--you'd be talking about a rather ambitious undertaking.
JET
Copy link to clipboard
Copied
You can access PathFinder functionality through the Add New Effect (fx) button within the Appearance panel and save that as a Graphic Style which can then be called from your ExtendScript. For example:
Whilst there are some limitations to this method (in that it does not directly replicate all the functionality of the PathFinder panel) it's better than nothing and generally works for most situations. This approach is also useful for doing other operations that are not directly exposed by the Illustrator DOM (eg: Offset Path).
Hope this helps!
Andy McDonald
PhD Student / Research Assistant
Centre for Advanced Textiles
Glasgow School of Art
Copy link to clipboard
Copied
Andy, thanks for your especially helpful answer.
Unfortunately, this graphic style only exists as long as the group exists. Is there any way to break apart the group with the pathfinder style (ideally using javascript), such that the changes are kept?
My specific application is using outline to get rid of redundant lines (generated by another program) which are then cut using a craftrobo plotter. Each line should only exist once (or the cuts become ttoo deep).
The only thing I can currently do that works is print to a pdf, and then open it, and it looks like that might be scriptable, but there are other issues in the printing conversion (such as the image being rotated, etc. ) that I would need to deal with.
So if anyone has ideas on how to script outline such that the segments can be ungrouped, that would be great.
Thanks
Copy link to clipboard
Copied
Hi RFS22,
Not sure I fully understand what you are trying to do but you could try saving a Graphic Style that creates a PathFinder / Add effect (as I described in my previous reply) and then use the document.rasterize() method to isolate its path. I know this sounds strange but if the RasterizeOptions object that you pass to the rasterize() method has its clippingMask property set to true, then the resulting RasterItem will contain your outline as a single path. All you need to do is extract this from the group that is created.
I have attached a simple script that does this for you. To use it, you first need to create the Graphic Style as follows:
Next, you need to create an object to work with:
One thing to note is that this approach does not seem to work with Symbols (as opposed to simple paths). For some reason, there is not equivalent of "Break Link to Symbol" that can be called from your script - this would make things SO much easier.
___________________________________
*** UPDATE: I'm having trouble uploading the script so I've pasted it below ***
var myDoc = app.activeDocument;
var myLayer = myDoc.layers[0];
myLayer.name = "myLayer";
var myGroup = myDoc.groupItems[0];
myGroup.name = "myGroup";
myDoc.graphicStyles.getByName("PathFinder / Add").applyTo(myGroup);
var rasterizeOptions = new RasterizeOptions;
rasterizeOptions.antiAliasingMethod = AntiAliasingMethod.ARTOPTIMIZED;
rasterizeOptions.backgroundBlack = false;
rasterizeOptions.clippingMask = true;
rasterizeOptions.colorModel = RasterizationColorModel.GRAYSCALE;
rasterizeOptions.convertSpotColors = false;
rasterizeOptions.convertTextToOutlines = false;
rasterizeOptions.includeLayers = false;
rasterizeOptions.padding = 0;
rasterizeOptions.resolution = 300;
rasterizeOptions.transparency = false;
var rasterItem = myDoc.rasterize(myGroup, myGroup.controlBounds, rasterizeOptions);
var myPath = rasterItem.groupItems[0].pathItems[0].duplicate(myLayer, ElementPlacement.PLACEATBEGINNING);
myPath.name = "myPath";
rasterItem.remove();
___________________________________
Cheers,
Andy McDonald
PhD Student / Research Assistant
Centre for Advanced Textiles
Glasgow School of Art
Message was edited by: Andy McDonald
Copy link to clipboard
Copied
Turns out that the document.rasterize() method always calculates the outer path (provided clippingMask = true) therefore you don't actually need to setup the Graphics Style at all... just rasterize the group of paths directly. I'm looking into methods for replicating other PathFinder operations and will post back with any findings.
Cheers for now,
Andy McDonald
PhD Student / Research Assistant
Centre for Advanced Textiles
Glasgow School of Art
Copy link to clipboard
Copied
I've erased this reply because I accidently posted the same message (see above) whilst trying to upload the attachment
Message was edited by: Andy McDonald
Copy link to clipboard
Copied
Great job, Andy
Works a treat!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more