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

I created a XMP javascript types file to help with the VSCode intellisense regarding XMP.

Valorous Hero ,
Nov 01, 2022 Nov 01, 2022

Copy link to clipboard

Copied

https://github.com/Silly-V/Adobe-TS-ExtendScript/blob/master/AdobeTypes/xmp.d.ts

SillyV_0-1667315938733.png

 

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

 

 

TOPICS
Scripting

Views

353

Translate

Translate

Report

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
Community Expert ,
Nov 01, 2022 Nov 01, 2022

Copy link to clipboard

Copied

Thanks @Silly-V this is awesome. A lot of work for you but will help many!

- Mark

Votes

Translate

Translate

Report

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
Valorous Hero ,
Nov 02, 2022 Nov 02, 2022

Copy link to clipboard

Copied

LATEST

This kind of work is probably in the same vein what you had to do with the liveEffects catalogue!

Votes

Translate

Translate

Report

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
Community Expert ,
Nov 01, 2022 Nov 01, 2022

Copy link to clipboard

Copied

Thanks for sharing! it's appreciated

Votes

Translate

Translate

Report

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