Link in Zwischenablage kopieren
Kopiert
Anyone have any suggestions for a script to merge character or paragraph styles?
Marcrest
Link in Zwischenablage kopieren
Kopiert
Problem is which property should take advantage in case they are both set differently ?
Link in Zwischenablage kopieren
Kopiert
do you have specific examples we can work with? the more specific you can be, the more we'll be able to help.
Link in Zwischenablage kopieren
Kopiert
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.
Link in Zwischenablage kopieren
Kopiert
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();
Link in Zwischenablage kopieren
Kopiert
Thank you Silly-V. It took me awhile to figure out what your script did. Unfortunately for your script to work, in this case, I would want it to change the font, not the color. However, your initial command "CharacterStyle.applyTo (textItem:any, clearingOverrides: Boolean )" intrigues me. I use another script which applies a character style to all cases of a bullet in a document. Unfortunately my current script does not clear the overrides. Is this possible?
here is my current script:
var main = function() {
var doc;
if ( app.documents.length > 0 && app.activeDocument.textFrames.length > 0 ) {
// Set the value of the character to look for
searchCharacter1 = "•";
// Iterate through all characters in the document
// and color the character that match searchWord
for ( i = 0; i < app.activeDocument.textFrames.length; i++ ) {
textArt = activeDocument.textFrames;
for ( j = 0; j < textArt.characters.length; j++) {
character = textArt.characters
if ( character.contents == searchCharacter1 ) {
// character.filled = true;
// character.fillColor = CharacterColor;
app.activeDocument.characterStyles.getByName ( "Bullet" ).applyTo ( character );
}
}
}
}
}
var u;
main();
Please remember, I am really trying to understand this scripting stuff and it's hard!? Please be gentle.
Link in Zwischenablage kopieren
Kopiert
Aha, you are simply missing the 2nd argument in .applyTo(). After your first argument, include a true like so : .applyTo(character, true);
And in my snippet if you wanted to control the font instead of color, you're going to be using the characterAttributes.textFont property. You'd have to use one of the textFont objects in app.textFonts collection.
To see all commands for styling characters, look up the characterAttributes object inside the ESTK Object Model Viewer (in help menu) or one of the AI scripting PDFs online that you may find.
Link in Zwischenablage kopieren
Kopiert
Silly-V you are amazing. This will save me hours of work : ) I will try to read up on the AI scripting PDFs. I've already downloaded them. Honestly, this is new to me and although I'm a quick study, piecing these things together is a little perplexing. Here I am at 52 and thinking I need to go back to school ; ) Cheers to all who have helped.
Link in Zwischenablage kopieren
Kopiert
Oh you're gonna have fun with this!
Weitere Inspirationen, Events und Ressourcen finden Sie in der neuen Adobe Community
Jetzt ansehen