Reply To: Script to label selection with height and width

#61445

… Actually, one line would be easier – I can just draw the rules to match and leave the text either above or below the graphic (wherever is easiest for the script to place it).

Actually, all of the above is possible using regular scripting :) No extra plug-in needed, just a bit of know-how.

Copy the Javascript below and paste it into a plain text file — see David's handy “How to Install a Script in InDesign That You Found in a Forum or Blog Post” article for the exact procedure. Rest assured, there is no malicious code hidden in here :D That I know of :(

It has the following features:

1. Run on a single, plain selection — one with the black arrow. It will add labels and lines for width and height. The current selected object will stay selected.

2. It puts the labels and lines on a layer called “ImageLabel”, which is set to non-printing on creation. If the layer already exists, it doesn't change the existing settings. (If you always want to have it print: to remove the default non-printing setting, change 'printable: false' to 'printable: true' in line 17.) This layer is colored ghastly green by default.

3. The lines and text use a custom swatch called “ImageLabel”. It's an RGB color (because presumably it's just for viewing), but of course I can make it a real CMYK color as well. As per above, you can also run the script once and then adjust the settings — the script won't change it if it already exists.

4. The text has a paragraph style called “ImageLabel” by default. It's set to Helvetica at 12 pt, but you can change these values in the script (for new defaults) in line 30, or simply change the “ImageSize” paragraph style. Same as above.

5. The labels appear centered in their text frames, so the left one has to be wide enough for three decimals. The text frames are set to ignore all text wrappings to prevent unexpected overset text.

6. You didn't ask for this, but it groups the text frames and lines together for each image. Might come in handy; but if you find yourself ungrouping everything every time because stuff is just not In The Right Place (and that's always a different place (*)), delete the entire line near the bottom that says “app.activeDocument.groups.add …”

(*) I mean, if you find that everything is always off by exactly 0.1″, it's easier to change the script. If the value is always different, remove that grouping line.

7. It comes with an Undo! Undoing will, uh, undo everything the script did. If you ran it twice, a first Undo will remove the last labels it added. The second time it will also remove the layer, paragraph style, and swatch (but only if it created them in the first place).

… That's about it. I tested with CS4 but I'm totally fairly reasonable sure it'll work on CS5 and later as well. If not, yell and I'll think about what needs tinkering with.

removed from post — sorry, it was too complicated for the forum

Alas … The script contained too much special codes for this forum to be copied & used as-is, so I put it up at my website: https://www.jongware.com/binaries/labelImageSize.zip

Download, unpack (if your browser doesn't do so automatically), and put into your User Scripts folder. Then, enjoy!

This article was last modified on September 13, 2016

Comments (0)

Loading comments...