Skip to main content
dev_willis
Inspiring
October 19, 2018
Answered

Why is xmpMetadata.rawData always empty?

  • October 19, 2018
  • 1 reply
  • 1970 views

The only way I've been able to get at the metadata on a layer is like this:

function dump(obj) {
	var out = '';
	for (var i in obj) {
		out += i + ": " + obj[i] + "\n";
	}
	return out;
};

dump(doc.artLayers[i].xmpMetaData);

 

This returns a string with the properties parent, rawData and typename and their associated values including all of the layer metadata. So why does doc.artLayers.xmpMetaData.rawData not contain anything? This fails every time:

try{
	xmp = doc.artLayers[i].xmpMetadata.rawData;  
	xmpObject = new XMPMeta(xmp);  
}catch(e){  
	alert("failed to create xml object");
}

 

What's going on here? Why do I have go through the awkward parsing above to get at the metadata?

This topic has been closed for replies.
Correct answer r-bin

The EXIF data from the files I loaded into layers is what's there. And it is there--I can get at it by enumerating the xmpMetadata object as I described above. But it would be easier if I could just load .rawData straight into a DOMParser object or something. Which I feel like should be possible, is probably how it's supposed to work and is likely a bug that it doesn't.


I very rarely use XMP.
But everything works for some reason.

if (!ExternalObject.AdobeXMPScript) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript'); 

doc = activeDocument;

doc.artLayers[0].xmpMetadata.rawData = "" //doc.xmpMetadata.rawData;   

try{ 

    xmp = doc.artLayers[0].xmpMetadata.rawData;   

    xmpObject = new XMPMeta(xmp);   

    alert("OK!");

} catch(e){   

    alert(e);

    alert("failed to create xml object"); 

What am I doing wrong?

1 reply

Legend
October 19, 2018

Maybe I do not understand something in your question

if (!activeDocument.activeLayer.isBackgroundLayer)

    {

    activeDocument.activeLayer.xmpMetadata.rawData = "Hello world!";

    alert(activeDocument.activeLayer.xmpMetadata.rawData)

    activeDocument.activeLayer.xmpMetadata.rawData = activeDocument.xmpMetadata.rawData;

    alert(activeDocument.activeLayer.xmpMetadata.rawData)

    }

else

    alert("Background has no xmpMetadata")

dev_willis
Inspiring
October 20, 2018

Yes, I think so. I want to read the existing data from xmpMetadata.rawData. Not write to it and then read back what I wrote.

Legend
October 20, 2018

What data do you expect to read? For example, when you create a new layer, what data do you expect to read from rawData?
I have always believed that this is a place to store some service information defined by the user himself for this layer. Moreover, the data format in rawData does not have to be in xmp format. For example, there you can save completely another graphic file, or an array or data structure.