I'm in need of a script to import a xml as variables in Illustrators variables panel.
I have the correct formatted XML and it works as expected when importing manually. I would like to automate this through Switch, which is why I'm looking for at script that can do this.
Anyone?
Import variables in Illustrator
Re: Import variables in Illustrator
485 views but 0 replies Well, I found help elsewhere so here is the solution if anybody else would need it:
main();
//------------- MAIN CLOSURE -----------------------------
//--------------------------------------------------------
function main() {
var document = app.activeDocument;
var dataFile = new File("<path to the xml file>");;
document.importVariables(dataFile);
var dataSet = document.dataSets.getByName('<name of required data set>');
document.activeDataset = dataSet;
dataSet.display();
redraw();
}
main();
//------------- MAIN CLOSURE -----------------------------
//--------------------------------------------------------
function main() {
var document = app.activeDocument;
var dataFile = new File("<path to the xml file>");;
document.importVariables(dataFile);
var dataSet = document.dataSets.getByName('<name of required data set>');
document.activeDataset = dataSet;
dataSet.display();
redraw();
}
Re: Import variables in Illustrator
There was not much to go by Erik And the Illustrator scripting documentation was also not very helpful when looking for XML. Variables is the keyword I see now. A couple of remarks about the code snippet, though.
There is no need to have the main procedure but it is certainly not wrong. As documented here (https://www.enfocus.com/manuals/UserGui ... tions.html) you should use $doc instead of app.activeDocument, and you could make use of the arguments to get cleaner code. Not tested, but this is how I would rewrite it:
There is no need to have the main procedure but it is certainly not wrong. As documented here (https://www.enfocus.com/manuals/UserGui ... tions.html) you should use $doc instead of app.activeDocument, and you could make use of the arguments to get cleaner code. Not tested, but this is how I would rewrite it:
Code: Select all
var dataFile = new File($arg1); //place the path to the XML in the first argument of the element
var datasetName = $arg2; //and the dataset name in the second argument
$doc.importVariables(dataFile);
var dataSet = $doc.dataSets.getByName(datasetName);
$doc.activeDataset = dataSet;
dataSet.display();
redraw();