Copy link to clipboard
Copied
Is there a script where I could change the font sizes in a document based on character style? For example:
- If character style = "Style1", then change font size to 10pt
- If character style = "Style2", then change font size to 13pt
1 Correct answer
Okay, here you go. Just change the array where I've commented "change these". Add or subtract lines with [ 'style name', point-size ] with comma between each. - Mark
function main() {
setCharacterStylesPointSize(
// the document
app.activeDocument,
[
// change these:
['Style1', 10],
['Style2', 13],
['Style3', 20],
['Style4', 22]
]
)
function setCharacterStylesPointSize(doc, changes) {
...
Copy link to clipboard
Copied
It is possible with a script, but I need to ask: why not just change the point size *in* the character styles? I think there may more to your question.
- Mark
Copy link to clipboard
Copied
Thanks Mark. The only problem with that is I have about 15 character styles and was hoping for a more streamlined way to do it. If all else fails, I could just update the character styles.
Copy link to clipboard
Copied
I think I see: so you need to change these point sizes in a predictable way, again-and-again, and you don't want to do it manually? Then maybe what you need is a script that changes the font sizes in the character styles? So you'd need to specify the changes in the script, eg. setStylesFontSize([ ['Style1',10], ['Style2',13], ... ]). It wouldn't be hard to write the script, but it would take much longer than the time it would take to change 15 character styles manually, so you'd want to judge if it was worth it.
- Mark
Copy link to clipboard
Copied
Exactly! I create wedding magazines and we use a template, so we do this over and over again. Long term I think it would save time to produce the script that does it. I just don't know where to start, or if there's a framework out there to begin with?
Copy link to clipboard
Copied
Okay, here you go. Just change the array where I've commented "change these". Add or subtract lines with [ 'style name', point-size ] with comma between each. - Mark
function main() {
setCharacterStylesPointSize(
// the document
app.activeDocument,
[
// change these:
['Style1', 10],
['Style2', 13],
['Style3', 20],
['Style4', 22]
]
)
function setCharacterStylesPointSize(doc, changes) {
for (var i = 0; i < changes.length; i++) {
var style = doc.characterStyles.itemByName(changes[i][0]),
size = changes[i][1];
if (style.isValid) style.pointSize = size;
}
}
} // end main
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Update Character Styles');
Copy link to clipboard
Copied
THANK YOU! This worked perfectly!!

