Copy link to clipboard
Copied
https://github.com/Silly-V/Adobe-TS-ExtendScript/blob/master/AdobeTypes/xmp.d.ts
I saw that there was no types file for XMP. It seemed that for VSCode this is one of the more obscure apis that had no online types file. So I copied the whole set of information from the xmp javascript online tools guide documentation page and put it into a typescript declarations format.
It is kind of helpful, maybe it can be made even better. However, it seems ok to start using.
At the end of the file is an example of making an array and putting custom object elements into it.
Using this types file combined with the online doc, an ESTK debugger of the old kind which I happened to have, it made the process of dissecting and figuring out the example code easier. I got the hint about using bracket accessors and a one-based index as the field-name from here: https://indisnip.wordpress.com/2010/09/07/storing-custom-data-into-indesign-file-xmp/
// * Making an array which contains object elements with properties.
var theFile = File("~/Desktop/test.pdf");
if (xmpLib==undefined) var xmpLib = new ExternalObject('lib:AdobeXMPScript');
var xmpFile = new XMPFile(theFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
var xmpPackets = xmpFile.getXMP();
var mt = new XMPMeta(xmpPackets.serialize());
XMPMeta.registerNamespace("http://ns.my-special-namespace/1.0/", "myNs:");
var arrayToSet = [
{ name : "ABC", width : 50, height : 100 },
{ name : "Name-2", width : 125, height : 75 },
];
mt.setProperty("http://ns.my-special-namespace/1.0/", "mySpecialArray", "", XMPConst.PROP_IS_ARRAY);
for (var i = 0; i < arrayToSet.length; i++) {
var oneBasedIndex = i + 1;
var x = arrayToSet[i];
mt.setStructField("http://ns.my-special-namespace/1.0/", "mySpecialArray[" + oneBasedIndex + "]", XMPConst.NS_RDF, "name", x.name);
mt.setStructField("http://ns.my-special-namespace/1.0/", "mySpecialArray[" + oneBasedIndex + "]", XMPConst.NS_RDF, "width", x.width);
mt.setStructField("http://ns.my-special-namespace/1.0/", "mySpecialArray[" + oneBasedIndex + "]", XMPConst.NS_RDF, "height", x.height);
}
if (xmpFile.canPutXMP(xmpPackets)) {
xmpFile.putXMP(mt);
}
xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
// app.open(theFile); // View the result XMP in the app
Copy link to clipboard
Copied
Thanks @Silly-V this is awesome. A lot of work for you but will help many!
- Mark
Copy link to clipboard
Copied
This kind of work is probably in the same vein what you had to do with the liveEffects catalogue!
Copy link to clipboard
Copied
Thanks for sharing! it's appreciated