Skip to main content
wangjohnwang
Participant
February 19, 2019
Answered

Get measurement value with JavaScript

  • February 19, 2019
  • 1 reply
  • 1025 views

Hi,

Is it possible to get measurement value from one page with JavaScript? If Yes, I want to add all the values up.

Thanks for help.

John

    This topic has been closed for replies.
    Correct answer try67

    Do you mean the value of a "Measurement" comment? If so, then yes, it's possible.
    It's simply a Line annotation and the result of the measurement is its "contents" property.

    So if you select it with the mouse and run this code:

    selectedAnnots[0].contents

    It will print out something like this:

    Distance:

    6.56 cm

    Since it's two lines you can access just the second one like this:

    selectedAnnots[0].contents.split("\r")[1]

    1 reply

    try67
    Community Expert
    try67Community ExpertCorrect answer
    Community Expert
    February 19, 2019

    Do you mean the value of a "Measurement" comment? If so, then yes, it's possible.
    It's simply a Line annotation and the result of the measurement is its "contents" property.

    So if you select it with the mouse and run this code:

    selectedAnnots[0].contents

    It will print out something like this:

    Distance:

    6.56 cm

    Since it's two lines you can access just the second one like this:

    selectedAnnots[0].contents.split("\r")[1]

    wangjohnwang
    Participant
    February 19, 2019

    Yes, I measure from a pdf drawing. I want to add all the distance values up.

    try67
    Community Expert
    Community Expert
    February 19, 2019

    Then you can write a script that iterates over all the comments (annotations) in the file, checking if they're of the Line type (and maybe also if their subject is "Distance Measurement") and then parse their contents in the way I described above and add them up.