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

Wish to check if a style exists; create it if it doesn't exist.

Explorer ,
Mar 14, 2008 Mar 14, 2008

Copy link to clipboard

Copied

Hello,

I am trying to write a script that will check to see if a style already exists in a document. If it does, fine, I'll use it. If it does not, then I want to create the style. The following script errors out, telling me there is an invalid parameter.

if(document.objectStyles.item().name !== myCharStyle){
var myCharStyle = myDoc.characterStyles.add({name:"myCharStyle"});
}

I have tried using the try/catch function as it is written in Adobe's InDesign Scripting Guide: JavaScript but this also just errors out.

Thanks,
Tom
TOPICS
Scripting

Views

604

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 ,
Mar 14, 2008 Mar 14, 2008

Copy link to clipboard

Copied

LATEST
Try this:

if(myDoc.characterStyles.item ("cstyle") == null)
myDoc.characterStyles.add({name:"cstyle"});
var myCharStyle = myDoc.characterStyles.item ("cstyle");

"cstyle" is the name you see in the char. style panel, myCharStyle is a variable -- these are not the same thing.

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