Skip navigation
kerosk_inddNew
Currently Being Moderated

Paragraph rule

May 3, 2012 4:26 AM

Hi All,

 

Is it possible to add a rule above or below my selected paragraph in the documents through Javascript?

 

In my document I require rule to cover whole paragraph (paragraph lines varies in the document) in selected paragraph style sheet named QUOTE.

 

See example below:

Screen shot 2012-05-03 at 4.55.01 PM.png

 

 

Please provide the JS code.

 

 

Thanks,

Kerosk

 
Replies
  • Currently Being Moderated
    May 3, 2012 4:52 AM   in reply to kerosk_inddNew

    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.

     

    Good luck.

     

    Dave

     
    |
    Mark as:
  • Currently Being Moderated
    May 3, 2012 10:47 AM   in reply to kerosk_inddNew

    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?

     
    |
    Mark as:
  • Currently Being Moderated
    May 3, 2012 1:44 PM   in reply to kerosk_inddNew

    hi,

     

    you may have a look at http://dtputils.com/products/view/1

     

    ... cause you'll run into problems scripting "column/page breaks" (as Mr. Saunders mentioned above)

     
    |
    Mark as:
  • Currently Being Moderated
    May 4, 2012 2:03 AM   in reply to kerosk_inddNew

    kerosk_inddNew wrote:

     

    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.

     

    Here:

     

    alert ('height of this paragraph is '+
      (app.selection[0].paragraphs[0].lines[-1].baseline - app.selection[0].paragraphs[0].lines[0].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.

     
    |
    Mark as:
  • Currently Being Moderated
    May 4, 2012 1:16 PM   in reply to kerosk_inddNew

    hi,

     

    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

     

    main()

     

    function main()

    {

        setViewPrefs([MeasurementUnits.points, MeasurementUnits.points]);

    cycleThruStories(myStories);   

            setViewPrefs(mUnits);

     

        }

     

    function setViewPrefs(units)

    {

            with(myDoc.viewPreferences){

                    horizontalMeasurementUnits = units[0];

            verticalMeasurementUnits = units[1];

        }

        }

     

     

    function cycleThruStories(docStories)

    {

     

    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[0].baseline) + myParagraph.pointSize + toAdd;

     

    with(myParagraph)

    {

        ruleBelowLineWeight=offsetWeight;

        ruleBelowOffset = -(offsetWeight  - toAdd/5*3.5); //- toAdd/5*3.5 bit more or less space? ;-)

        }

     

    }

     

            }

     

     

        }

     

        }

     
    |
    Mark as:
  • Currently Being Moderated
    May 7, 2012 12:22 AM   in reply to kerosk_inddNew

    Hi,

     

    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

     

    Hans-Gerd Claßen

     
    |
    Mark as:
  • Currently Being Moderated
    May 7, 2012 10:18 AM   in reply to kerosk_inddNew

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

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points