There aren't any direct alignment methods as per the UI options. As Nermander says - you can use
getPageMargins and related methods - but then you have to calculate the desired position for the object and set this. It is also possible to use guides in the same way but I just used the calcs off page or margin as needed.
Note that if you are using facing pages with inner and outer margins then
getPageMargins will return a tuple of (top,inner,outer,bottom) which is actually really useful - but you still need to know whether you are on a right or left page as the calcs are different:
- Left Page, align to margin: x = Outer
- Right Page, align to margin: x = Inner
It's fairly easy to write a function for 'align to margins' for a given item:
Pseudo-code to align at margin top left:
# assume left page and use outer margin
x = getPageMargins()[2]
if getPageType() == 2 :
# 2 is a RIGHT PAGE so use inner margin
x = getPageMargins()[1]
y = getPageMargins()[0]
moveObjectAbs(x,y,"myObjectName")
Centre alignment requires a little more maths:
viewport_width= PageWidth - (inner + outer)
leftpage_target_x = outer + (viewport_width-frame_width)/2
rightpage_target_x = inner + (viewport_width-frame_width)/2
Distribute functions are a little more complex - but do-able if you really need it.)