Calculating the width and height of a group of elements

Post questions on how to use or achieve an effect in Inkscape.
jhopkins
Posts: 1
Joined: Wed Jun 15, 2011 5:01 pm

Calculating the width and height of a group of elements

Postby jhopkins » Wed Jun 15, 2011 5:14 pm

First off, thanks to the Inkscape team for making such a great product.

I'm trying to write a script that resizes the data from a group of .svg files and places them all together into 1 finished file. Using <g transform=""> is doing the trick when I fiddle with it by hand, but I need the transformation numbers to be based on the collective width and height of a group of SVG elements - each of my .svg files' collective objects are a different size. Does Inkscape provide a mechanism in Python for calculating the width and height of the objects inside a <g> container? I've looked through the SVG spec several times and I can't seem to find a way to do this easily.

Thank you for any ideas that you have.

User avatar
tomh
Posts: 218
Joined: Sat Feb 14, 2009 10:14 pm

Re: Calculating the width and height of a group of elements

Postby tomh » Wed Jun 15, 2011 11:29 pm

Not sure about from within python, but I know that it can from the command line. (I beleve several extentions call inkscape a second time as a process to get the command line data).

from the command line, you can use the query commands:

relevent section of Man page
-I, --query-id
Set the ID of the object whose dimensions are queried. If not set, query options will return the dimensions of the drawing (i.e. all document objects), not the page or viewbox

-X, --query-x
Query the X coordinate of the drawing or, if specified, of the object with --query-id. The returned value is in px (SVG user units).

-Y, --query-y
Query the Y coordinate of the drawing or, if specified, of the object with --query-id. The returned value is in px (SVG user units).

-W, --query-width
Query the width of the drawing or, if specified, of the object with --query-id. The returned value is in px (SVG user units).

-H, --query-height
Query the height of the drawing or, if specified, of the object with --query-id. The returned value is in px (SVG user units).

-S, --query-all
Prints a comma delimited listing of all objects in the SVG document with IDs defined, along with their x, y, width, and height values.




Return to “Help with using Inkscape”