"The" x value? Left? Center? Right?
To get any if these three, you need not group everything first. Just gather all x coordinates from their geometricBounds and: for Left, take the minimum; for Right, take the maximum; for center, first find the minimum *and* maximum and use the average.
@bduffy323 – would you like to consider anchored objects for calculating the x coordinates?
Then Jongware's method would be best. Of course you have to use "allPageItems" for every selected object to get ALL the geometric bounds. Maybe even better to use the visual bounds of the objects…
In this case the UI controls are misleading and grouping the objects does not add information…
Something more to consider:
At first glance this task seems trivial, but unfortuantely it is not, if you want to take into account tables that exceed text frames, effects like drop shadows, text on paths, generally spoken, texts that exceed the text frames and the case of anchored objects.
@jongware That is what I normally do until I reached a situation shown below. For me, this group of page items needs to be assigned the x-value from page one. By just running through the geometric bounds for each of the pages items, the top page item returns an x value based on the right page. So my solution was to temporarily group the objects, get the x value and then ungroup. However, this was becoming an issue because the group was bringing pageitems that were behind other items to the front and not sending them back on an ungroup. I am trying to avoid temporarily changing the rulerOrigin to spread but I'm pretty sure that would work. I was really hoping there was a way to get the bounds that shows when I select a group of page items.
@Uwe - I am coming to realize that this task isn't as trivial as I first thought it would too! I run through allpageitems that are tied to my label then attempt to climb the parent tree to a top level page item. Which proves to be difficult with anchored objects!
@bduffy323 – That's a valid point!
To find out, if a specific object is an anchored one, you can check its parent:
that will always be a character.
@Uwe - This is PRECISELY what I did. I didn't know if this was always valid but it seemed to work so it is nice to know that. Side note to this thread. Is there anyway of getting the pageitem that anchor is inside of?
That should be the "parentTextFrame".
This, of course, is an array and since we have only one single character to consider, you will be good with "parentTextFrames". It will usually result in a TextFrame Object; is the character part of text on path, you'll get a TextPath Object.
And that could be part of a text frame (or a spline item of the type Rectangle, Oval or Polygon), which itself could be anchored, etc.pp.
No nice and easy task, in my opinion…
Is someone else here to cut this Gordian Knot? ;-)
I actually saw that post before posting this one. When I tried this method I got strange results including some negative values.
@bduffy323, in case of your post no 3,
did you consider to change a doc view pref rulerOrigin to SPREAD
to avoid repeating X-values accross a spread?