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

Accessing per-layer metadata from plugin

Explorer ,
Jan 20, 2015 Jan 20, 2015

Hello,

I can access the document-level metadata of a PSD file (as done in the Propertizer sample plugin in the SDK) with something like this:

Handle h = NULL;

OSErr error = sPSProperty->getPropertyProc(kPhotoshopSignature, 'xmpd', 0, NULL, &h);

Is there a way to access per-layer metadata from a C++ plugin?

Thanks

TOPICS
SDK
5.5K
Translate
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
Jan 20, 2015 Jan 20, 2015

You cannot get to the per layer metadata vie the Properties suite. You will need to use an automation plugin and access the classLayer and the "XMPMetadataAsUTF8" string.

Translate
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
Explorer ,
Jan 20, 2015 Jan 20, 2015

Thanks! Is it not possible to get this in an Export plugin?

Translate
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
Jan 21, 2015 Jan 21, 2015

It is not possible in Export either. You need an automation plug-in type. You could have an automation plug-in listen to "your export" event and then send out the XMP data for each layer.

Translate
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
Explorer ,
Jan 22, 2015 Jan 22, 2015

I see. I searched in the SDK samples, but couldn't find "XMPMetadataAsUTF8" being used. Any pointer to how this constant can be used to retrieve the data would be much appreciated.

Translate
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
Explorer ,
Feb 11, 2015 Feb 11, 2015

I studied Getter automation plugin for the same purpose.

According to that we can extract properties of a layer via PIActionDescriptor.

I extract all the key-value pairs of entire layer description but still I can't find a way to access per-layer meta data.

Tom Ruark wrote:

"use an automation plugin and access the classLayer and the "XMPMetadataAsUTF8" string.

Can you explain your idea further?  In SDK5, there is no at least single usage of "XMPMetadataAsUTF8".

Translate
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
Feb 11, 2015 Feb 11, 2015

Here is a JavaScript example. Converting to C++ is an exercise I'll leave to you. I am not using the DOM for setting the XMP.

documents.add();

activeDocument.artLayers.add();

var dataForLayer = """<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?> \

<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.5-c021 79.154911, 2013/10/29-11:47:16        ">\

   <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">\

      <rdf:Description rdf:about=""\

            xmlns:xmp="http://ns.adobe.com/xap/1.0/"\

            xmlns:dc="http://purl.org/dc/elements/1.1/"\

            xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/">\

         <xmp:CreatorTool>Toms Awesome App CC (Windows)</xmp:CreatorTool>\

         <xmp:CreateDate>2014-03-26T08:50:14-07:00</xmp:CreateDate>\

         <xmp:ModifyDate>2014-03-26T08:50:14-07:00</xmp:ModifyDate>\

         <xmp:MetadataDate>2014-03-26T08:50:14-07:00</xmp:MetadataDate>\

         <dc:format>application/vnd.adobe.photoshop</dc:format>\

         <photoshop:ColorMode>3</photoshop:ColorMode>\

         <photoshop:ICCProfile>Adobe RGB (1998)</photoshop:ICCProfile>\

      </rdf:Description>

   </rdf:RDF>

</x:xmpmeta>""";

var xmpDataKey = stringIDToTypeID( "XMPMetadataAsUTF8" );

var classLayer = charIDToTypeID( 'Lyr ' );

var classDocument = charIDToTypeID( 'Dcmn' );

var keyTarget = charIDToTypeID( 'null' );

var keyTo = charIDToTypeID( 'T   ' );

var eventSet = charIDToTypeID( 'setd' );

var classProperty = charIDToTypeID( "Prpr" );

var target = new ActionReference();

target.putProperty( classProperty, xmpDataKey );

target.putIdentifier( classLayer, activeDocument.activeLayer.id );

target.putIdentifier( classDocument, activeDocument.id );

var desc = new ActionDescriptor();

desc.putReference( keyTarget, target );

var dataDesc = new ActionDescriptor();

dataDesc.putString( xmpDataKey, dataForLayer );

desc.putObject( keyTo, xmpDataKey, dataDesc );

executeAction( eventSet, desc );

var test = activeDocument.activeLayer.xmpMetadata.rawData == dataForLayer;

alert(activeDocument.activeLayer.xmpMetadata.rawData + " : " + test);

Translate
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
Explorer ,
Feb 15, 2015 Feb 15, 2015

Hi Tom,

Following your example I have set layer meta data. Again, I have verified whether meta data are set for the layer or not (It is set).

And I used Getter sample plugin for extract those  custom meta info. In Geeter example I used following two functions and checked the Getter.log.

GetLayerInfo(logfilename);         // Even I set meta tags, still meta data can not be obtain under key - "XMPMetadataAsUTF8". 

GetDocumentInfo(logfilename);  // If I set document meta tags those can be obtain under key - "XMPMetadataAsUTF8".

If you have inputs stating, why layer meta tags were not obtain while document meta extracting, that will be much helpful.

