Skip to main content
Inspiring
July 6, 2015
Answered

Struggling to understand CoordinateSpaces using resolve method

  • July 6, 2015
  • 1 reply
  • 2093 views

As the title of my post says... I'm struggling to understand CoordinateSpaces. I read the description provided in the 'Adobe InDesign CS6 JavaScript Scripting Guide' and I created a simple document to confirm my understanding. But the results I received were not as expected and I don't think I understanding some core concepts.

I will write some blocks of code and then try to explain what I think they work.

$.writeln( document.selection[0].resolve( [[0,0], BoundingBoxLimits.GEOMETRIC_PATH_BOUNDS], CoordinateSpaces.PAGE_COORDINATES )[0] );

This functions as I expected. The following is a breakdown of the arguments and my understanding of them:

  1. [0,0], BoundingBoxLimits.GEOMETRIC_PATH_BOUNDS
    1. [0,0] – anchor position relative to the object bounds – Top Left
    2. BoundingBoxLimits.GEOMETRIC_PATH_BOUNDS –  I am assuming that this makes the anchor position relative to the PageItem's path where as OUTER_STROKE_BOUNDS makes the anchor position include stroke weight extending past the PageItem's path
  2. CoordinateSpaces.PASTEBOARD_COORDINATES – Is the location of the anchor point within the pasteboard coordinate space


Now this is all understandable but then I saw the following code on indiscripts:

$.writeln( document.selection[0].resolve( [[0,0], BoundingBoxLimits.GEOMETRIC_PATH_BOUNDS, CoordinateSpaces.INNER_COORDINATES], CoordinateSpaces.INNER_COORDINATES)[0];


  1. [0,0], BoundingBoxLimits.GEOMETRIC_PATH_BOUNDS, CoordinateSpaces.INNER_COORDINATES]
    1. [0,0] – as above
    2. BoundingBoxLimits.GEOMETRIC_PATH_BOUNDS – as above
    3. CoordinateSpaces.INNER_COORDINATES – This bit I don't understand. I read the Adobe InDesign CS6 JavaScript Scripting Guide and it seems to suggest that this is the location of the anchor point within the coordinate space. But that doesn't make sense to me because thats what the last argument is meant to do isn't it?
  2. CoordinateSpaces.INNER_COORDINATES – Confused now because of point above


So as you can see this example the introduction of a coordinate space in the first argument confuses me. If somebody could help me understand its purpose I would really appreciate it.

Also I have the following questions about coordinate spaces:

  1. PARENT_COORDINATES – Wouldn't this just be spread? All PageItems parents are a spread right?
  2. INNER_COORDINATES – What is this!? Documentation says it's the coordinate space the object was created in. How can I tell what coordinate space an object is created in? Why is this usful? If I draw a rectangle on a page is its created the pasteboard, page, or spread coordinate space?
This topic has been closed for replies.
Correct answer Marc Autret

Hi McShaman,

1. On the introduction of a coordinate space in the location argument of the resolve() method, give a read at Indiscripts :: InDesign Scripting Forum Roundup #7

In short this parameter allows you to specify which bounding box is considered, noting that a single spline item has many possible b-boxes depending on the space you look from. More details on the full syntax of the location argument will come soon in the next chapters of my “Coordinate Spaces & Transformations” PDF.

2. The parent coordinate space of a PageItem might be another PageItem's (inner) space, in case for example of a grouped object. Coordinate spaces basically reflect object hierarchy.

Many details on this topic have been already exposed in CS&T: http://www.indiscripts.com/post/2014/03/coordinate-spaces-and-transformations-1

Hope that helps,

@+

Marc

1 reply

Marc Autret
Marc AutretCorrect answer
Legend
July 6, 2015

Hi McShaman,

1. On the introduction of a coordinate space in the location argument of the resolve() method, give a read at Indiscripts :: InDesign Scripting Forum Roundup #7

In short this parameter allows you to specify which bounding box is considered, noting that a single spline item has many possible b-boxes depending on the space you look from. More details on the full syntax of the location argument will come soon in the next chapters of my “Coordinate Spaces & Transformations” PDF.

