How can I get a file path element in XML to work in AI javascript?
Copy link to clipboard
Copied
Hi all - this is my first post. I'm pretty familiar with javascript, but I'm new to the Adobe scripting environment.
Our client wants Illustrator at startup to load a certain pattern swatch. It works fine when I hard code the pattern file path, but it needs to be user configurable, so I put the file path info in an XML file to be read in at startup. The XML file is read in and the elements are extracted into varibles. When I concatenate the variables to create the file path string and try to open the pattern file, it says file not found.
Here is my source code:
--------------------------------------------------
var fileObj = new File("aiConfig.xml");
fileObj.open("r:");
var xmlString = new XML(fileObj.read());
var driveLetter = xmlString.fullPathName.driveLetter.text();
var filePath = xmlString.fullPathName.filePath.text();
var fileName = xmlString.fullPathName.fileName.text();
var fullFilePath = driveLetter + filePath + fileName;
var styled_ai = app.open(new File(fullFilePath));
app.activeDocument = styled_ai;
--------------------------------------------------
Here is aiConfig.xml:
--------------------------------------------------
<?xml version="1.0" encoding="windows-1252" ?>
<aiConfig>
<fullPathName>
<driveLetter>C:</driveLetter>
<filePath>/Program Files/Adobe/Adobe Illustrator CS4/Presets/en_US/Swatches/Patterns/Decorative/</filePath>
<fileName>Decorative_Modern.ai</fileName>
</fullPathName>
</aiConfig>
--------------------------------------------------
Any help would be greatly appreciated - this is driving me a little crazy.
Thanks,
Tom
Explore related tutorials & articles
Copy link to clipboard
Copied
Hi Tomchag,
Your script works fine on MAC OS X & illustrator CS4.
i have change only pathway to aiConfig.xml like this:
var fileObj = new File("/Volumes/LaCie/aiConfig.xml"); //<- path of my external HDD should be D:/ on windows
and the contents in aiConfig.xml to :
<?xml version="1.0" encoding="windows-1252" ?>
<aiConfig>
<fullPathName>
<driveLetter></driveLetter>
<filePath>/Applications/Adobe Illustrator CS4/Presets.localized/fr_FR/Nuancier/</filePath>
<fileName>VisiBone2.ai</fileName>
</fullPathName>
</aiConfig>
So.. i notice twice thing:
1) complete file and path for aiConfig.xml
2) i didn't use drive letter (but it's specific to windows)
I hope this post can help you
Cyao, art.chrome

