I'm trying to work out how to achieve the same result as using the Pathfinder Shape Modes Unite tool via script. It's one of the few pathfinder tools not available via `executeMenu()`
So if I have two overlapping circles and unite them I end up with a single 'flattened' item of a single path with no internal paths, which differs from creating a CompoundPath which preserves the internal details for later editing - in this case, I'm deliberately trying to discard the internal details to get a clean united shape!
A similar question was posed here https://community.adobe.com/t5/illustrator/shape-mode-scripting/m-p/11206350?page=1 and that was resolved for the minus front operation and also has some good examples of doing it with compound paths, but not anything on doing it in a way that mimics Unite.
I could record an action and replay that via a script, but it's super slow to replay and a bit of a hack!
Has anyone done this before? Thanks!
app.executeMenuCommand("Live Pathfinder Add");
did that. Sorry, I'm not at my PC to check.
Copy link to clipboard
For Unite, the command is 'Live Pathfinder Add'
app.executeMenuCommand('Live Pathfinder Add')
When you record the action for Unite, you can see it add actions as Pathfinder->Add. See screenshot for reference.
But the problem is when I execute above command, nothing happens.
As per your requirement Unite operation can be done with combination of the exceuteMenuCommand. Make sure you have selected items.
app.executeMenuCommand('group'); app.executeMenuCommand('Live Pathfinder Add'); app.executeMenuCommand('expandStyle'); app.executeMenuCommand('ungroup');
Edit : Added after more information from Kurt_Gold
> "But the problem is when I execute above command, nothing happens."
Actually something happens. The command applies a Pathfinder effect (see Effect menu).
Usually Pathfinder effects are applied to groups or layers. So, in order to see that something happens, just draw a couple of overlapping filled and stroked paths and group them. Then apply the script.
After that you may do an Object > Expand Appearance.
Yes, that works perfectly.
With set of combination of commands, it is possible. I have updated the answer above.
Thank you. 🙂
Thank you Charu and Kurt, that is totally awesome - exactly what I was hoping for!
Everytime I'm about to give on Extendscript the community saves the day 🙂