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

Adding an offset path and stroke to a group of objects

Community Beginner ,
Mar 27, 2025 Mar 27, 2025

I have a group that contains multiple objects.  I am trying to add an offset path on each object, then add a 1pt black stroke to each object and each offset path.

 

The offset paths are being created (almost) correctly, but the stroke is only being applied to one object - from what I can tell, it seems to be the back-most object in the group.

 

I originally had the stroke being applied inside the first for loop, when I was adding the offset path, but expandStyle then made the path into a new object, which I don't want, so I moved the stroke logic to the end.

 

Can anyone see what I need to change to get the stroke on all objects and offset paths?

 

And bonus question ... if my object is a square, the offset path created is a filled square.  But if my object is a triangle, the offset path is a triangle with a hollow middle - a compound path.  Is there a way to make it fill that in so I have a solid triangle which I think should just be a path?

 

        var offsetEffectString = 
            '<LiveEffect name="Adobe Offset Path">' +
            '<Dict data="I jntp 2 R mlim 4 R ofst 18"/>' +
            '</LiveEffect>';

        // Go through each item in the group
        var groupItems = selection[0].pageItems;
        for (var i = groupItems.length - 1; i >= 0; i--) { 
            var item = groupItems[i];

            var offsetPath = item.duplicate();
            offsetPath.selected = true;
            offsetPath.applyEffect(offsetEffectString);
            offsetPath.filled = true;
            offsetPath.fillColor = white;
        }

        app.redraw();
        app.executeMenuCommand('expandStyle');

        // Re-fetch the pageItems collection after expanding styles
        groupItems = selection[0].pageItems;

        // Apply stroke to all items
        for (var i = groupItems.length - 1; i >= 0; i--) { 
            var item = groupItems[i];
            if (item.typename === "PathItem") { 
                // Apply stroke to PathItem
                item.strokeColor = black;
                item.strokeWeight = 1;
            } else if (item.typename === "CompoundPathItem") {
                // Apply stroke to each path in CompoundPathItem
                for (var j = 0; j < item.pathItems.length; j++) {
                    var subPath = item.pathItems[j];
                    subPath.strokeColor = black;
                    subPath.strokeWeight = 1;
                }
            }
        }

 Before:

Ezmash_1-1743122606703.pngexpand image

 

After:

Ezmash_2-1743122692585.pngexpand image

Only the dark triangle has the stroke.

(Also, I noticed the offset paths are not all being moved behind the original objects, but I know how to fix that)

TOPICS
How-to , Scripting
117
Translate
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 Beginner , Mar 27, 2025 Mar 27, 2025

Solved - I just needed to add item.stroked = true and subPath.stroked = true.

Translate
Adobe
Community Beginner ,
Mar 27, 2025 Mar 27, 2025
quote

I originally had the stroke being applied inside the first for loop, when I was adding the offset path, but expandStyle then made the path into a new object, which I don't want, so I moved the stroke logic to the end.

 

What I meant to say here was that expandStyle made the stroke into a new object, which I don't want.

I couldn't find an edit button to fix my post.

Translate
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 Beginner ,
Mar 27, 2025 Mar 27, 2025
LATEST

Solved - I just needed to add item.stroked = true and subPath.stroked = true.

Translate
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