Copy link to clipboard
Copied
Forgive me if this has been asked and answered. I've been searching on line and in the forums and cannot quite seem to find a direct answer to my question. I am converting large numbers of documents from the oldest version of InDesign to ID6. The problem I'm facing is that we used spaces in style names earlier but no longer do so for future compatability/flexibility reasons. Is there a way to write a script that will sort through existing paragraph style names and change them, or lease delete any spaces? Thanks
Copy link to clipboard
Copied
try this:
var doc=app.activeDocument;
var myPstyles=doc.allParagraphStyles, l=myPstyles.length;
while (l--){
myPstyles
.name=myPstyles .name .replace(" ","_"); //replace the space character with a underscore}
alert ("Done!\nYou can go outside an play now");
for character styles just replace the
var myPstyles=doc.allParagraphStyles with
var myPstyles=doc.allCharacterStyles
Copy link to clipboard
Copied
Vamitul, that's how I'd do it as well but you'd better add a try .. catch around the rename line. There is a small chance that a duplicate name would occur (if you have a "body text" and a "body_text" as well ), but also you cannot rename "Basic Paragraph" nor "No Paragraph style".
Copy link to clipboard
Copied
Jongware, you are right as always..
var doc=app.activeDocument;
var myPstyles=doc.allParagraphStyles, l=myPstyles.length;
while (l--){
try{
myPstyles
.name=myPstyles " ","_"); //replace the space character with a underscore.name.replace( }catch(e){}
}
alert ("Done!\nYou can go outside an play now");
ps. Still an Elite fan? See you in StarCitizen?
Copy link to clipboard
Copied
StarCitizen? Nah, I'm going to wait for Elite:Dangerous! (a.k.a. "David Braben Is Still Alive")
Copy link to clipboard
Copied
.name.replace(" ","_") replaces just the first space. To replace all spaces in a name you should use a regular expression: .name.replace(/\x20/g,"_")
Peter
Copy link to clipboard
Copied
always assumed the "replace" method to work as global. Never even knew that the first arg is actualy a regex.
guess.. live an learn.
thanks Peter
Copy link to clipboard
Copied
> Never even knew that the first arg is actualy a regex.
The first argument of replace() isn't actually a regex: it can be one.
Peter