2. The parent coordinate space of a PageItem might be another PageItem's (inner) space, in case for example of a grouped object. Coordinate spaces basically reflect object hierarchy.

Many details on this topic have been already exposed in CS&T: http://www.indiscripts.com/post/2014/03/coordinate-spaces-and-transformations-1

Hope that helps,

@+

Marc

McShamanAuthor
Inspiring
July 19, 2015

Hi Marc Autret‌,

Thanks for those resources. I wish Adobe put in half as much effort with their documentation as you guys at Indesign scripts do!

I am starting to grasp these concepts better, I just have a couple of questions:

1. Consider that I have a new document and I draw a rectangle somewhere on the page. With that rectangle selected I run the following code:

$.writeln( document.selection[0].resolve( [ AnchorPoint.TOP_LEFT_ANCHOR, BoundingBoxLimits.GEOMETRIC_PATH_BOUNDS, CoordinateSpaces.INNER_COORDINATES ], CoordinateSpaces.INNER_COORDINATES ) );

Now the second argument (inSpace) is set to CoordinateSpaces.INNER_COORDINATES. I would have thought position 0, 0 of the rectangles inner coordinate space would be the middle of the shape. But instead it seems to be the middle of the spread coordinate space. Is this right? Is there a reason why?

2. In the Scripting Roundup link you sent me it makes the following statement:

The PageItem.resolve() method has three parameters: location, inSpace, and consideringRulerUnits (optional). The most important one, location, has almost ten different forms (all poorly documented).

Is there anywhere these other forms a documented?

Marc Autret
Legend
July 20, 2015

Hi McShaman,

Now the second argument (inSpace) is set to CoordinateSpaces.INNER_COORDINATES. I would have thought position 0, 0 of the rectangles inner coordinate space would be the middle of the shape. But instead it seems to be the middle of the spread coordinate space. Is this right? Is there a reason why?

Yes and yes. According to your parameters, the resolve() method is asked to express the location of the inner bounding box top left anchor point relative to the inner coordinate space. A little known fact is that the origin of the inner coordinate space of any new page item coincides with the origin of the pasteboard space—which also is the origin of the first spread. Details here: http://indiscripts.com/blog/public/data/coordinate-spaces-and-transformations-1/CoordinateSpacesTransfos01-02.pdf#page=1…

(It took me a long time to understand this phenomenon, for intuitively we all think that the inner space origin of an object should coincide with some inherent center point. The fact is, inner coordinate space does not fit inner bounding box. Moreover, bounding boxes are not coordinate spaces, although one can express locations in any bounding box system.)

Also, take note that the coordinates returned by your resolve() code will not change if you move the object! Indeed, the translation affects the inner space origin itself, in a way that the transformation matrix of the object relative to its inner space always remains the IDENTITY matrix. Seen from the pasteboard space perspective, the original location of the inner space origin is [0,0] and any change in this value reveals the distance to which the object has been moved since its creation (which is an interesting feature.)

For example, suppose you draw a rectangle at some location anywhere in your document. Now, move the object randomly, and move it again as much as you like… You can even close and reopen the document, create other objects, and so on. The very original location of the rectangle can always be restored using the [x,y] coordinates of its inner space origin relative to the pasteboard and applying the inverse translation, as shown below:

var myPageItem = app.selection[0];

// Inner space origin of the sel (in pasteboard space.)

// ---

var xy = myPageItem.resolve(

    [[0,0],CoordinateSpaces.INNER_COORDINATES],

    CoordinateSpaces.PASTEBOARD_COORDINATES

    )[0];

// Restore the original location by reverting the translation.

// ---

myPageItem.transform(

    CoordinateSpaces.PASTEBOARD_COORDINATES,

    [0,0],

    [1,0,0,1].concat([-xy[0],-xy[1]])

    );

About the full documentation of the location parameter, it will be detailed in the next chapters of my PDF.

@+

Marc