Skip to main content
Participant
March 25, 2024
Answered

How do I get the x and y coordinates of a paragraph with ExtendScript?

  • March 25, 2024
  • 1 reply
  • 156 views

I've never done much with ExtendScript and am trying to get a little bit familiar with it. Assuming I have a paragraph object, how can I get the x, y location of the beginning of the paragraph?

 

Thanks,

Nick

This topic has been closed for replies.
Correct answer frameexpert

Here is a way to do this with the beginning of the paragraph containing the text cursor. Note that the values are relative to the subcolumn containing the paragraph. And the top offset is to the baseline of the text in the paragraph.

 

var PT, doc, pgf, textLoc, prop, value;

PT = 65536; // Metric for a Postscript point.

doc = app.ActiveDoc;
// The paragraph object containing the cursor.
pgf = doc.TextSelection.beg.obj;
// Make a text location at the beginning of the paragraph.
textLoc = new TextLoc (pgf, 0);

// Left offset in points.
prop = doc.GetTextPropVal (textLoc, Constants.FP_LocX);
value = prop.propVal.ival / PT;
alert (value);

// Top offset in points.
prop = doc.GetTextPropVal (textLoc, Constants.FP_LocY);
value = prop.propVal.ival / PT;
alert (value);

1 reply

frameexpert
Community Expert
frameexpertCommunity ExpertCorrect answer
Community Expert
March 25, 2024

Here is a way to do this with the beginning of the paragraph containing the text cursor. Note that the values are relative to the subcolumn containing the paragraph. And the top offset is to the baseline of the text in the paragraph.

 

var PT, doc, pgf, textLoc, prop, value;

PT = 65536; // Metric for a Postscript point.

doc = app.ActiveDoc;
// The paragraph object containing the cursor.
pgf = doc.TextSelection.beg.obj;
// Make a text location at the beginning of the paragraph.
textLoc = new TextLoc (pgf, 0);

// Left offset in points.
prop = doc.GetTextPropVal (textLoc, Constants.FP_LocX);
value = prop.propVal.ival / PT;
alert (value);

// Top offset in points.
prop = doc.GetTextPropVal (textLoc, Constants.FP_LocY);
value = prop.propVal.ival / PT;
alert (value);