Copy link to clipboard
Copied
I'm writing a replacement JPEG export panel for Bridge, and currently working on copying metadata. I have it working for any source format with embedded metadata using the testing code stub below. But this doesn't work with RAW files, presumably due to using XMP sidecars. Note that the "SnpInspectMetadata.jsx" sample included in the Bridge CC SDK also fails, in fact it throws an exception when trying to run new XMPFile().
So how do I get metadata from RAW files? Do I have to test for sidecars? Looking at one with a text editor, there are lots of extra fields.
My script works otherwise to export JPEG files, and copies metadata from image formats other than RAW.
this.run = JPEGExport();
function JPEGExport(){
var thumbs = app.document.getSelection("psd, jpg, png, tif, gif, CR2, nef");
if(thumbs.length != 0){
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
for(var i = 0;i < thumbs.length;i++){
if(thumbs.spec instanceof File){
var thumb = thumbs;
var selectedFile = thumb.spec;
var oldXmpFile = new XMPFile(selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_READ);
var oldXmp = oldXmpFile.getXMP();
var bm = new BitmapData(thumbs.spec);
if(bm instanceof BitmapData){
var fullName = thumbs.name;
var finalDotPosition = fullName.lastIndexOf(".");
if(finalDotPosition > -1){
repname = fullName.substr(0 , finalDotPosition);
}
}
var exportFilePath = thumbs.parent.spec + "/" + repname +"_new.jpg";
var exfile = new File(exportFilePath);
bm.exportTo(exfile);
var newthumb = exfile.spec;
var myXmpFile = new XMPFile(exfile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
if (myXmpFile.canPutXMP(oldXmp)){
myXmpFile.putXMP(oldXmp);
myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
}
}
}
}
}
Ah nevermind. Had to use the Thumbnail object, not thumbnail.spec
var xmp = new XMPMeta(thumb.synchronousMetadata.serialize());
Copy link to clipboard
Copied
var xmp = new XMPMeta(selectedFile.synchronousMetadata.serialize());
Copy link to clipboard
Copied
Doesn't work. It throws an error of "undefined is not an object" with both RAW and JPEG source files. And the Object Model Viewer says that Thumbnail.synchronousMetadata returns undefined if the node doesn't support embedded metadata.
Copy link to clipboard
Copied
Ah nevermind. Had to use the Thumbnail object, not thumbnail.spec
var xmp = new XMPMeta(thumb.synchronousMetadata.serialize());
Copy link to clipboard
Copied
While on the topic, I thought that this may be helpful (or at least interesting):
Bridge Export Panel Sample Code | Photoshop Family Customer Community
Copy link to clipboard
Copied
Yes I posted that script. I’m maybe halfway done writing a new JPEG export panel.