Hey all (Happy New Year)
I actually see some people here who helped me with this originally so many years ago (hi 'x'). Any way, I'm using this .js file to annotate aerial imagery prior to printing, and I know just enough about scripting to make changes to the basic layout as needs arise - until now. A new rather anal retentive mgr doesn't like substitutions I've made for a few 'illegal' characters that windows doesn't allow in file names. For example, the file name used for the annotation is:
001 0003 1in = 660ft CFL 154_074 01-01014 503-013.tif
But Mr. mgr doesn't like the in, the ft and the use of the _ instead of a period (.) so what I need is a modification that goes something like (and note I DO NOT CODE, so stop laughing) -
"look for in and replace with ", look for ft and replace with ' and look for _ and replace with , " so the final annotation written to the image is:
001 0003 1" = 660' CFL 154.074 01-01014 503-013.tif
My current .js is below, I'd really appreciate any assistance. Thanks! TLL
------------
// CREATE NEW CANVAS W/SPACE ON TOP
var deltaW = 0; // add 'N' pixels to the width
var deltaH = 150; // add 'N' pixels to the height
var anchor = AnchorPosition.BOTTOMCENTER; // anchor point for canvas resize
// SET FONT TYPE AND SIZE - use GetFontName.js to get exact name
var fontName = "ArialMT";
var fontSize = 18;
// Check if a document is open
if ( documents.length > 0 ) {
var originalRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
try {
var docRef = activeDocument;
docRef.resizeCanvas(docRef.width + deltaW, docRef.height + deltaH, anchor);
// Create a text layer at the front
var myLayerRef = docRef.artLayers.add();
myLayerRef.kind = LayerKind.TEXT;
myLayerRef.name = "Filename";
var myTextRef = myLayerRef.textItem;
// ADD FILE EXTENSION, change the n to y below
var ShowExtension = "n";
myTextRef.size = fontSize;
myTextRef.font = fontName;
// SET TEXT COLOR in RGB values
var newColor = new SolidColor();
newColor.rgb.red = 0;
newColor.rgb.green = 0;
newColor.rgb.blue = 0;
myTextRef.color = newColor;
// SET POSITION OF TEXT - PIXELS from left first, then from top.
myTextRef.position = new Array( 30,110);
// Set the Blend Mode of the Text Layer. The name must be in CAPITALS
// ie change NORMAL to DIFFERENCE.
myLayerRef.blendMode = BlendMode.NORMAL;
// select opacity in percentage
myLayerRef.opacity = 100;
// The following code strips the extension and writes tha text layer.
// fname = file name only
//use extension if set
if ( ShowExtension == "y" ) {
fname = docRef.name;
} else {
di=(docRef.name).indexOf(".");
fname = (docRef.name).substr(0, di);
}
myTextRef.contents = fname;
// docRef.flatten("n");
} catch( e ) {
// An error occurred. Restore ruler units, then propagate the error back
// to the user
preferences.rulerUnits = originalRulerUnits;
throw e;
}
// Everything went Ok. Restore ruler units
preferences.rulerUnits = originalRulerUnits;
} else {
alert( "You must have a document open to add the filename!" );
}