Inkscape.org
Beyond the Basics Is it possible to have dynamic xml values
  1. #1
    nico rey nico rey @reytrace

    Technical question for masters
    Is it possible to have "dynamic values" in the editor

    IE:
    I want to draw a 120x160 rectangle and a 20x20 circle in the center of the rectangle.

    I'd like to dynamicaly position the circle at :
    circle.y=rectangle.height/2
    circle.x=rectangle.width/2

    This way as soon as I change the rectangle shape, the circle stays in the center.

    Any idea on how to do that ?

  2. #2
    Xav Xav @Xav👹

    Inkscape uses the SVG file format, which is an XML-based language. The XML editor just lets you directly edit the content of the SVG file, and does little validation of what you enter. So although it won't stop you entering something like that, it also won't have any effect, since the SVG language doesn't support those sorts of dynamic values.

    However, SVG can be manipulated by JavaScript, which would let you achieve dynamic values. But there's a massive caveat to this: Inkscape doesn't have a JS interpreter, so even writing some JS code wouldn't let you have that sort of dynamic effect while editing within Inkscape. JS in SVG files is only really executed when they're loaded into a web browser.

    So for what I think you're trying to achieve, the answer is no. But if you're actually looking for something that could be scripted to run in a web page, the answer is that it is possible, but requires the right technical skills to write the code.

  3. #3
    Paddy_CAD Paddy_CAD @Paddy_CAD

    Maybe something like this. It's a hack, but it works.

    Centered Circle
  4. #4
    Paddy_CAD Paddy_CAD @Paddy_CAD
    *

    Inkscape has some "dynamic" capabilities. Live path effects are recalculated when the underlying shapes are edited. However, there's no interface exposing this functionality so the user can't create new effects. Time to put on your programming hat. I don't have one myself.

  5. #5
    nico rey nico rey @reytrace

    Wow I'll try the browser thing thanks a lot.

  6. #6
    Xav Xav @Xav👹
    reytrace

    Wow I'll try the browser thing thanks a lot.

    Unless you're an experienced web developer, you probably don't want to do that.

    I've attached a proof-of-concept that I've put together. Load it directly into your browser and you should be able to drag the handle around to resize the rectangle and see that the circle remains centred. But it takes nearly 100 lines of quite advanced JS to achieve that (near the bottom of the file, if you load it into a text editor).

  7. #7
    nico rey nico rey @reytrace
    *

    Wow this is something, Sorry for the late answer I was working abroad. I don't know javascript, evne though i am not a programer, i did some python, so i'll check that javascript code.

    Thanks a lot for your help!

     

Inkscape Inkscape.org Inkscape Forum Beyond the Basics Is it possible to have dynamic xml values