label script
Learn / Forums / InDesign Add-ons (Scripts, Scripting, and Plug-ins) / label script
- This topic has 11 replies, 5 voices, and was last updated 13 years ago by Jean-Claude Tremblay.
-
AuthorPosts
-
-
May 19, 2010 at 4:02 am #55751maggsMember
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.
-
May 20, 2010 at 2:30 pm #55788Theunis De JongMember
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;
}
-
June 3, 2010 at 8:03 am #55903maggsMember
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?
-
June 6, 2010 at 4:19 am #55946Theunis De JongMember
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.
-
March 12, 2011 at 7:33 pm #58970Bob RubeyMember
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
-
March 13, 2011 at 3:58 am #58971Theunis De JongMember
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.
-
March 14, 2011 at 12:09 pm #58978Bob RubeyMember
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
-
March 14, 2011 at 3:31 pm #58980Theunis De JongMember
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.
-
March 15, 2011 at 6:06 am #58983Bob RubeyMember
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
-
April 16, 2011 at 5:35 am #59288Jean-Claude TremblayParticipant
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
-
April 16, 2011 at 9:05 am #59289Kasyan ServetskyMember
//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;
} -
April 18, 2011 at 12:14 pm #59303Jean-Claude TremblayParticipant
Kasyan, thank you…
Work great! Now I will be able to learn what you did comparing with Jongware original.
-
-
AuthorPosts
- You must be logged in to reply to this topic.