return absolute leading
Learn / Forums / InDesign Add-ons (Scripts, Scripting, and Plug-ins) / return absolute leading
- This topic has 6 replies, 2 voices, and was last updated 7 years ago by Raphael Freeman.
-
AuthorPosts
-
-
February 16, 2017 at 8:00 am #92264Raphael FreemanParticipant
I am writing my very first script (wish my luck) and I’m trying to return the leading of text that I have selected. The problem is that the leading happens to be set to Auto and I want it to return the absolute leading.
This is what I typed:
app.selection[0].leading;
and it gave me AUTO instead of 15. (The leading happens to be 12/Auto but in the character panel it says (15pt)
Is there a way to return 15?
-
February 16, 2017 at 8:08 am #92265Loic AigonMember
Hello,
Leading can either be a numeric value or an enumeration ( Leading.AUTO ) which you got.
So you may want to check if leading is set that wey and if so compute the leading based on font size and autoLeading value:
[pre]
var sel = app.selection[0];
var leading = sel.leading;
leading==Leading.AUTO && leading = sel.pointSize*sel.autoLeading/100;
alert (“leading is worth:”+leading );
[/pre]FWIW
-
February 16, 2017 at 8:21 am #92267Raphael FreemanParticipant
Thank you very much. I will try that.
-
February 27, 2017 at 7:26 am #92424Raphael FreemanParticipant
So I have progressed (thanks to the starting clue) with my little script and I have managed to set the baseline grid and offset with a script (yey).
I’m trying to enhance the script to make it a little more useful and I’m getting stuck on the moving of a frame.
For the script to work, I have to select some text. When I do that and run the script, it successfully does what I set out for it to do. (The variable mySel is defined earlier correctly)
var myFrameGB = mySel.parentTextFrames[0].geometricBounds;
alert(myFrameGB[0]);So this bit works and returns the top edge of the text frame. but I want it not to be 67.87363pt but rather 25 so I tried this line:
myFrameTopGB[0] = 25;
However nothing happens. What have I done wrong?
-
February 27, 2017 at 7:38 am #92425Raphael FreemanParticipant
sorry, I made a mistake in my code above!
I should have written
myFrameGB[0] = 25;
not that it works now, but now at least there is no syntax error.
-
February 27, 2017 at 8:14 am #92428Loic AigonMember
[QUOTE]However nothing happens. What have I done wrong?[/QUOTE]
It’s not that you do something wrong but you are misleading yourself. When you write
myFrameGB[0] = 25;
you are just adding 25 to the value stored in the array myFrameGB at index 0.If you want to affect object geometry, you need to either reset the whole array like
myFrameGB[0]=25;
myObjet.geometricBounds = myFrameGB;Or use specific functions such as mov, transform or resize. See docs for further details.
-
February 27, 2017 at 8:28 am #92431Raphael FreemanParticipant
Thank you. It works now!
-
-
AuthorPosts
- You must be logged in to reply to this topic.