Copy link to clipboard
Copied
Hi!
I'm looking for code to add to a script that will change the case of a specific paragraph style to AllCaps. To be clear, not to change all instances to uppercase but to change the case inherent to the style to AllCaps. Thanks in advance for any help!
Thanks,
Eubha
Hi @EubhaLiath, this is how:
var doc = app.activeDocument;
var myParaStyle = doc.paragraphStyles.itemByName('My Style');
if (myParaStyle.isValid)
myParaStyle.capitalization = Capitalization.ALL_CAPS;
- Mark
Copy link to clipboard
Copied
Why not make a secondary paragraph style that is set to all caps?
Copy link to clipboard
Copied
The styles are linked to export tags so they need to stay the same. Thank you though.
Copy link to clipboard
Copied
Hi @EubhaLiath, this is how:
var doc = app.activeDocument;
var myParaStyle = doc.paragraphStyles.itemByName('My Style');
if (myParaStyle.isValid)
myParaStyle.capitalization = Capitalization.ALL_CAPS;
- Mark
Copy link to clipboard
Copied
That's brilliant, thank you! Exactly what I needed. Only small hiccup - it doesn't work if the style is in a style folder and I'm not sure how to alter it to sort that. Any ideas?
Copy link to clipboard
Copied
Hi @EubhaLiath
var doc = app.activeDocument;
var myParaStyle = doc.paragraphStyleGroups.item("My Group").paragraphStyles.itemByName('My Style');
if (myParaStyle.isValid)
myParaStyle.capitalization = Capitalization.ALL_CAPS;
Copy link to clipboard
Copied
Perfect!
Also, for the extra case, here is how I do it when I don't want to care where the ParagraphStyle is—it might be in any paragraphStyleGroup):
var doc = app.activeDocument;
var myParaStyle = getThing(doc.allParagraphStyles, 'name', 'My Style');
if (undefined !== myParaStyle)
myParaStyle.capitalization = Capitalization.ALL_CAPS;
/**
* Returns a thing with matching property.
* {Array|collection} things - the things to look through, eg. PageItems.
* {String} key - the property name, eg. 'name'.
* {*} value - the value to match.
*/
function getThing(things, key, value) {
for (var i = 0; i < things.length; i++)
if (things[i][key] == value)
return things[i];
};