/////////////////////////////////////////////////////////////////////////////// // ShowFocusPoint // Malcolm Hoar 2010 // Script to show the focus point // Supports Nikon/Canon EXIF // Requires Exiftool // Edit the lines below to set exiftoolpath and temp plus a valid font /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// // Global variables /////////////////////////////////////////////////////////////////////////////// var exiftoolpath = "C:/Wintools/exiftool.exe"; var tempdir = "C:/TEMP/"; var batfile = "dump.bat"; var datfile = "dump.txt"; var textFont = "Arial"; var textFontSize = 60; var focusPoint = ""; var displayText = "[ ]"; /////////////////////////////////////////////////////////////////////////////// // Function: imageView /////////////////////////////////////////////////////////////////////////////// function imageView (view) { var id73 = charIDToTypeID( "slct" ); var desc17 = new ActionDescriptor(); var id74 = charIDToTypeID( "null" ); var ref13 = new ActionReference(); var id75 = charIDToTypeID( "Mn " ); var id76 = charIDToTypeID( "MnIt" ); if (view.length < 5) var id77 = charIDToTypeID( view ); else var id77 = stringIDToTypeID( view ); ref13.putEnumerated( id75, id76, id77 ); desc17.putReference( id74, ref13 ); executeAction( id73, desc17, DialogModes.NO ); } /////////////////////////////////////////////////////////////////////////////// // function createDialog() /////////////////////////////////////////////////////////////////////////////// function createDialog() { var dlg = new Window('dialog', "Custom Frame"); dlg.alignChildren = "fill"; dlg.orientation = "column"; // Panel dlg.titlePnl = dlg.add('panel', undefined, "Confirm Orientation"); var tp = dlg.titlePnl; tp.orientation = "column"; tp.alignment = "fill"; tp.alignChildren = "left"; tp.txt = tp.add('statictext', undefined, "Left of camera frame is displayed at image:") tp.top = tp.add('radiobutton', undefined, "Top"); tp.bot = tp.add('radiobutton', undefined, "Bottom: "); tp.lef = tp.add('radiobutton', undefined, "Left: "); tp.rit = tp.add('radiobutton', undefined, "Right:"); // Add "OK" and "Cancel" buttons dlg.buttons = dlg.add('group'); var b = dlg.buttons; b.orientation = "row"; b.alignment = "right"; b.okBtn = b.add('button', undefined, 'OK', {name:'ok'}); dlg.center(); return dlg; } // End createDialog /////////////////////////////////////////////////////////////////////////////// // function initializeDialog(TheDialog) /////////////////////////////////////////////////////////////////////////////// function initializeDialog(TheDialog, rot) { if (rot == 0 || rot == 1 || rot == 2) { TheDialog.titlePnl.lef.value = true; } if (rot == 3 || rot == 4) { TheDialog.titlePnl.rit.value = true; } if (rot == 5 || rot == 8) { TheDialog.titlePnl.bot.value = true; } if (rot == 6 || rot == 7) { TheDialog.titlePnl.top.value = true; } } // End initializeDialog /////////////////////////////////////////////////////////////////////////////// // Main Script /////////////////////////////////////////////////////////////////////////////// function main() { var AD = activeDocument var originalUnit = app.preferences.rulerUnits; app.preferences.rulerUnits = Units.PIXELS; var COL = new SolidColor(); COL.rgb.red = 255; COL.rgb.green = 0; COL.rgb.blue = 0; var imgname = AD.fullName.path; imgname = decodeURI(imgname); // Windows specific pathname fudge imgname = imgname.charAt(1) + ":" + imgname.substr(2,imgname.length) + "/" + AD.name; dat = new File(tempdir + datfile); dat.remove(); // Invoke Exiftool to extract Orientation and AFPoint var bat = new File(tempdir + batfile); bat.open('w'); bat.writeln(exiftoolpath + ' -n -Make -Orientation -AFPoint "' + imgname + '" > ' + tempdir + datfile); bat.writeln('exit'); bat.close(); bat.execute(); while (! dat.open("r")) { $.sleep(100); } dat.close(); $.sleep (500); dat.open ("r"); var mak = dat.readln(); var rot = dat.readln(); var afp = dat.readln(); dat.close(); // Parse the data mak = mak.substr(mak.indexOf(":")+2,5); // Make of camera rot = rot.substr(rot.indexOf(":")+2,rot.length); // rotation 1-8 afp = afp.substr(afp.indexOf(":")+2,afp.length); // AF point 0-10 mak = mak.toLowerCase(); // alert ("mak=" + mak + " rot=" + rot + " afp=" + afp); // If the camera is not Nikon or Canon, we can't do anything else if (mak != "canon" && mak != "nikon") return; // If portrait orientation display and process the user dialog // to confirm the orientation var x = AD.width.value; var y = AD.height.value; if (y > x) { var TheDialog = createDialog(); initializeDialog(TheDialog, rot); TheDialog.show(); if (TheDialog.titlePnl.lef.value) rot = 1; if (TheDialog.titlePnl.rit.value) rot = 3; if (TheDialog.titlePnl.top.value) rot = 8; if (TheDialog.titlePnl.bot.value) rot = 6; } // cent, top, bot, left, rt, up-lt, up-rt,lo-lt,lo-rt,far-lt,far-rt nikonx = new Array(0.50, 0.50, 0.50, 0.30, 0.70, 0.30, 0.70, 0.30, 0.70, 0.15, 0.85) nikony = new Array(0.50, 0.25, 0.75, 0.50, 0.50, 0.25, 0.25, 0.75, 0.75, 0.50, 0.50) // none rt cent c+r Lt lt+rt lt+c All canon1x = new Array(0.00, 0.70, 0.50, 0.50, 0.30, 0.30, 0.30, 0.30) canon1y = new Array(0.00, 0.50, 0.50, 0.50, 0.50, 0.50, 0.50, 0.50) canon2x = new Array(0.00, 0.00, 0.00, 0.70, 0.00, 0.70, 0.50, 0.50) canon2y = new Array(0.00, 0.00, 0.00, 0.50, 0.00, 0.50, 0.50, 0.50) canon3x = new Array(0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.70) canon3y = new Array(0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.50) nx = new Array(0,0,0); ny = new Array(0,0,0); if (mak == "nikon") { if (afp < 0) afp = 0; if (afp > 10) afp = 10; nx[0] = nikonx[afp]; ny[0] = nikony[afp]; nx[1] = 0; ny[1] = 0; nx[2] = 0; ny[2] = 0; } if (mak == "canon") { afp = afp - 12288; if (afp < 0) afp = 0; if (afp > 7) afp = 7; nx[0] = canon1x[afp]; ny[0] = canon1y[afp]; nx[1] = canon2x[afp]; ny[1] = canon2y[afp]; nx[2] = canon3x[afp]; ny[2] = canon3y[afp]; } // Adjust per the orientation flag dx = new Array(0,0,0); dy = new Array(0,0,0); for (i = 0; i < 3; i++) { dx[i] = x * nx[i]; dy[i] = y * ny[i]; if (rot == 3 || rot == 4) { dx[i] = x * (1 - nx[i]); dy[i] = y * (1 - ny[i]); } if (rot == 5 || rot == 8) { dx[i] = x * (1 - ny[i]); dy[i] = y * nx[i]; } if (rot == 6 || rot == 7) { dx[i] = x * ny[i]; dy[i] = y * (1 - nx[i]); } // Display text if (nx[i] > 0) { var focusLayer = AD.artLayers.add(); focusLayer.kind = LayerKind.TEXT; var displ = focusLayer.textItem; displ.position = [dx[i], dy[i]]; displ.justification = Justification.CENTER; displ.contents = displayText; displ.font = textFont; displ.size = textFontSize; displ.color = COL; displ.fauxBold = true; } } // View Fit On Page imageView('FtOn'); // Restore unit prefs app.preferences.rulerUnits = originalUnit; } main();