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

Illustrator Scripting - Combining/Merging multiple CompoundPathItem into one

Explorer ,
Aug 04, 2022 Aug 04, 2022

Copy link to clipboard

Copied

Hey guys,

 

I would like to combine/merge multiple CompoundPathItem into a single one.

 

Has anyone done something similar previously?

 

My code so far looks like this:

 

var flattened = doc.activeLayer.compoundPathItems.add();
for (var i = 0; i < compoundPaths.length; i++) {
    var currCompoundPath = compoundPaths[i];
    var currPathItems = currCompoundPath.pathItems;
    
    for (var j = 0; j < currPathItems.length; j++) {
        var currPathItem = currPathItems[j];
        flattened.pathItems.add(currPathItem);
    }
}

 

 But apart from copying over the pathItems that a CompoundPathItem contains it doesn't do much more.

 

I think I am missing something, any help would be appreciated!

TOPICS
Scripting

Views

215

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

Explorer , Aug 04, 2022 Aug 04, 2022

The solution for this is:

app.executeMenuCommand("noCompoundPath");
app.executeMenuCommand("compoundPath");
app.executeMenuCommand("group");

 

.. executed on all selected CompoundPathItem

Votes

Translate

Translate
Adobe
Community Expert ,
Aug 04, 2022 Aug 04, 2022

Copy link to clipboard

Copied

@JSuX 

You want to release all compoundPath Items?

Best regards

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
Explorer ,
Aug 04, 2022 Aug 04, 2022

Copy link to clipboard

Copied

The solution for this is:

app.executeMenuCommand("noCompoundPath");
app.executeMenuCommand("compoundPath");
app.executeMenuCommand("group");

 

.. executed on all selected CompoundPathItem

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
Advocate ,
Aug 05, 2022 Aug 05, 2022

Copy link to clipboard

Copied

LATEST

Bonjour Ivan,

En effet votre code ne fait pas grand chose...

Je parle du premier code.

Voici une solution, testée sur les versions 11, 12, 15 antérieures à la version 16 (CS6):

 

 

 

var doc = activeDocument;
var lay = doc.activeLayer;
var compoundPaths = lay.compoundPathItems;
if (compoundPaths.length > 1) {
  var flattened = lay.compoundPathItems.add();
  var currCompoundPath, Paths, newPath, fcolor, sColor;
      for (var i = 0; i < compoundPaths.length; i++) {
        currCompoundPath = compoundPaths[i];
        Paths = currCompoundPath.pathItems;
          for (var j = Paths.length-1; j >= 0; j--) {
            if (i == compoundPaths.length-1) {
              fcolor = Paths[j].fillColor;
              scolor = Paths[j].strokeColor;
            }
            newPath = flattened.pathItems.add();
            Paths[j].duplicate(newPath);
          }
      }
    flattened.pathItems[0].fillColor = fcolor;
    flattened.pathItems[0].strokelColor = scolor;
    for (var i = compoundPaths.length-1; i >= 1; i--) {
      compoundPaths[i].remove();
    }
}

 

 

 

Peut on savoir pourquoi vous avez besoin d'un tel script?

René

PS pour executeMenuCommand

app.executeMenuCommand("compoundPath");

cette ligne doit suffire

 

 

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