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

How can I get a file path element in XML to work in AI javascript?

New Here ,
Mar 31, 2010 Mar 31, 2010

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

TOPICS
Scripting
1.3K
Translate
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
Adobe
Engaged ,
Apr 01, 2010 Apr 01, 2010
LATEST

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

Translate
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