Yes it is possible, although you need to answer the question: what do you want to do at column/page breaks? Your described techique won't work there.
But you seem to be expecting some kind soul to just write a script for you. That might happen, but most people needing a script who aren't prepared to write one themselves would look to hire someone to do the work for them.
I will do it manually. But need to apply pagragraph rule globally in document.
I write below code but don't know how to calculate paragraph height in paragraph length.
If anybody has done this before please add the required code in my below JS code.
You can use the text baseline for that: http://jongware.mit.edu/idcsjs5.5/pc_Text.html#baseline
Read the baseline for the first and the last line. The difference between these is the exact "height" of the paragraph, usually a multiple of its leading (1). Calculate this in points to immediately feed the value into RuleBelowWeight. You'll have to manually find the difference to shift down, but I think you only need to do this once.
(1) If all of your paragraph text uses the same leading, this would simply be
someParagraph.lines.length * someParagraph.leading;
-- but not if it's set to Auto, though (still possible but then you'd use autoLeading and pointSize instead).
... Why are you changing your paragraph style in your sample? Are all of your "QUOTE" paragraphs exactly the same amount of lines?
Thanks, Jongware for your suggestion. You are really a master.
QUOTE paragraphs are different amount of lines. Looking for ready JS code.
QUOTE paragraphs are different amount of lines.
Yeah I realize that, but you suggested changing the paragraph style, so they would all be the same.
Looking for ready JS code.
alert ('height of this paragraph is '+ (app.selection.paragraphs.lines[-1].baseline - app.selection.paragraphs.lines.baseline)+ ' in your current vertical measurement units');
This measures from the first baseline to the last, so it's one line "short" so you should add your leading to it. (I couldn't test this because my leading is set to "Auto", but it's easy enough.)
As the alert says, this is in your current measurement units. To set the line weight, you need one of two: either a string of the value plus its measurement unit ("20 mm") or a numerical value (which would be in points). If you are not already working in points, you have to somehow construct this value. You could either try out the infernal function UnitValue (which I personally have given up on), or simply temporarily set verticalMeasurementUnits to POINTS, measure, then reset it to what it was.
1 person found this helpful
this should basically do the job ... column/page breaks are not considered.
Cycles thru the stories of the document to find a certain pStyle, modifies the existing rule below.
It's not perfect ;-)
var pStyleName, myDoc, mUnits, myStories, myStory, myParagraphs, myParagraph, offsetWeight, toAdd, s, p
pStyleName = 'quote' //the paragraphstyle to look for ...
myDoc = app.activeDocument;
mUnits = [myDoc.viewPreferences.horizontalMeasurementUnits, myDoc.viewPreferences.verticalMeasurementUnits];
myStories = myDoc.stories;
toAdd = 8; //to add to lineweight in pt; space above and below
horizontalMeasurementUnits = units;
verticalMeasurementUnits = units;
for(s = 0; s < docStories.length; s++)
myParagraphs = docStories[s].paragraphs;
for(p = 0; p< myParagraphs.length; p++)
myParagraph = myParagraphs[p];
if(myParagraph.appliedParagraphStyle.name === pStyleName)
offsetWeight = (myParagraph.lines[-1].baseline - myParagraph.lines.baseline) + myParagraph.pointSize + toAdd;
ruleBelowOffset = -(offsetWeight - toAdd/5*3.5); //- toAdd/5*3.5 bit more or less space? ;-)
if you can't get 'myParagraph.lines[-1].baseline' then you probably have a overflow of the paragraph in the text frame (shown as a red '+') ... and so it's not possible to get / calculate a position.
you can ignore it by try catch or write a function to calculate from the last line in the textframe in that case.
have a nice day
Thank you so much, Hans. It is working. The script does not apply rule below on quote paragraph style if text is flowing on one page to next page.
Thanks once again for your support.
>It is working. The script does not apply rule below on quote paragraph style if text is flowing on one page to next page.
That was mentioned right away as a flaw of this method ... Did you check out dtputils' plugin? That adds it as a paragraph attribute, as Adobe should've done long ago.