4

I use Inkscape as a UI designer. I want to export each group as a single SVG using the python parser and Inkscape command line renderer but I have problems with the coordinates of each object.

For example I have a group which is a complete window. Inside this group we have another group (for example the close button) that includes a path, a rectangle and an ellipse.

And the parser create tree of folders depending on <g></g>. When the parser "sees" the <g></g> then it creates a folder named <group ID> and goes deeper until it encounters <g root_img="true"></g>. Everything between <g....></g> is treated as separate SVG and calls Inkscape command line to render it, and save it as *<group ID>*.png.

This is what I have.

[folder]Window
    [image]close_btn.png
    [image]title_bar.png
    [folder]Products_list
        [image]product_belt1.png
        [image]product_belt3.png
        [image]product_belt2.png
    [folder]Advanced_options_window
        [image]hide_btn.png
        [image]title_aow_bar.png
        [folder]Options
            [image]opt1.png
            [image]opt2.png
            [image]opt3.png

I want the coordidnates values, for instance:

close_btn 1250, 10
title_bar 0, 0
product_belt1.png 150, 150

But how do I get the absolute coordinates of each group?

EDIT: It is possible to make a plug-in which I add additional arguments[x=150, y=120] to all groups in XML?

0

Not solution but part of it, idea

1 way «semi-automatic» Place tranparent 1px rectangle with mark-color #f1f2f300 in left-top corner of group and get coordinates of mark-object by parser.

2 way «automatic» As I understand it needs absolute coordinate from top-left corner, such as the size of document 1000x1000 pixels document, the root-group (height=100px) at the bottom left corner, then she has the coordinates x = 0 and y = 900. Root-group have subgroup and she has same coordinates. Or need a subgroup relative coordinates? Example root-group(0,900) subgroup (0x0)?

If you need only the absolute coordinates here easier — parse group. Compares the coordinates of objects within a group, we need an object with the smallest (x,y) coordinates. This is the position of the group.

But a little more complicated when inkscape added parameter like transform="translate(0,-100)". It appears when the group made a duplicate and change the position of the group. Here it is necessary to make additions and complicate the logic.

0

I did something very similar a few years ago. After exploring many different options for parsing SVG files I ended up with using html/javascript. Back then I traversed the SVG file using jQuery but I'm sure there are better libraries available today (and it could be a good idea to use a headless browser).

Once you know which element you want you can call Element.getBoundingClientRect() to get the absolute coordinates of it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.