Copy link to clipboard
Copied
I'd like to expand the ever tricky transparent paths inside of filled groups, but can't seem to detect the fill on the group specifically. I tried app.activeDocument.groupItems[0].filled and app.activeDocument.groupItems[0].fillColor, both of which produce undefined. I tried app.activeDocument.defaultFillColor to indicate when the selection color changes, but it picks up the color of the art within the group even if the group doesn't have an appearance.
Is there a way to detect the fill/appearance on a group? My plan is to loop through each path inside each group and determine if those aren't filled so I could just assume expand appearance to the group, but wanted a more direct way to test the group first.
Copy link to clipboard
Copied
I don't think there is a direct way to get the appearance of a group. I played around with the trick of converting a copy of the group into a compound path.
main();
function main() {
var grpColor;
var sel = app.selection;
if (sel[0].typename !== 'GroupItem') return;
var dup = sel[0].duplicate();
app.selection = [];
dup.selected = true;
app.executeMenuCommand('compoundPath');
if (app.selection[0].typename === 'CompoundPathItem' && app.selection[0].pathItems.length) {
if (app.selection[0].pathItems[0].filled) grpColor = app.selection[0].pathItems[0].fillColor;
}
app.selection[0].remove();
app.selection = sel;
alert(grpColor);
}
Copy link to clipboard
Copied
Thanks! I thought that may be the case. I expanded on your logic, because if I'm reading correctly it's not really making a comparison of what the fill is of pathItem 0 before and after compoundPath. I went a slightly different route however and added a path to the duplicated group, removed fill and stroke, removed every other page item in the group, expanded and ungrouped. If the path reads no color, then there wasn't a fill, if a color does show up then the group had an appearance. The tricky part would be if there's a layered appearance, but if one were trying to catch that, the pageItems look to be a multiple of the original once expanded.
main();
function main() {
var grpColor;
var sel = app.selection;
if (sel[0].typename !== 'GroupItem') return;
var dup = sel[0].duplicate();
capture = dup.pathItems.rectangle(-50, 50, 100, 100);
capture.name = "CAPTURING";
capture.filled = false;
capture.stroked = false;
app.selection = [];
dup.selected = true;
//Delete most things in dup except the new capturing shape
for (var g = dup.pageItems.length-1; g >= 1; g--){
dup.pageItems[g].remove();
}
//Reselect just in case
dup.selected = true;
app.executeMenuCommand('expandStyle');
app.executeMenuCommand('ungroup');
groupColor = app.activeDocument.selection[0].fillColor;
alert(groupColor);
}
Copy link to clipboard
Copied
This is also an interesting solution with an empty rectangle.