Reply To: label script

#55788

Try this script. It will create a NON-PRINTING layer “ImageScales” — just to remind you have to manually switch between printing and non-printing! — as well as a paragraph style “ImageScales”. If the layer and/or style already exist, you can adjust them to what you want; it won't change them any further.

Then it goes over all images and inserts their scale.

Make a version with the ImageScales layer set to printable for your clients, and one with the layer non-printable for production (don't do it the other way around, or you'll make your clients less happy, rather than more).

Written on a CS4 machine but it ought to work, methinks.

(Edit: changed 'horizontalScale' to 'absoluteHorizontalScale, and the same for vertical.) (!)

//DESCRIPTION:Label Images with their Scale

// Jongware, 20-May-2010

// No Guarantees, Etc.

try {

app.activeDocument.layers.add({name:”ImageScales”, layerColor: [255,192,0], printable: false});

} catch (_) { }

try {

app.activeDocument.paragraphStyles.add({name:”ImageScales”, justification: Justification.CENTER_ALIGN});

} catch (_) { }

reportLayer = app.activeDocument.layers.item(“ImageScales”);

reportStyle = app.activeDocument.paragraphStyles.item(“ImageScales”);

imageList = app.activeDocument.allGraphics;

for (im=0; im<imageList.length; im++)

{

try { showScaleFor (imageList[im]); } catch (_) {}

}

function showScaleFor (anImage)

{

var gb,fr,pg;

gb = anImage.parent.geometricBounds;

pg = anImage.parent;

while (1)

{

if (pg instanceof InsertionPoint)

pg = pg.parentTextframes[0];

if (pg instanceof Document || pg instanceof Spread || pg instanceof Page)

break;

pg = pg.parent;

}

fr = pg.textFrames.add(reportLayer, {geometricBounds: gb, textFramePreferences: {verticalJustification: VerticalJustification.CENTER_ALIGN}});

fr.insertionPoints[0].appliedParagraphStyle = reportStyle;

if (anImage.absoluteHorizontalScale == anImage.absoluteVerticalScale)

fr.contents = twoDec(anImage.absoluteHorizontalScale)+”%”;

else

fr.contents = twoDec(anImage.absoluteHorizontalScale) + “%/” + twoDec(anImage.absoluteVerticalScale) + “%”;

}

function twoDec(x)

{

return Math.round(x*100)/100;

}

This article was last modified on May 20, 2010

Comments (0)

Loading comments...