Inkscape.org
Creating New Extensions python delete path
  1. #1
    costycnc costycnc @costycnc

    I create a extension that make gcode ... from 0,0 i create a red line element with 

    line1 = inkex.etree.SubElement(self.current_layer, inkex.addNS('line','svg'), {'x1': '0', 'y1': '0', 'style': 'stroke-width:1;stroke:red', 'x2': x, 'y2': y} )     

    but need to delete this line when modify the document again...

    with         node.getparent().remove(node)  i can remove the line but only if line is selected because node is inside in

        for id, node in self.selected.iteritems():

    so is possible to call  self.iteritems(): or another function where return all elements ? not only selected elements?


                            

    Test
  2. #2
    costycnc costycnc @costycnc

    I resolve myself the problem :

            pathNodes = self.document.xpath('//svg:path',namespaces=inkex.NSS)
            for cPathNode in pathNodes:
                cPathNode.getparent().remove(cPathNode)

    Thanks alwais

  3. #3
    costycnc costycnc @costycnc

    but i dont know how remove only id node ... 

  4. #4
    Martin Owens Martin Owens @doctormo🌹🧀

    All this old style code is making me die a little inside. 😅

    In new 1.0 API style this would be:

    from inkex.elements import Line
    
    ...
    
    line1 = self.current_layer.add(Line(x1='0', y1= '0', x2=x, y2=y))
    line1.style = {'stroke-width': 1, 'stroke': 'red'}   
    
    for node in self.svg.xpath('//svg:path'):
        node.delete()
    
    ...