• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
0

Applying a Graphic Style via a Script

Engaged ,
Dec 09, 2022 Dec 09, 2022

Copy link to clipboard

Copied

I used your bit of script and its worked really well!  


 

  //Apply Outline to selected shape
    for (var i = 0; i < sel.length; i++) {   
        var gStyle = doc.graphicStyles.getByName("Outline");
        gStyle.applyTo(doc.selection[i]);
    }

 

I've noticed one thing that I can't explain. 
The graphic style is set to "Align Stroke to Outside"  but occasionally it sets the graphic style to "Align Stroke to Center" is there something I can change with my code to ensure it always applies as "Align Stroke to Outside"?

 

Thank you!

TOPICS
Scripting

Views

654

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
Community Expert ,
Dec 09, 2022 Dec 09, 2022

Copy link to clipboard

Copied

Hi @BryanPagenkopf, I don't think that the scripting API provides access to the "Align Stroke to" options. Hope I am wrong. But also, I couldn't reproduce your problem occasionally it sets the graphic style to "Align Stroke to Center". Do you have a test file that demonstrates this problem? A possible solution is to reset the appearance and then re-apply the graphic style? Just thinking aloud.

- Mark

 

P.S. the line var gStyle = doc.graphicStyles.getByName("Outline") should be outside the loop, otherwise it unnecessarily gets evaluated for every item selected.

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
Engaged ,
Dec 12, 2022 Dec 12, 2022

Copy link to clipboard

Copied

@m1b Thanks for the P.S. comment, made the change!   Funny thing about my issue...   I can't recreate it now either.  I've tried repeatedly and the graphic style is applying correctly. 

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
Community Expert ,
Dec 12, 2022 Dec 12, 2022

Copy link to clipboard

Copied

LATEST

Please post back if you do find the elusive error caseā€”I'm interested to nail it down. One thing to try if you haven't already is to quit Illustrator and VSCode and run again. Sometimes variables can be persistent in memory and this can have the result of making it look like everything is running fine until you next boot Illustrator and a variable is missing or different. - Mark

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 ,
Dec 09, 2022 Dec 09, 2022

Copy link to clipboard

Copied

Just jumping in here. When I automated applying styles and had the same issue, tt was on compound paths. I dont remember if it was when they were compound paths or if I converted them to compound paths it resolved the issue. You could test easily enough manually then automate that as a first step if it resolved it.

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
Community Expert ,
Dec 09, 2022 Dec 09, 2022

Copy link to clipboard

Copied

@mcs_dean, that rings true! @BryanPagenkopf can you confirm that your problem occurs with compoundPathItems? Maybe try making two separate path items with different settings for align stroke, then compound them? Some edge case?

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