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

Is there a way to detect fills on groups via scripting?

Enthusiast ,
Jul 27, 2023 Jul 27, 2023

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.

TOPICS
Scripting

Views

125

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
Adobe
Enthusiast ,
Jul 27, 2023 Jul 27, 2023

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);
}

 

2023-07-28 10.47.58.gif

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 ,
Jul 28, 2023 Jul 28, 2023

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);
}

 

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
Enthusiast ,
Jul 28, 2023 Jul 28, 2023

Copy link to clipboard

Copied

LATEST

This is also an interesting solution with an empty rectangle.

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