Inkscape.org
Creating New Extensions Moving objects between layers
  1. #1
    kyocobra kyocobra @kyocobra

    Howdy fam,

    In my Inkscape 1.0.1 extension, I am trying to create a new layer and move a few selected elements from self.svg.get_selected() onto this new layer.

    I've been browsing the inkex docs, but I haven't found anything on setting the active layer.

    Is it possible to move objects between layers?

  2. #2
    grillover grillover @grillover

    Each Layer can contain one or more objects. The final image is made up of all the (visible) Layers stacked on top of each other. Layers can be made visible or invisible, given an opacity, moved up or down relative to other Layers, locked, deleted, and named.

  3. #3
    Ellen Wasbø Ellen Wasbø @EllenWasbo

    I'm not sturdy in this, but I think this post could help you: https://inkscape.org/forums/extensions/how-to-add-an-element-to-etree-with-10/#c10476
    I try to challenge myself by answering such posts. Forgive me if I just confuse you.

    From what you say and the post I link to above, I guess you could create the new layer by

    newlayer=self.svg.add(Group.new('my_label', is_layer=True))

    and then add the selected paths by

    newlayer.append(self.svg.get_selected())

    Then I would guess the selected paths will be in both the current and the new layer. Seems like there is a remove method which I have not tried myself, yet and you can get the current layer so I would guess

    self.svg.get_current_layer().remove(self.svg.get_selected()) maybe....???.... or maybe it will bite its own tail here....

    To move to an existing layer you might be able to choose the layer to where you want to append by getElementById