Inkscape.org
Creating New Extensions Root system generator
  1. #1
    kt_inkscape kt_inkscape @kt_inkscape

    Hey Inkscapers. Hope you're having an awesome day...

    Ok, so I've been asked to generate a random root structure type graphic. Fairly thick roots, meandering, over lapping etc. My first thought was to adapt the Tree extension and invert it.

    I downloaded the Dropbox script on here : https://alpha.inkscape.org/vectors/www.inkscapeforum.com/viewtopic3404-2.html?t=19449

    But can't seem to install pturtle as calls to this are making the rtree-debug extension wig out, so not sure if that's been superseded?

    So thought, find the Render > Random Tree.. extension copy that and see if I can make it do multiple tress and thicken / separate the paths. Can't seem to find this anywhere so coupla questions, where would I find this script and would this be the best way of generating a tangled root style graphic? Thoughts welcomed!

    Enjoy, Cheers, Keith

  2. #2
    Tyler Durden Tyler Durden @TylerDurden

    Maybe this:

     

    New Document 2   Inkscape 2022 04 06 13 41 46
  3. #3
    Polygon Polygon @Polygon🌶

    In essence the Random Tree won´t make it?

    I believe that´s the one you´re searching for in the Inkscape package:

  4. #4
    kt_inkscape kt_inkscape @kt_inkscape

    Kind of… And thanks.. 😊 When I ran the extension it generated “single” / tightly packed root segments. Do we know where I could find the script on Windows as it wasn’t obvious? Ta.. 

  5. #5
    kt_inkscape kt_inkscape @kt_inkscape

    Damn windows search… located and will have a look later. Have a great day both! Cheers Keith 

  6. #6
    kt_inkscape kt_inkscape @kt_inkscape

    And promise not to press the submit button so many times next time… 🤨

  7. #7
    Polygon Polygon @Polygon🌶

    Isn´t the path the same inside the Windows version? 

  8. #8
    Tyler Durden Tyler Durden @TylerDurden

    ...ish...

    C:\Program Files\Inkscape\share\inkscape\extensions\
  9. #9
    kt_inkscape kt_inkscape @kt_inkscape

    Hi both. Thanks for the input. Always learning... 😊

    Which leads me to my next question.. I'm working on an  extension (non turtle based) to draw roots and branches, something to get me into writing extensions and working with Python. Odd beast..

    So I can generate multiple elements (with specified names / ids) onto a new layer group (with a specified name / id). The loop is "generate element", randomize some variables, generate a new element etc. What I would like to do is generate element, make it branchey / rooty, randomize variables, repeat. What I'm struggling with is how to select path / segment element (by id / by layer to get all?) and make it branchey / rooty. and whether I should generate all elements then do the fancy bit or do the fancy bit after the generation of each element. I'm guessing en masse at the end of the element generation stage would be more efficient.

    I'm currently looking to have the py / inx files available via GitHub shortly, but not really used it much and just setting up VS code etc etc.. Have attached for now. Please excuse randomness, happy to accept advice. Happy to explain any of my non coder code if anyone has any thoughts!

    Basically, the question is how do I select a path so I can use fractalise or some some pattern to make the elements more root / branch like. Thanks in advance.

  10. #10
    kt_inkscape kt_inkscape @kt_inkscape

    UPDATE Aiming to keep this up to date, it would be great if you could confirm this works and is the standard method : https://github.com/ktacme/extensions.git

    Cheers all

  11. #11
    Tyler Durden Tyler Durden @TylerDurden

    Topic moved to extensions forum.

  12. #12
    inklinea inklinea @inklinea⛰️

    If you are the creator of the elements, you can add an id as you create each one.
    You can also add the id ( or the entire element to a list / dictionary etc ) 
    If you do not assign an id, Inkscape will assign one automatically when the extension finishes running.

    element.attrib['id'] = element_id
    my_id_list.append(element_id)

    If you want to select items after creation without using ids there are several options:

    Please note it is not possible to pass back a 'selection' to the main Inkscape window

    for element in group:
        # output the id
        inkex.errormsg(element.get_id())
        # Output the element type
        inkex.errormsg(element.TAG)

        
    if you want to select elements by type, I usually use xpath

    def get_drawable_elements(parent):

        # Delete element types as you see fit.

        elements = parent.xpath('//svg:circle | //svg:ellipse | //svg:image | //svg:line| //svg:path |  //svg:polygon | '
                                  '//svg:polyline | //svg:rect | //svg:text | //svg:textPath | //svg:title | '
                                  '//svg:tspan | //svg:use')
        return elements

        
    groups etc into the function - https://www.w3schools.com/xml/xpath_syntax.asp

    Thats just an example, xpath has a lot of options.

    or you could loop through finding element.TAG of your choice etc.

    For creating the paths, I am not a mathematician

    However unless you want to use fractals - there are many types of modified random walks - https://demonstrations.wolfram.com/ConstrainedRandomWalk/

    I think that is how the original extension works. Python has a function, random.randrange(lower, upper) generally you would set upper and lower on a curve - fractions of 2 pi Radians.

  13. #13
    kt_inkscape kt_inkscape @kt_inkscape

    Hi, thanks for your thoughts, appreciated! Not sure I quite understand, passing back a "selection" to the main Inkscape window but continual reading is leading me to come to the conclusion that Inkscape is "just" an XML (SVG) parser. "just" obviously" doesn't do it justice, but I think it's helping me understand how to manipulate elements.

    Haven't touched XPath etc in quite some time, time to get back into it!

    I'll check out some of the random walk algorithms and be sure to let you know how it goes! Have a great day all.

  14. #14
    inklinea inklinea @inklinea⛰️
    *

    to correct an error the code I posted above should show .// instead of just //

    https://www.w3schools.com/xml/xpath_syntax.asp

  15. #15
    kt_inkscape kt_inkscape @kt_inkscape

    Hi all

    Thanks for your input. Currently looking at the L-system extension as seems to do what I need! Have a great day all

    Cheers Keith