Copy link to clipboard
Copied
Is there a way in Javascript to retrieve an information showing in which Adobe Illustrator format was the currently open document saved?
Thanks
franK
Copy link to clipboard
Copied
You can read this info from the filehead without opening the file… Should that be your wish…
Copy link to clipboard
Copied
I'm not sure what you mean by "filehead".
I'm on Windoze XP and when I move a mouse pointer over the file, it tells me that the file is Type: Adobe Illustrator Artwork 14.0, but I know for a fact that it's not in CS4 format. When I open this file in CS4 and resave, it asks me if I really want to save in a legacy format. So, I guess, the info about the type only means that the file type is associated with Illustrator 14.
So, my question is if there is a way in JS to retrieve this kind of info about the file's compatibility mode.
Thanks
franK
Copy link to clipboard
Copied
you can select the file in Bridge and look at the Application property in the Metadata panel
and taken from majorLaser's on this post http://forums.adobe.com/message/2036802#2036802
#target illustrator
//To use the XMP objects, you must load the XMP library as an ExtendScript ExternalObject. To avoid
//loading multiple instances of the library, use code like the following:
// load the library
if (ExternalObject.AdobeXMPScript == undefined) {
ExternalObject.AdobeXMPScript = new
ExternalObject("lib:AdobeXMPScript");
}
//Create an XMPMeta object from the active documents XMPString:
var myXmp = new XMPMeta(app.activeDocument.XMPString);
// retrieve property
prop = myXmp.getProperty(XMPConst.NS_XMP, "CreatorTool");
alert("Document Created in " + prop);
Copy link to clipboard
Copied
another way using Bridge
#target bridge
// get the file
var f = new File(File.openDialog("chose file"));
// create a Thumbnail object
var t = new Thumbnail( f );
// get the metadate
var m = t.metadata;
// add namespace
m.namespace = "http://ns.adobe.com/xap/1.0/";
// get CreatorTool property
alert("Document Created in " +
m.CreatorTool);
Copy link to clipboard
Copied
Carlos;
I opened a new document and saved it as CS2 format. Then I ran the code you sent and it happily reported that the file was created in Adobe Illustrator CS4. That's correct but I'm trying to find out a way to see that the file is actually in a CS2 format. Is there a property with this information?
Thanks
franK
Copy link to clipboard
Copied
The metadata in the Bridge also shows the creator info and not the actual file format
Copy link to clipboard
Copied
You could give this a try…
var f = new File('~/Desktop/Untitled-V3.ai'); savedasVersion(f); function savedasVersion(f) { f.open(); var line = ''; do { line = f.readln(); } while (/^%%Creator:/.test(line) == false); var v = line.substring(11,line.length); f.close(); return v; }
I only have CS2 so I can't say if this is true for how newer ones save the info…
Copy link to clipboard
Copied
that'll do Mark, the file I made from CS5 to CS2 reads
%%Creator: Adobe Illustrator(R) 12.0
%%AI8_CreatorVersion: 15.0.1
I added an alert to see what's going on
alert(savedasVersion(f));
Copy link to clipboard
Copied
The function itself does NOT test that you are passing it an Illustrator .ai file. You should do that test yourself before passing the file. Otherwise the loop is going to spin forever when it can't find its expected string match. It does work for me on file versions 3 thru 12. You could have also looked for the string '%AI5_FileFormat' as that also contains the versioning but would require an additional switch. Carlos thanks its good to know that this stuff isn't going to be broken when we eventually upgrade…
The %% are commented lines in postscript (I think?)… But there are a couple of lines of useful info in there… Help you decide which files to open before passing to the app.open()
Copy link to clipboard
Copied
Yeah, a single % at the start of a line signifies a comment. Adobe habitually prepends a double %, probably to make it clear it's sort of a 'system' comment rather than a human one.
Adding support for 'any' file is easy -- just check for an end-of-file. If so, this little rewrite returns null. Otherwise, the version string is returned.
var f = new File('~/Desktop/Untitled-V3.ai');
alert (savedasVersion(f));
function savedasVersion(f)
{
if (f.open() == false) return null;
var line = '';
while (!f.eof)
{
line = f.readln();
if (/^%%Creator:/.test(line))
{
f.close();
return line.substring(11);
}
}
f.close();
return null;
}
Copy link to clipboard
Copied
Jong that is better… Im liking that adjustment… I tinkered a couple of times and thats bang on what I had in mind…
line.substring(11)
Hum, no second parameter does to eos (end of string) will check…
Find more inspiration, events, and resources on the new Adobe Community
Explore Now