Copy link to clipboard
Copied
Hello all, I was wondering if there was a best-practice way of storing data in an Illustrator document.
My quick attempt was to simply create a "Settings" layer (locked and hidden) with a PageItem named after the script, and store JSON in the "note" property. This works mostly ok, but has problems:
Any ideas would be much appreciated!
Hi, you can save your datas in your doc's metadatas 🙂
You have to check documentation about XML and XMP metadatas.
Copy link to clipboard
Copied
Hi, you can save your datas in your doc's metadatas 🙂
You have to check documentation about XML and XMP metadatas.
Copy link to clipboard
Copied
Have a look at the following for detailed description on XMP scripting API as mentioned by Steven
-Manan
Copy link to clipboard
Copied
Thank you both, that is perfectly what I needed!
It did take me most of the morning to get it working though, so if it helps anyone, here's what I ended up with.
I used tenA's XMPtool.jsx. Thank you, tenA, if you're listening!
Here's tenA's code, with trivial modifications for my needs:
XMPtool = {
ns: "http://ns.adobe.com/xap/1.0/",
prefix: "xmp:",
f: new Object(),
read: function (prop) {
if (xmpLib == undefined) var xmpLib = new ExternalObject('lib:AdobeXMPScript');
var xmpFile = new XMPFile(this.f.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_READ);
var xmpPackets = xmpFile.getXMP();
var xmp = new XMPMeta(xmpPackets.serialize());
var val;
try {
val = xmp.getProperty(this.ns, prop).toString();
} catch (error) {}
return val;
},
write: function (prop, val) {
if (xmpLib == undefined) var xmpLib = new ExternalObject('lib:AdobeXMPScript');
var xmpFile = new XMPFile(this.f.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
var xmp = xmpFile.getXMP();
var mt = new XMPMeta(xmp.serialize());
XMPMeta.registerNamespace(this.ns, this.prefix);
mt.setProperty(this.ns, prop, val);
if (xmpFile.canPutXMP(xmp)) xmpFile.putXMP(mt);
xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
}
}
// set file reference to the active document
XMPtool.f = new File(app.activeDocument.fullName);
// example write
XMPtool.write('TestProperty1', 'TestValue1');
// example read
alert( XMPtool.read("TestProperty1") );
Copy link to clipboard
Copied
You can add tag to an object on the document. Tags can be used to store key/value data in them. Tags can be stored on pageitems and not document object, so you will have to identify an object that you will use to save your data in. See the following for examples and more description
https://illustrator-scripting-guide.readthedocs.io/jsobjref/Tag/#jsobjref-tag
https://illustrator-scripting-guide.readthedocs.io/jsobjref/Tags/
-Manan
Copy link to clipboard
Copied
That's great too, Manan. I can think of a few uses for those! 😃