How to tag or embed data in a layer [scripting]

Community Beginner ,
Aug 14, 2022 Aug 14, 2022

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!

TOPICS
Actions and scripting

Views

57

Likes

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

correct answers 2 Correct answers

Community Expert , Aug 14, 2022 Aug 14, 2022
//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
...

Likes

Translate

Translate
Community Expert , Aug 15, 2022 Aug 15, 2022

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/

 

Likes

Translate

Translate
Community Expert ,
Aug 14, 2022 Aug 14, 2022

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) }

Likes

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 ,
Aug 15, 2022 Aug 15, 2022

Copy link to clipboard

Copied

LATEST

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/

 

Likes

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