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

Not present than skip lines

Participant ,
Aug 16, 2011 Aug 16, 2011

Copy link to clipboard

Copied

 

Dear people,

Is it possible for InDesign to skip rules in the script if something is not present?

Il try to illustrate what I mean:

//Map the XML tags to the defined styles.

var myDocument = app.documents.item(0);

//Part 1.

myDocument.xmlImportMaps.add(myDocument.xmlTags.item("TAGNAME_1"),

myDocument.paragraphStyles.item("myparagraphStyle_1"));

myDocument.xmlImportMaps.add(myDocument.xmlTags.item("TAGNAME_2"),

myDocument.paragraphStyles.item("myparagraphStyle_2"));

myDocument.xmlImportMaps.add(myDocument.xmlTags.item("TAGNAME_3"),

myDocument.paragraphStyles.item("myparagraphStyle_3"));

//Part 2.

myDocument.xmlImportMaps.add(myDocument.xmlTags.item("TAGNAME_a1"),

myDocument.paragraphStyles.item("myparagraphStyle_1"));

myDocument.xmlImportMaps.add(myDocument.xmlTags.item("TAGNAME_a2"),

myDocument.paragraphStyles.item("myparagraphStyle_2"));

myDocument.xmlImportMaps.add(myDocument.xmlTags.item("TAGNAME_a3"),

myDocument.paragraphStyles.item("myparagraphStyle_3"));

//Map the XML tags to the defined styles.

myDocument.mapXMLTagsToStyles();

 

Part 2 is not present in the InDesign document so the script returns with an error that he cannot find Part 2.

So is it possible to run the script like:

If part 1 and 2 is present go on

If part 2 is NOT present ignore and go on.

Already thanks for the help!

Greetings from Holland!

TOPICS
Scripting

Views

553

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

correct answers 1 Correct answer

Explorer , Aug 16, 2011 Aug 16, 2011

Hi,

Do you mean something like this (not tested):

//Map the XML tags to the defined styles.
var myDocument = app.documents.item(0);

//Part 1.
myDocument.xmlImportMaps.add(myDocument.xmlTags.item("TAGNAME_1"),
myDocument.paragraphStyles.item("myparagraphStyle_1"));
myDocument.xmlImportMaps.add(myDocument.xmlTags.item("TAGNAME_2"),
myDocument.paragraphStyles.item("myparagraphStyle_2"));
myDocument.xmlImportMaps.add(myDocument.xmlTags.item("TAGNAME_3"),
myDocument.paragraphStyles.item("myparagraphStyle_3"))

...

Votes

Translate

Translate
Explorer ,
Aug 16, 2011 Aug 16, 2011

Copy link to clipboard

Copied

Hi,

Do you mean something like this (not tested):

//Map the XML tags to the defined styles.
var myDocument = app.documents.item(0);

//Part 1.
myDocument.xmlImportMaps.add(myDocument.xmlTags.item("TAGNAME_1"),
myDocument.paragraphStyles.item("myparagraphStyle_1"));
myDocument.xmlImportMaps.add(myDocument.xmlTags.item("TAGNAME_2"),
myDocument.paragraphStyles.item("myparagraphStyle_2"));
myDocument.xmlImportMaps.add(myDocument.xmlTags.item("TAGNAME_3"),
myDocument.paragraphStyles.item("myparagraphStyle_3"));

//Part 2.
if(myDocument.xmlTags.item("TAGNAME_a1") != null)

{

     myDocument.xmlImportMaps.add(myDocument.xmlTags.item("TAGNAME_a1"),
     myDocument.paragraphStyles.item("myparagraphStyle_1"));
     myDocument.xmlImportMaps.add(myDocument.xmlTags.item("TAGNAME_a2"),
     myDocument.paragraphStyles.item("myparagraphStyle_2"));
     myDocument.xmlImportMaps.add(myDocument.xmlTags.item("TAGNAME_a3"),
     myDocument.paragraphStyles.item("myparagraphStyle_3"));

}

//Map the XML tags to the defined styles.
myDocument.mapXMLTagsToStyles();

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
Participant ,
Aug 17, 2011 Aug 17, 2011

Copy link to clipboard

Copied

LATEST

Wonderful!!!

Tested with allot more tags and indeed, Indesign is not giving me a error, just great!

Want' to give you five stars but the forum dosn't allow that

Greetings!

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