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

Shape Mode Scripting continued - Unite equivalent script?

Explorer ,
Aug 18, 2020 Aug 18, 2020

Copy link to clipboard

Copied

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!

 

Screen Shot 2020-08-18 at 9.40.27 pm.png

 

 

 

 

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!

 

 

TOPICS
Performance , Scripting

Views

681

Likes

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 , Aug 18, 2020 Aug 18, 2020

Hi,

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.

 

Screenshot 2020-08-18 at 6.46.04 PM.png

 

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'
...

Likes

Translate

Translate
Advisor ,
Aug 18, 2020 Aug 18, 2020

Copy link to clipboard

Copied

I thought 

app.executeMenuCommand("Live Pathfinder Add"); 

did that.  Sorry, I'm not at my PC to check.  

Likes

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 ,
Aug 18, 2020 Aug 18, 2020

Copy link to clipboard

Copied

Hi,

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.

 

Screenshot 2020-08-18 at 6.46.04 PM.png

 

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

Best regards

Likes

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
New Here ,
Mar 24, 2022 Mar 24, 2022

Copy link to clipboard

Copied

Charu, 

For some reason, the "expandStyle" menu command does not work for me. Could you help me out?

Thanks

Likes

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 ,
Aug 18, 2020 Aug 18, 2020

Copy link to clipboard

Copied

Charu,

 

> "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.

Likes

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 ,
Aug 18, 2020 Aug 18, 2020

Copy link to clipboard

Copied

Yes, that works perfectly.

With set of combination of commands, it is possible. I have updated the answer above.

 

Thank you. 🙂

 

 

Best regards

Likes

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
Explorer ,
Aug 18, 2020 Aug 18, 2020

Copy link to clipboard

Copied

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 🙂

Likes

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
New Here ,
Feb 28, 2022 Feb 28, 2022

Copy link to clipboard

Copied

This tip is very helpful. Thank you. However, it doesn't solve an issue I'm having. I'm trying to fix an existing script that creates outer strokes for a grouped object. After creating groups, the script runs the following commands:

 

app.executeMenuCommand("CompoundPath");
app.executeMenuCommand("Live Pathfinder Add");
app.executeMenuCommand("expandStyle");

 

This results in an outer stroke(good)  as well as maintains inner strokes (bad), though they are hidden (no stroke color/weight). See screenshot:

defaultjljedvits7bp_1-1646059935336.png

Ideally, the script would only keep the outer stroke and elimate the inner stroke, as they are unnecessary. That's exactly the result I get when using "Unite" from the Pathfinder tab. See screenshot:

defaultjljedvits7bp_0-1646059746545.png

Any advice on how to achieve the latter result using javacript?

 

Likes

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 ,
Mar 24, 2022 Mar 24, 2022

Copy link to clipboard

Copied

You could simulate the Pathfinder > Unite command exactly as the native UI behaves by loading .aia rawtext as an Action, executing it, then unloading the Action so it disappears from the Actions panel:

 

/**
 * Creates and runs a temporary action from given .aia rawtext
 *  {String} actionName Exact name of action
 *  {String} actionSet Exact name of set containing action
 *  {String} contents Raw .aia string of action file
 */
function runActionFromString(actionName, actionSet, contents) {
    // Rather oddly AI always wants you to use a file instead of a string,
    // so we'll just create a temp file every time we need to:
    var tmp = File(Folder.desktop + "/tmp.aia");
    tmp.open("w");
    tmp.write(contents);
    tmp.close();
    // Then load, execute, and unload the action:
    app.loadAction(tmp);
    app.doScript(actionName, actionSet, false);
    app.unloadAction(actionSet, "");
    // And remove the file:
    tmp.remove();
}

var actionStr =
    "/version 3 /name [ 12 756e697465436f6d6d616e64 ] /isOpen 1 /actionCount 1 /action-1 { /name [ 5 556e697465 ] /keyIndex 0 /colorIndex 0 /isOpen 1 /eventCount 1 /event-1 { /useRulersIn1stQuadrant 0 /internalName (ai_plugin_pathfinder) /localizedName [ 10 5061746866696e646572 ] /isOpen 0 /isOn 1 /hasDialog 0 /parameterCount 1 /parameter-1 { /key 1851878757 /showInPalette -1 /type (enumerated) /name [ 3 416464 ] /value 0 } } }";

runActionFromString("Unite", "uniteCommand", actionStr);

 

 

Likes

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
New Here ,
Mar 28, 2022 Mar 28, 2022

Copy link to clipboard

Copied

LATEST

Thanks, @Inventsable. With a little help, I got this method to work.

Likes

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