Skip to main content
Community Expert
September 29, 2023
Answered

Illustrator Scripting: changing stroke or fill of groupItems (not content of a group)

  • September 29, 2023
  • 2 replies
  • 1094 views

In Illustrator Stroke and Fill can be applied to a Group itself in the Appearance Panel.

They then will visualy overright the Strokes of all objects inside this group.

 

I wonder if it is possible to check / change the strokeWidth of such a group by script as the scripting reference seams not have any specific attributes for this case.

check attached file (rename as .ai) to play around...

 

Anyone any idea / solution in mind?

 

Thanks

Nils

This topic has been closed for replies.
Correct answer Nils M. Barner

Hi Nils, yes! select your group and check the default stroke

 

var strokeSize = activeDocument.defaultStrokeWidth;

damn! this one was too easy! 😂

but it makes perfect sense (i will never get used to these default stroke functions.... and i still don't understand why they don't just give us a direct control function for group properties 🤷🏼‍♂)...

thank you soo much for helping me out!

So here's my final Script:

var docRef = app.activeDocument;
var minStrokeWidth = 4;


for (var p=0; p<docRef.pageItems.length; p++) {
    docRef.selection = null;
    var myPI = docRef.pageItems[p];

    if (myPI.constructor.name == "GroupItem") {
        myPI.selected = true;
        var myStrokeWidth = activeDocument.defaultStrokeWidth;
        if (myStrokeWidth < minStrokeWidth) {
            activeDocument.defaultStrokeWidth = minStrokeWidth;
        }
        docRef.selection = null;
    }
}

2 replies

CarlosCanto
Community Expert
Community Expert
September 30, 2023

select your group before running

activeDocument.defaultStrokeWidth = 6
CarlosCanto
Community Expert
Community Expert
September 30, 2023

wait, maybe I misunderstood, your sample file doesn't give any clues as what you need, please provide before and after if I did.

Community Expert
September 30, 2023

Hi CarlosCanto,

selecting the groups worked out well so far (see script below)

 

Big question now is:

Is it possible to check the strokeWidth of such a group before changing (getting the value before setting a new one)?

 

example file setting are the following:

- the sample file includes 2 similar groups, each containing 2 rectangles

- all rectangles do not have any stroke

- but a 3pt stroke was added for the whole group (both groups)

 

Here's my Script so far:

var docRef = app.activeDocument;
var pIs = docRef.pageItems;

for (var p=0; p<pIs.length; p++) {
    docRef.selection = null;

    if (pIs[p].constructor.name == "GroupItem") {
        pIs[p].selected = true;
        activeDocument.defaultStrokeWidth = 6;
    }
}

 

Community Expert
September 29, 2023

Please post only Scripting solutions!