Copying metadata from XMP sidecar files?

General Discussion of Scripting for Adobe Bridge

Moderators: Tom, Kukurykus

lumigraphics
Posts: 3
Joined: Tue Oct 31, 2017 7:53 pm

Copying metadata from XMP sidecar files?

Post by lumigraphics »

I'm writing a replacement for the JPEG Export panel and currently getting metadata copying setup. I have it working in the testing snippet below for image formats having embedded metadata, but it doesn't copy metadata from RAW files (presumably due to the sidecar file.) Trying Adobe's Bridge CC SDK samples, SnpInspectMetadata.jsx actually throws an exception on

Code: Select all

new XMPFile()
with RAW files.

Do I need to test for sidecar files and parse those? I can't find documentation or anything online about this specific problem.

Code: Select all

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[i].spec instanceof File){
var thumb = thumbs[i];
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[i].spec);
if(bm instanceof BitmapData){
var fullName = thumbs[i].name;
var finalDotPosition = fullName.lastIndexOf(".");
if(finalDotPosition > -1){
repname = fullName.substr(0 , finalDotPosition);
}
}
var exportFilePath = thumbs[i].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);
}
}
}
}
}
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Copying metadata from XMP sidecar files?

Post by Kukurykus »

Nimakhore
Posts: 1
Joined: Wed Sep 30, 2020 11:48 am

Re: Copying metadata from XMP sidecar files?

Post by Nimakhore »

Great!