Inkscape.org
Creating New Extensions ungroup / remove from container
  1. #1
    RuaridhW RuaridhW @RuaridhW

    I have made an extension that does a bunch of stuff with symbols and their clones, but the final action i'd like to do is ungroup but i'm stumped.

    I'm happy finding the object element(s) and children, but am unable to workout how to remove them from the group/container in a single operation. Have tried monkeying about ElementTree copy/_setroot as well as with deepcopy and other such techniques but can't get them to work. e.g.

    ulnk_c_decendants = copy.deepcopy(unlinked_clone)
    ulnk_c_decendants[0].delete()
    self.svg.append(ulnk_c_decendants)

    So basically, does anyone know if there is a classmethod that would do this simply, like AddBeforeParent in XML?

    I'm surprised no one has asked this question before, which makes me feel like there is something obvious i'm missing. Else I'll have to dig into making a recursive, element by element copy method.

     

     

  2. #2
    inklinea inklinea @inklinea⛰️
    *

    Yes. 

    Nodes can only be in 1 place at once. 

    inkex uses etree. 

    addnext() addprevious()

    Perhaps this:

    If we have objects inside a group

    for child in my_group.getchildren():

    my_group.addnext(child)

    and finally.

    my_group.delete()

  3. #3
    RuaridhW RuaridhW @RuaridhW

    inklinea aren't you a star as well as appearing to be the main source of helpful advice on this forum, thank you.

    Thank you for that will give it a go!