Skip to main content
Øyvind235243823c6v
Known Participant
October 15, 2023
Answered

Using resolve() to get coordinates / position

  • October 15, 2023
  • 2 replies
  • 1274 views

I'm trying the get positions of a line, and since geometricBounds / visibleBounds just give me the frame position I thought I could get it through "resolve()". But I'm apparently missing something; every example I find for resolve() uses AnchorPoint and CoordinateSpaces, but I'm not sure how to reference them

 

Example:

const id = require("indesign");
const app = id.app;

// We only have one item (line) in the document
const line = app.activeDocument.pageItems.item(0); 
// Use resolve method, where all examples look like this:
const position = line.resolve(AnchorPoint.TOP_LEFT_ANCHOR, CoordinateSpaces.SPREAD_COORDINATES)[0];
console.log(position);

Which gives

ReferenceError: AnchorPoint is not defined

How do I set up my code so that it gets the correct "AnchorPoint.TOP_LEFT_ANCHOR" and "CoordinateSpaces.SPREAD_COORDINATES" ?

This topic has been closed for replies.
Correct answer Robert at ID-Tasker

As @rob day pointed out - you need to get into PathPoints collection of the Path(s) of the Object.

 

But I don't think you need to use resolve() ? 

 

2 replies

rob day
Community Expert
Community Expert
October 15, 2023

Or, if the line is pasted into a pageitem:

 

var gl = app.activeDocument.pageItems[0].graphicLines[0].geometricBounds

alert("X: " +gl[1]+ "  Y: " + gl[0])

 

 

To use resolve try this:

var gl = app.activeDocument.pageItems[0].graphicLines[0]
var a = gl.paths[0].pathPoints[0].anchor

//returns points
alert(gl.resolve(a,CoordinateSpaces.PARENT_COORDINATES))

 

 

Øyvind235243823c6v
Known Participant
October 15, 2023

Yes, this is probably what I'm after 🙂

But how do I find the correct CoordinateSpace enum?

 

Example, when I run this:

var gl = app.activeDocument.pageItems[0].graphicLines[0]
var a = gl.paths[0].pathPoints[0].anchor

//returns points
alert(gl.resolve(a,CoordinateSpaces.PARENT_COORDINATES))

I get a value for "a", but I get this error for the second parameter:

ReferenceError: CoordinateSpaces is not defined

 

rob day
Community Expert
Community Expert
October 15, 2023
rob day
Community Expert
Community Expert
October 15, 2023

Hi @Øyvind235243823c6v , Try getting graphicLines:

 

var gl = app.activeDocument.graphicLines[0].geometricBounds

alert("X: " +gl[1]+ "  Y: " + gl[0])

 

Øyvind235243823c6v
Known Participant
October 15, 2023

Yes, that gives me the frame position, but I need to get the position for the contents of the frame, i.e for each line start and end

 

E.g. these two lines will give me the same geometricBounds:

 

I need to find the find the x1,y1,x2,y2 point of each line. The x1,y1 of the blue line is not the x1,y1 of the black line

 

I was probably a bit unclear describing my problem 🙂

 

I've looked through all attributes and cannot find any reference, so I thought I needed to use a function like resolve()

 

Is there any other attributes on 

app.activeDocument.graphicLines

that show these values?

Robert at ID-Tasker
Robert at ID-TaskerCorrect answer
Legend
October 15, 2023

As @rob day pointed out - you need to get into PathPoints collection of the Path(s) of the Object.

 

But I don't think you need to use resolve() ?