You must be logged in to post Login

Search Forums:


 






label script

UserPost

4:02 am
May 19, 2010


maggs

Community Member

posts 7

I would like to know if there is a script or plugin for InDesign CS3 that can create labels for placed images that shows at what percentage the image was placed. We have clients that would like to see this information.

2:30 pm
May 20, 2010


Jongware

Member

posts 764

Post edited 9:40 pm – May 20, 2010 by Jongware


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;

}

8:03 am
June 3, 2010


maggs

Community Member

posts 7

First, Thanks to Jongware for the label script. One other thing I neglected to mention is that most of our images are anchored or inline. The script seems to have problems with these images. Is there any solution?

4:19 am
June 6, 2010


Jongware

Member

posts 764

Ah, the wonders of error suppression … I thought: if an error occurs, you might want to have the script ignore that one image and continue automatically. Unfortunately, I made a typo and checked the wrong 'type' somewhere — with the result that both of these image types are skipped without giving me an error message to tell me the code did not work!

Change these two lines

    if (pg instanceof InsertionPoint)

      pg = pg.parentTextframes[0];

to this

    if (pg instanceof Character)

      pg = pg.parentTextFrames[0];


to make the script work as planned.

7:33 pm
March 12, 2011


Bob Rubey

Member

posts 30

Jongware:

Your Image Scales script has aided me in my job as a prepress tech, and I thank you for that. Is there a way, however, to make the text boxes that the script creates ignore text wraps? Could such a command string also be added to the Label Graphics script that shipped with CS3 and CS4 and still works with CS5.

I use the scripts to create visuals with image info for our customer service and image enhancement departments, and manually modifying text boxes to ignore text wraps when they occur can get tedious.

Bob

3:58 am
March 13, 2011


Jongware

Member

posts 764

Bob, change this line

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

(12th from the bottom up) to this

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

– I didn't try, but I'm pretty sure that'd do the trick.

I've never used LabelGraphics so I can't recommend something off the top of me head for that.

12:09 pm
March 14, 2011


Bob Rubey

Member

posts 30

Jongware:

That did the job, thank you.

I copied a couple of lines from near the end of the Label Graphics script (the indents do not show in the post). I only have a cursory understanding of scripts, but my sense is that the ignoreWrap command should be inserted somewhere in these lines, or should I be looking for something else?


myTextFrame.textFramePreferences.firstBaselineOffset = FirstBaseline.leadingOffset; 

myTextFrame.parentStory.texts.item(0).appliedParagraphStyle = myLabelStyle;


I tried copying in the last 15 lines or so, but indents and line breaks were removed in the post.


Bob


3:31 pm
March 14, 2011


Jongware

Member

posts 764

Post edited 3:32 pm – March 14, 2011 by Jongware


Hey, but you are very close!

All it needs is an "ignoreWrap" command, and that's to be applied to a textFramePreferences, which in turn is a part of a text frame proper. So it's "good" to locate where some text frame gets created, and really "best" when you can find a line that does something with the text frame preferences (*). See the first line you copied!

Add this right after that line:


myTextFrame.textFramePreferences.ignoreWrap = true;

and you should be alright.

[*] Why do text frames have separate text frame preferences? Nobody knows — it might be because you can, uh, "store" the text frame preferences into an object style. My personal 2nd best guess is the Adobe engineers didn't like the idea to have more than a hundred properties per each text frame.

6:06 am
March 15, 2011


Bob Rubey

Member

posts 30

Jongware:

That did the job. I will still need to check for overset text when the picture frames are narrow and the file names are long, but in that case I need to watch for side-by-side labels too, so that's probably for the best.  The changes to the two scripts will eliminate the other manual work.

Thanks again for your time and for the  mini-tutorial.

Bob

5:35 am
April 16, 2011


jctremblay

Community Member

posts 13

Post edited 9:03 am – April 16, 2011 by jctremblay


Hi Jongware,

What should I do to make this script write Effective PPI instead of scale. I know that effective PPI is a two arrays values. I try a few things but I'm giving up after an hour of trying. Any help appreciated.


Thanks

Jean-Claude

9:05 am
April 16, 2011


Kasyan Servetsky

Kiev, Ukraine

Member

posts 65

//DESCRIPTION:Label Images with their Eff ppi
try {
app.activeDocument.layers.add({name:"ImageEffPpi", layerColor: [255,192,0], printable: false});
} catch (_) { }

try {
app.activeDocument.paragraphStyles.add({name:"ImageEffPpi", justification: Justification.CENTER_ALIGN});
} catch (_) { }

reportLayer = app.activeDocument.layers.item("ImageEffPpi");
reportStyle = app.activeDocument.paragraphStyles.item("ImageEffPpi");
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 Character)
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, ignoreWrap:true}});
fr.insertionPoints[0].appliedParagraphStyle = reportStyle;
if (anImage.effectivePpi[0] == anImage.effectivePpi[1])
fr.contents = twoDec(anImage.effectivePpi[0])+" ppi";
else
fr.contents = twoDec(anImage.effectivePpi[0]) + "/" + twoDec(anImage.effectivePpi[1]) + " ppi";
}

function twoDec(x)
{
return Math.round(x*100)/100;
}

12:14 pm
April 18, 2011


jctremblay

Community Member

posts 13

Kasyan, thank you… 

Work great! Now I will be able to learn what you did comparing with Jongware original.