• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Changing Paragraph Style Names

Explorer ,
Nov 20, 2012 Nov 20, 2012

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

TOPICS
Scripting

Views

2.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Nov 20, 2012 Nov 20, 2012

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 21, 2012 Nov 21, 2012

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".

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Nov 21, 2012 Nov 21, 2012

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.name.replace(" ","_"); //replace the space character with a underscore

}catch(e){}

}

alert ("Done!\nYou can go outside an play now");

ps. Still an Elite fan? See you in StarCitizen?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 21, 2012 Nov 21, 2012

Copy link to clipboard

Copied

StarCitizen? Nah, I'm going to wait for Elite:Dangerous! (a.k.a. "David Braben Is Still Alive")

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 23, 2012 Nov 23, 2012

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Nov 24, 2012 Nov 24, 2012

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 24, 2012 Nov 24, 2012

Copy link to clipboard

Copied

LATEST

> 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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines