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!
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"))
...
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();
Copy link to clipboard
Copied
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!