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

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

Community Expert ,
Sep 29, 2023 Sep 29, 2023

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

552
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

correct answers 3 Correct answers

Community Expert , Sep 29, 2023 Sep 29, 2023

select your group before running

activeDocument.defaultStrokeWidth = 6

Votes

Translate
Community Expert , Sep 30, 2023 Sep 30, 2023

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

 

var strokeSize = activeDocument.defaultStrokeWidth;

Votes

Translate
Community Expert , Oct 01, 2023 Oct 01, 2023

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 🤷🏼‍:male_sign:)...

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.con
...

Votes

Translate
Adobe
Community Expert ,
Sep 29, 2023 Sep 29, 2023

Copy link to clipboard

Copied

Please post only Scripting solutions!

Votes

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
Community Expert ,
Sep 29, 2023 Sep 29, 2023

Copy link to clipboard

Copied

select your group before running

activeDocument.defaultStrokeWidth = 6

Votes

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
Community Expert ,
Sep 29, 2023 Sep 29, 2023

Copy link to clipboard

Copied

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

Votes

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
Community Expert ,
Sep 30, 2023 Sep 30, 2023

Copy link to clipboard

Copied

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

 

Votes

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
Community Expert ,
Sep 30, 2023 Sep 30, 2023

Copy link to clipboard

Copied

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

 

var strokeSize = activeDocument.defaultStrokeWidth;

Votes

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
Community Expert ,
Oct 01, 2023 Oct 01, 2023

Copy link to clipboard

Copied

LATEST

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 🤷🏼‍:male_sign:)...

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

Votes

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
Community Expert ,
Sep 30, 2023 Sep 30, 2023

Copy link to clipboard

Copied

or make a copy, select the copy and Expand Appearance, one of the paths should have the stroke size you need

Votes

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