Moving an object dynamically parsing the XML (sla) file.

Previous topic - Next topic

Thibaud

Hi,
I using the ScribusGenerator script in order to generate covers of books from a csv, with changing position and sizes of objects from a Scribus template. But sizes and positions are from the csv using millimeters when Scribus uses special units.
So I want to change the values of the PAGEOBJECT tags dynamically. For this, I need to convert values like millimeters to "Scribus units".
However, I don't understand how work the units used in Scribus with XPOS, YPOS, gXpos, gYpos, WIDTH and HEIGHT... I can"t switch from millimeters to units.
Here is a very simple example: I want to move a circle which is in a left square, to a right square.

So I want to change the XPOS value of the PAGEOBJECT with ANNAME="CIRCLE".
Reading my .sla file, I know the answers, but I need to get them by computing from milimeters values.
Here is the table I use for the maths:

So, when Scribus says to me that my circle is X positioned at 20mm, I read from the .sla that it is 156,693913385827 units. It has a width of 75mm, and the .sla indicates that is 212,59842519685 units.
So I suppose that I can make a cross product: xpos = ( width / width_mm ) * xpos_mm
However this formula get me a number very far from the attended answer what 20mm :
( 212,59842519685 / 75 ) * 20 = 56,6929133858267 ; it would be 20 mm!
In conclusion: how can I change the size and the position of graphical objects dynamically into the .sla code from millimeter units?
I join the .ods and the .sla files.

Nermander

If I am not wrong Scribus uses points as internal unit. 212,6 points seem to equal 75 mm, but I think for the 20 mm the issue is that Scribus does maybe not use the upper left corner of the page as reference.

Are you using bleed?

MrB

The Scribus format uses points. You may reference units.cpp for all the conversion factors.

Thibaud

Thanks @MrB ! I read the code from units.cpp that 1cm = 2,54/72 units, it's clear now.
And thanks @Nermander ! I don't use Bleed, but I saw that in my document, I get this:
<MASTERPAGE PAGEXPOS="100.00062992126" PAGEYPOS="20.0012598425197" PAGEWIDTH="1190.55118110236" PAGEHEIGHT="841.889763779528"Now I am able to take in account the pagexpos and pageypos values to move an object.

In fact, this solution (proportionality) works only when you need to move an object, not when you have to resize it. In my case, I was needing to resize a square (as a guide for the cutting). But if you resize it using the WIDTH property, the original width is keeping in the "path" and the "copath" properties (with rounded figures), and the form is not displays correctly (I get a red square for the new form, a black one for the original, what is displayed in the final pdf).
In the case of the square from my example you have to edit the two following properties:
WIDTH="333.992544220922"
path="M0 0 L333.993 0 L333.993 20 L0 20 L0 0 Z"

Thibaud

The edition of the path et copath attributes with ScribusGenerator works. Problem solved, many thanks!