Script to label selection with height and width
Learn / Forums / InDesign Add-ons (Scripts, Scripting, and Plug-ins) / Script to label selection with height and width
- This topic has 20 replies, 2 voices, and was last updated 11 months, 2 weeks ago by giuliano bocchi.
-
AuthorPosts
-
-
January 13, 2012 at 8:50 am #61436suzerpMember
I'm a long time pre-presser, but just *gasp* discovered scripts. Being self taught sometimes results in not realizing what's available.
I'm guessing this already exists, but I've searched and can't find it easily –
I'm looking for an InDesign (5.0) script that would label a selected object with it's height and width. I've seen a script that gives the percentage, which is close, but not quite what I need. In a perfect world I'd get two labels, one for the width and one for the height, but I'm not picky – right now I'm doing this by hand so any automation would speed my life along.
Any help is appreciated!
-
January 13, 2012 at 9:14 am #61439Theunis De JongMember
Can you make a mock-up image of what it should look like?
The percentage thingy you found may well have been mine; it creates a text frame the size of the original image on a new layer and writes the size into this, so you can easily switch off all labels at once. It's a piece a cake to have it write out width and height, in any measurement unit you like and with as much precision decimals as you can care about.
-
January 13, 2012 at 9:37 am #61440David BlatnerKeymaster
One idea is to use the Frame Reporter plug-in from rorohiko:
https://www.rorohiko.com/wordpress/indesign-downloads/framereporter/
-
January 13, 2012 at 10:06 am #61441suzerpMember
Hi Jongware – yes it was your script that gave me the idea that this would either already exist or be possible ( https://creativepro.com/forum/indesign-add-ons-scripts-scripting-and-plug-ins/label-script )
Attachment one.jpg is what I'm doing by hand, now.
Attachment two.jpg shows what I'm guessing would be possible – either one line showing height x width (3 decimals, always in inches is what I need to show) or maybe the two text boxes – one showing height and one showing width so I can scoot them to their locations. 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).
-
January 13, 2012 at 4:14 pm #61445Theunis De JongMember
… 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 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 forumAlas … 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!
-
January 16, 2012 at 8:26 am #61457suzerpMember
Oh my!
That is totally freakin' awesome. And the way you documented it made me kinda sorta understand how you did it.
We do need the layer to always be printable (but it doesn't matter if it's RGB or CMYK – it just needs to print on the hard copy production proofs that go out to production, then we delete the layer when we set up for plates/film/whatever the thing becomes)., so I changed that. Everything else is just amazing – it runs just fine in 5.0.
Not sure what I can offer in return, but you've cut my workload a heap!
-
January 17, 2012 at 10:35 am #61474suzerpMember
Ok, so now there's a little trouble. This script works great for me. I made only one mod – I changed “false” to “true” regarding the print state of the new layer.
But when I shared it with a co-worker, his gives us the attached error. He can run other scripts, but not this one. Any idea where to start?
-
January 17, 2012 at 11:54 am #61475Theunis De JongMember
Ouch.
Can you check if this copy is complete? The very first thing the script does is checking if the layer, paragraph style, and swatch “ImageLabel” exist — and if any of them don't, it creates them! So theoretically, this error — what it says is basically 'I don't have access to this style called “ImageLabel”' — ought not have happened.
Can you verify on a simple rectangle in a blank new document if the layer, paragraph style, and swatch are created correctly?
-
January 17, 2012 at 1:12 pm #61477suzerpMember
Unfortunately, we already thought about that, and he gets that same error on a new document that only has a blank rectangle.
But – my other co-worker (there are three of us) has no trouble with the script.
We are all running CS5.0. We tried to poke about for differences between the 3 machines, but we're all running the same system. Those two are running Version 7.0 of CS5, I'm running 7.04 (you'd think I'd be the one with trouble since I'm odd man out).
-
January 17, 2012 at 2:57 pm #61478Theunis De JongMember
Can you check if the script created any of the three items before crashing?
-
January 17, 2012 at 3:09 pm #61479suzerpMember
It doesn't create anything before crashing.
But here's something you didn't ask but we tried anyway – if we set up a Paragraph Style called ImageLabel before we run it, it works. We didn't make it match the specs of ImageLabel in the script – we just renamed one of our existing styles, so the text overset the box, but it didn't crash and it drew the rules.
-
January 18, 2012 at 4:01 am #61480Colin FlashmanParticipant
@Jongware
for once I actually know the answer to a scripting question!!!!
had the same error on my mac @ work (10.5.8 running cs5.5). Go to line 31 of the script and change the
appliedFont:”HelveticatRegular”
to a font which is definitely on the other user's system.
on my mac, there was no Helvetica Regular, instead just used ArialtRegular.
after that, the script worked.
-
January 19, 2012 at 8:21 am #61486suzerpMember
collywolly is right!
I changed the font to Arial and it works like a charm. We have something like 10 thousand Helveticas between the 3 of us, but only 1 Arial. :)
Thank you both so much!
-
January 19, 2012 at 9:38 am #61488Theunis De JongMember
Oof — saved by collywolly!
(I really had no idea what to look for. It's weird that creating the paragraph style works but trying to use it results in an error …)
-
January 22, 2012 at 9:03 pm #61511William PoseyParticipant
Errors out when using with IDCS3. Shame I was looking for this exact script two weeks ago… Sounds like maybe it has some CS4+ code in the JS, maybe someoen can offer some suggestions for modifying it.
-
January 23, 2012 at 3:59 am #61513Theunis De JongMember
Oh the irony — in a script from the writer of Add Undo to Your Script! I forgot to include the magic lines at the top that checks the InDesign version.
This is a quick fix: Insert the following lines below the 5th line (if (app.docu…), above the 6th line (app.doScript ..):
if (app.version < 6)
labelItem(app.selection[0]);
else— it ought to get the main part of the script up and running. Unfortunately, it's still possible that that in turn may contain CS4-specific constructions, so if it still fails call me back in the morning.
-
January 27, 2012 at 8:16 am #61561Anne-Marie ConcepcionKeymaster
I really love the narrative in this thread! What a community. If we made a commercial for InDesignSecrets I think just scrolling through the posts from top to bottom would be a Clio winner. :D Thank you so much, jongware, especially! (And collywolly to the rescue!)
AM
-
February 17, 2012 at 3:53 pm #61651Stix HartMember
This script is great! I've managed to alter the script to make the labels and lines black, make their layer printing, have them display in millimeters with mm after it and now I'm going through adjusting the lines and boxes to be in mm instead as well. Great fun an very useful!
-
October 13, 2017 at 4:17 am #98848Paul JonesMember
Can I ask how this can be changed to use mm as the default unit?
And a more tricky one, would I be able to set this to measure to the tick marks of a placed item and not the edge?
-
August 29, 2022 at 10:55 am #14371175David BlatnerKeymaster
Jongware’s site is no more, so I uploaded the script here: creativepro.com/files/jongware/binaries/labelImageSize.zip
-
May 5, 2023 at 6:21 am #14390479giuliano bocchiParticipant
Hello there and thanks David for revamping this thread.
I am relatively new to this but I came up with a script based on the one that was originally shared on jongware’s site.I have added a few things:
the script works with multiple objects and with grouped objects,
it automatically identifies the measurement units in the rulers and outputs measurements accordingly
it defaults the layer to “printable”
it aligns the labels centered
it automatically adapts the text frames to the length of the textand a few minor things that I thought were useful.
You can find the script here: https://drive.google.com/file/d/13M8hMTa21ZHLRfzTx_DRybLWRg6VVmdK/view?usp=sharing
DISCLAIMER
The script works fine, but it has a bug that I cant’ seem to fix:
it messes up the placement of labels and lines on the first item it runs on. If you delete the labels (not the layer and not the paragraph style) and rerun the script it works fine.
If you run it on a selection of multiple objects it only messes up the first one (which is the first created, not the first displayed)I honestly have no clue as to what generates this and how to fix it.
It might be the order in which it runs through certain tasks but it really make no sense to me…
still, I’m pretty sure I simply overlooked something silly, but if any of you would like to have a look and see if you can make sense of it it would be awesome!PS. I tried to make sensible annotations in the code, and I apologise should you find it messy.
Thanks everyone
-
-
AuthorPosts
- You must be logged in to reply to this topic.