Just had a thought, the above script should work on all but raw files, if you were using raw files this might work? It adds the Serial number to the xmp file, creating one if it dose not exist.
#target bridge;
if( BridgeTalk.appName == "bridge" ) {
addCameraNumberII = MenuElement.create("command", "Add Camera NumberII", "at the end of tools");
}
addCameraNumberII.onSelect = function () {
var win = new Window('dialog','Add Camera Number');
g = win.graphics;
var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [0.99, 0.99, 0.99, 1]);
g.backgroundColor = myBrush;
win.alignChildren="row";
win.g10 = win.add('group');
win.g10.orientation = "row";
win.title = win.g10.add('statictext',undefined,"Add Camera Number");
win.title.alignment="bottom";
var g = win.title.graphics;
g.font = ScriptUI.newFont("Georgia","BOLDITALIC",26);
win.p1= win.add("panel", undefined, undefined, {borderStyle:"black"});
win.p1.alignChildren="fill";
win.g3 =win.p1.add('group');
win.g3.orientation = "row";
win.g3.alignment="left";
win.g3.st1 = win.g3.add('statictext',undefined,'Enter Camera Number');
win.g3.et1 = win.g3.add('edittext',undefined,'123456789');
win.g3.et1.active=true;
win.g3.et1.preferredSize=[120,20];
win.g3.et1.onChanging = function() {
if (this.text.match(/[^\-\.\d]/)) {
this.text = this.text.replace(/[^\-\.\d]/g, '');
}
};
win.g150 =win.p1.add('group');
win.g150.spacing=10;
win.g150.orientation = 'row';
win.g150.alignment="top";
win.g150.bu1 = win.g150.add('button',undefined,"Process");
win.g150.bu1.preferredSize=[120,30];
win.g150.bu2 = win.g150.add('button',undefined,"Cancel");
win.g150.bu2.preferredSize=[120,30];
win.g150.bu1.onClick = function(){
if(win.g3.et1.text == ''){
alert("A Camera Number Needs To Be Entered!");
return;
}
var sels = app.document.selections;
if(sels.length < 1){
alert("No documents have been selected!");
win.close(2);
}
var cameraserial =Number(win.g3.et1.text);
win.close(0);
for(var a in sels){
if(sels.type != "file") continue;
setCameraNo(sels, cameraserial );
}
}
win.show();
function setCameraNo( thumb, SerialNumber ){
if(SerialNumber == undefined) return;
var file = new File(thumb.spec.toString().replace(/...$/,"xmp"));
try{
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
if(file.exists){
file.open('r');
file.encoding = "UTF8";
file.lineFeed = "unix";
file.open("r", "TEXT", "????");
var xmpStr = file.read();
file.close();
}else{
var xmpStr='';
}
var xmp = new XMPMeta( xmpStr );
xmp.setProperty(XMPConst.NS_EXIF_AUX, "SerialNumber",SerialNumber);
file.open('w');
file.encoding = "UTF8";
file.lineFeed = "unix";
file.write( xmp.serialize() );
file.close();
}catch(e){alert(e+"-"+e.line);}
};
};
... View more