Scribus > Scripts and Plugins

how to align an image frame relative to margins in scripter?

(1/1)

fredzannarbor:
Hi,

I want to align an image frame centered relative the page margins in scripter, just as I would using Align & Distribute in the UI.  How to accomplish?

Nermander:
I have no idea how to do it in the scripter, but I assume that if you can get the positions of margins and the size of the frame you can calculate the necessary numbers and change the position of the frame to those numbers.

That is kind of what the Align & Distribute does for you, but I think when using the scripter you have to code these calculations yourself.

(I have done a lot of similar calculations, not in the Scribus scripter though, but in my perl scripts for doing impositions of postscript files that I used when I wanted to typeset books from Project Gutenberg to use when learning bookbinding. There is an old wiki page about these here https://wiki.scribus.net/canvas/How_to_make_impositions_with_pstops )

RobSay:
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:

--- Code: ---# 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")

--- End code ---

Centre alignment requires a little more maths:

--- Code: ---viewport_width= PageWidth - (inner + outer)
leftpage_target_x = outer + (viewport_width-frame_width)/2
rightpage_target_x = inner + (viewport_width-frame_width)/2

--- End code ---

Distribute functions are a little more complex - but do-able if you really need it.)

Navigation

[0] Message Index

Go to full version