Skip to main content
lMarcrest
Known Participant
March 30, 2017
Question

merging styles?

  • March 30, 2017
  • 2 replies
  • 909 views

Anyone have any suggestions for a script to merge character or paragraph styles?

Marcrest

This topic has been closed for replies.

2 replies

Disposition_Dev
Legend
March 30, 2017

do you have specific examples we can work with? the more specific you can be, the more we'll be able to help.

lMarcrest
lMarcrestAuthor
Known Participant
March 30, 2017

As an example of what I would like to do, consider this… For the sake of discussion, I have 5 character styles and 5 paragraph styles. They exist in a template. They are ultimately used to create a "standard" chart. All the styles resort to using a specific font (ie Helvetica Regular). Sometimes the "standard" chart doesn't fit and I am required to change it out for a "Condensed" chart. When I execute this change I have to change the fonts from Helvetica Regular to a Helvetica Condensed along with other technical differences. I recognize I could just change the font using find font and I recognize that I could go into each style and change the font there, but both of those options have complications (ie having to change 10 styles or when finding the font, Helvetica Regular may be used elsewhere in the document and we may not want change it there) and take time. My thought… If the "Standard" chart styles are named with "_Std" as a suffix, can we not load in the "_Cnd" styles, then merge the "_Std" styles into the "_Cnd" styles? I know I can merge graphic styles so I thought this might be possible. Thanks for your thoughts. Hoping someone can assist.

Silly-V
Legend
March 30, 2017

It appears that what you ask is possible using thes commands:

CharacterStyle.applyTo (textItem:any, clearingOverrides: Boolean )

This one will work by you having to go through all the text frames and their characters to edit the character's style. This is not great because there's no such thing as "select same character style", so you'd have to go through everything in a loop, but it is good because it leaves your existing Character Styles alone.

Next, the CharacterStyle object has a characterAttributes property, so you can edit an existing character style, a change to which should propagate through all your textframes. This is good because it is super-efficient but bad because you're changing the makeup of your character style. However, if you're using suffixes and have a naming convention, this wouldn't be a bad thing since you'll just transform one style completely into another one with name and all.

Here's an example of where changing a style itself will have an effect on the document contents (RGB document only) :

#target illustrator

function test(){

  var doc = app.activeDocument;

  var s = doc.characterStyles[1]; // Character Style 1

  var clr = new RGBColor();

  clr.red = 255;

  s.characterAttributes.fillColor = clr;

};

test();

Loic.Aigon
Legend
March 30, 2017

Problem is which property should take advantage in case they are both set differently ?