You must be logged in to post Login

Search Forums:


 






Script to label selection with height and width

UserPost

8:50 am
January 13, 2012


suzerp

Community Member

posts 9

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!


9:14 am
January 13, 2012


Jongware

Member

posts 764

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.

9:37 am
January 13, 2012


David Blatner

Admin

posts 823

One idea is to use the Frame Reporter plug-in from rorohiko:

http://www.rorohiko.com/wordpr…..ereporter/

co-host, InDesignSecrets.com

10:06 am
January 13, 2012


suzerp

Community Member

posts 9

Hi Jongware – yes it was your script that gave me the idea that this would either already exist or be possible (http://indesignsecrets.com/for…..bel-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).

4:14 pm
January 13, 2012


Jongware

Member

posts 764

Post edited 4:23 pm – January 13, 2012 by Jongware


… 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: http://www.jongware.com/binari…..geSize.zip

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

8:26 am
January 16, 2012


suzerp

Community Member

posts 9

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!

10:35 am
January 17, 2012


suzerp

Community Member

posts 9

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?

11:54 am
January 17, 2012


Jongware

Member

posts 764

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?

1:12 pm
January 17, 2012


suzerp

Community Member

posts 9

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).


2:57 pm
January 17, 2012


Jongware

Member

posts 764

Can you check if the script created any of the three items before crashing?

3:09 pm
January 17, 2012


suzerp

Community Member

posts 9

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.

4:01 am
January 18, 2012


collywolly

Adelaide, Australia

Member

posts 83

Post edited 4:02 am – January 18, 2012 by collywolly


@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:"Helvetica\tRegular"

to a font which is definitely on the other user's system.

on my mac, there was no Helvetica Regular, instead just used Arial\tRegular.


after that, the script worked.

Keep an open mind, but not so open that your brain falls out – Richard Dawkins

8:21 am
January 19, 2012


suzerp

Community Member

posts 9

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!

9:38 am
January 19, 2012


Jongware

Member

posts 764

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 …)

9:03 pm
January 22, 2012


bluehz

New Member

posts 2

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.

3:59 am
January 23, 2012


Jongware

Member

posts 764

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.

8:16 am
January 27, 2012


Anne-Marie

Admin

posts 147

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

3:53 pm
February 17, 2012


Stix Hart

Community Member

posts 7

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!