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!
The solution for this is:
app.executeMenuCommand("noCompoundPath");
app.executeMenuCommand("compoundPath");
app.executeMenuCommand("group");
.. executed on all selected CompoundPathItem
Copy link to clipboard
Copied
Copy link to clipboard
Copied
The solution for this is:
app.executeMenuCommand("noCompoundPath");
app.executeMenuCommand("compoundPath");
app.executeMenuCommand("group");
.. executed on all selected CompoundPathItem
Copy link to clipboard
Copied
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