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

Can javascript execute pathfinder commands?

Community Beginner ,
May 14, 2009 May 14, 2009

Can javascript execute menu commands such as pathfinder options?

TOPICS
Scripting
7.7K
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
Adobe
LEGEND ,
May 17, 2009 May 17, 2009

No.

JET

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 ,
Jun 05, 2009 Jun 05, 2009

is there a way to get the same functionality -- for example to subtract one shape from another?

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
LEGEND ,
Jun 05, 2009 Jun 05, 2009

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

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
Guest
Jun 12, 2009 Jun 12, 2009

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:

  1. Draw two paths that overlap
  2. Group them together
  3. With the group selected, open the Appearance panel and press the Add New Effect button
  4. Under the Illustrator Effects section (within the drop down menu that appears), select PathFinder and then choose the operation you want
  5. Drag the group into the Graphic Styles panel to add it to the library (double click to change the name)
  6. You can now access this from within your script using the graphicStyles.getByName("GraphicStyleName").applyTo(ObjectYouWishToModify);

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

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 ,
Jun 17, 2009 Jun 17, 2009

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

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
Guest
Jun 18, 2009 Jun 18, 2009

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:

  1. Draw two paths that overlap
  2. Group them together
  3. With the group selected, open the Appearance panel and press the Add New Effect button
  4. Under the Illustrator Effects section, select PathFinder / Add
  5. Drag the group into the Graphic Styles panel to add it to the library
  6. Double click this Graphic Style and rename it to "PathFinder / Add"
  7. Delete the group

Next, you need to create an object to work with:

  1. Starting with a single blank layer, draw some overlapping shapes
  2. Group them together
  3. Run the script
  4. Let me know how you get on

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

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
Guest
Jun 18, 2009 Jun 18, 2009

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

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
Guest
Jun 18, 2009 Jun 18, 2009

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

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
Community Expert ,
Jun 18, 2009 Jun 18, 2009
LATEST

Great job, Andy

Works a treat!

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