Observations -

  • In .psd file, document meta is store in <xmpmeta> description.
  • Layer meta data is in binary format. Only layer name I can search in PSD file.

Thanks

Translate
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
Feb 19, 2015 Feb 19, 2015

We don't include it in the "give me all the keys" and we make it binary in PSD to give a bit of obfuscation for the data.Use the following routine instead. I believe the type is a Handle in C land. The "desiredKey" would be the runtime id of XMPMetadataAsUTF8. The desiredClass would be classLayer.

SPErr PIUGetInfo(DescriptorClassID desiredClass,

  DescriptorKeyID desiredKey,

  void * returnData,

  void * returnExtraData)

Translate
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
Explorer ,
Feb 25, 2015 Feb 25, 2015

Hi Tom,

It works !!!

Need to get the runtime id of the key kXMPMetadataAsUTF8Str

- Same way, I get the number of layer in the document using keyNumberOfLayers.

Here, I traversed all the layers available using layer index.

Therefore, I used the same thing in following way.

PIUGetInfoByIndex(int32 layerIndex,

DescriptorClassID desiredClass,

  DescriptorKeyID desiredKey,

  void * returnData,

  void * returnExtraData

);

Translate
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
Explorer ,
Feb 26, 2015 Feb 26, 2015

Hi Tom,

I am trying to export each layers to PNG with layer meta data. I tried to do the exporting in the automation plugin itself but seems it is not success. Can you explain me your idea behind this?

tom says,

You could have an automation plug-in listen to "your export" event and then send out the XMP data for each layer.

API to listen and send to exporter would be help me lot.

Translate
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
Feb 26, 2015 Feb 26, 2015

Are saving the PNG for each layer in an automation plug-in? If yes, then just get the XMP for each layer and make a side car file. Layer1.png Layer1.xmp

If no, then tell me how you are saving the PNG. Is the user doing that? If yes, then look at the Listener plug-in code. Add in the "save a png" and "save" as an option. I'll need more details on how you set up the file before the manual save by the user.

Translate
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
Explorer ,
Feb 26, 2015 Feb 26, 2015
Are saving the PNG for each layer in an automation plug-in? 

I tried but I got only one PNG. After selecting also it is not exporting each layer as png. I tried using below example.

Get Layer Groups from C++ plugin

If yes, then just get the XMP for each layer and make a side car file

I am getting each layer meta as per this thread. What do you mean by "make a side car file " ?

tell me how you are saving the PNG. Is the user doing that?

There is no manual exporter event at user's end !!

I am using layer traversal using layerIndex as discussed above. Therefore, only requirement is to export each layer as a PNG using an automation plugin.

That is why I collected layer info such as name, ID, meta data, ECT.

Actually, all needed things to be exported the current layer as PNG, is a still black box for me.

I saw in another example (outbound) is used layer width, height, channelDes info to be export to PNG.

How can I export Text Layer as PNG?

this is working..But as per my requirements, converting the same channel Info and exporter record info in an automation plugin seems challenging !!

Thanks

Translate
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
Feb 27, 2015 Feb 27, 2015

Maybe we should mark this thread as answered and start a new one with the topic of "I am trying to export each layers to PNG with layer meta dat"

You could look at the Layers to Files script. It makes each layer visible and then saves as PNG. C:\Program Files\Adobe\Adobe Photoshop CC 2014\Presets\Scripts\Export Layers To Files.jsx


It sounds like something similar to what you want. You could move the per layer metadata to the document metadata before saving each layer.

Translate
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
Explorer ,
Feb 28, 2015 Feb 28, 2015

sure !

See this in a separate discussion.

Translate
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
New Here ,
May 17, 2018 May 17, 2018

Hi,

I know it has been a while since you posted this but I'm trying to do exactly the same thing using the Getter plug-in, and I can't find a way to do this in CC 2018.. maybe you could help me.

I use the following code:

Handle h1 = NULL;

DescriptorTypeID runtimeKeyID2;

string returnVal;

runtimeKeyID2 = PIUActionControl::GetStringID("XMPMetadataAsUTF8"); // return 0x000010af

error = PIUGetInfoByIndex(layCounter, classLayer, runtimeKeyID2, &h1, NULL); // error = 0x5061726d (Parm)..

I dig deeper in the PIUGetInfoByIndex function, and found that the key "XMPMetadataAsUTF8" is not found in the ActionDescriptor..

I have the feeling that the runtimekey found for a string whose length is 4 char (like 'Lyr ', or 'NmbL') always work (kind of obvious as the 4 ascii char fit in a int32), but the one found for longer string won't.. but as stated in the PIStringTerminology it should..

Am I missing something ?

Thanks

Translate
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
New Here ,
Nov 06, 2018 Nov 06, 2018
LATEST

you have to provide some reasonable value for the last parameter of PIUGetInfoByIndex().

it can not be nullptr or zero valued variable.

otherwise this function will return 0x5061726d

Translate
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