Copy link to clipboard
Copied
Hi guys, so i've uploaded a xml file to my current document. I'm working through this api and i'm currently trying to style the xml tags that I have imported using a template. Please take a look at my code and tell me what I am missing.
Setup.js:
var myDocument = app.open(File(app.activeScript.parent.fsName + '/firstTemplate.indt'));
var curFile = app.activeScript.parent.fsName + '/library.xml';
myDocument.importXML(File(curFile));
// need to apply styling to tags
myDocument.mapXMLTagsToStyles();
var root = myDocument.xmlElements[0]; // root
var element = root.xmlElements[0];
root.placeXML(myDocument.textFrames[0]);
myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;
myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;
myDocument.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;
var price = root.evaluateXPathExpression('//pricing');
My Indt file has paragraph stylings that are to be applied to any document I run the script on just as long as the same xml tags match up to the styling.
Thank you!
mapXMLTagsToStyles doesn't work differently in scripting than in UI. You need to let InDesign know which styles have to be bound to tags through xmlImportMaps which can be translated by the map tags to styles in the tags panel :
var myImportMap = doc.xmlImportMaps.add(myTag,myStyle);
doc.mapXMLTagsToStyles();
Copy link to clipboard
Copied
mapXMLTagsToStyles doesn't work differently in scripting than in UI. You need to let InDesign know which styles have to be bound to tags through xmlImportMaps which can be translated by the map tags to styles in the tags panel :
var myImportMap = doc.xmlImportMaps.add(myTag,myStyle);
doc.mapXMLTagsToStyles();
Copy link to clipboard
Copied
@Loic.Aigon Is there a way to force Indesign to re-apply an existing map, or import a map from another file (i.e. a template file)?
I am moving XML elements between files, but the existing map is not being applied to the new elements properly.
Copy link to clipboard
Copied
Given that the UI doesn't allow to import such rules, the DOM doesn't expose such functionnality.
That said, recall
var myImportMap = doc.xmlImportMaps.add(myTag,myStyle);
doc.mapXMLTagsToStyles();
and that should do it (once again in the UI, if you reset styles maps, contents styling get updated).
Copy link to clipboard
Copied
@Loic.Aigon The trouble I was having was that adding just a single style seems to remove all of the other mapped styles. Do I need to re-map ALL of my mapped styles within the script?
Copy link to clipboard
Copied
@Loic.Aigon I take it back, re-mapping the one style seems to have worked.