Copy link to clipboard
Copied
I need to tag/embed a few hundred bytes of related data (saved settings for a script) in a PS layer, specifically an EPS SmartObject. To be clear, I just want my script to store & retrieve data in a layer while keeping the image as-is, don't want the data displayed. Different layers might have different data stored with each. Same idea as the "label' attribute of objects in InDesign scripts.
It's tempting to embed the data in the layer's name, but that could easily get messed up by the user renaming the layer, etc.
Any tips, ideas, tricks?
Thanks!
//load external library
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript')
// set custom namespace properties
const myCustomNamespace = 'layerMetadata',
myCustomPrefix = 'EmbedData:',
myProperty = 'label';
//write metadata in active layer
try { xmpMeta = new XMPMeta(app.activeDocument.activeLayer.xmpMetadata.rawData) } catch (e) { xmpMeta = new XMPMeta() }
XMPMeta.registerNamespace(myCustomNamespace, myCustomPrefix
...
I have not personally explored "per layer metadata", so here is some more reading:
https://www.photoshopgurus.com/forum/threads/read-write-metadata-to-image-layer.67949/
Copy link to clipboard
Copied
//load external library
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript')
// set custom namespace properties
const myCustomNamespace = 'layerMetadata',
myCustomPrefix = 'EmbedData:',
myProperty = 'label';
//write metadata in active layer
try { xmpMeta = new XMPMeta(app.activeDocument.activeLayer.xmpMetadata.rawData) } catch (e) { xmpMeta = new XMPMeta() }
XMPMeta.registerNamespace(myCustomNamespace, myCustomPrefix);
xmpMeta.setProperty(myCustomNamespace, myProperty, 'few hundred bytes of related data')
app.activeDocument.activeLayer.xmpMetadata.rawData = xmpMeta.serialize()
//get metadata from active layer
try {
xmpMeta = new XMPMeta(app.activeDocument.activeLayer.xmpMetadata.rawData)
if (xmpMeta.doesPropertyExist(myCustomNamespace, myProperty)) alert(xmpMeta.getProperty(myCustomNamespace, myProperty).value)
} catch (e) { alert(e) }
Copy link to clipboard
Copied
I have not personally explored "per layer metadata", so here is some more reading:
https://www.photoshopgurus.com/forum/threads/read-write-metadata-to-image-layer.67949/