Inkscape.org
Creating New Extensions How to change child index of in myObject with python using extension ?
  1. #1
    blueDie blueDie @blueDie

    Hi.! 

    I want to change order of objects

    How can I change the order of objects?

    When I add an svg-size,100% height and 100% width, rectangle to an existing svg file, it covers them all.

    I want to send this rectangle object to the bottom.

    How can i do this ?

  2. #2
    inklinea inklinea @inklinea⛰️

     

    selection_list = self.svg.selected
    if len(selection_list) < 1:
        inkex.errormsg('nothing selected')
        return
    from inkex import Rectangle
    
    canvas_bbox = self.svg.get_page_bbox()
    
    background_rect = Rectangle()
    
    background_rect.set('x', canvas_bbox.left)
    background_rect.set('y', canvas_bbox.top)
    background_rect.set('width', canvas_bbox.width)
    background_rect.set('height', canvas_bbox.height)
    background_rect.set('fill', 'green')
    
    rendering_order_list = selection_list.rendering_order()
    
    inkex.errormsg(len(rendering_order_list))
    
    rendering_order_list[0].addprevious(background_rect)
  3. #3
    blueDie blueDie @blueDie

    hi inklinea,

    thanks for your codes.

    I tried your code, it works, but I need to select objects in your code.

    I should have written in the beginning, but I forgot to write it. I'm sorry, it's my fault.

    I want to do this without selecting it.

    I have many objects, groups and rectangle objects in my .svg document. I want to post all below of my rectantangle. So what I'm actually going to do is have a rectangular background.

    But as I wrote, there are too many different objects in svg. So many of my attempts have failed.

  4. #4
    inklinea inklinea @inklinea⛰️
    *

    In that case:

    For the svg - something as simple as:

    svg_children = self.svg.getchildren()
    svg_children[0].addprevious(background_rect)

    or for the current layer:

    current_layer_children = self.svg.get_current_layer().getchildren()
    if current_layer_children:
        current_layer_children[0].addprevious(background_rect)
    else:
        self.svg.get_current_layer().append(background_rect)

    You can use the [0].addprevious(background_rect) for an element list I suppose.

  5. #5
    blueDie blueDie @blueDie

    Thank you very much inklinea,

    The code you gave really helped me a lot.

    The extension now works exactly as I want it to.

    You are super hero , thanks again. 

Inkscape Inkscape.org Inkscape Forum Creating New Extensions How to change child index of in myObject with python using extension ?