Inkscape.org
Creating New Extensions How can i create a path element?
  1. #1
    blueDie blueDie @blueDie

    Hi,

    Actually I'm using C#. and you know for example we write path b=new path() etc. to create an object in c#

    But i couldn't do this when i write an extension.

    How can i do this ? 

    Just i would like to create an path and add attribute or change its values etc...

     

  2. #2
    blueDie blueDie @blueDie

    i found this link

    https://wiki.inkscape.org/wiki/Generating_objects_from_extensions#A_simple_example

    am i right in road ?

  3. #3
    inklinea inklinea @inklinea⛰️

    It's a bit out of date.

    You can still use a dictionary to define the style or do it manually for each item. I've put an example of each below.

    import inkex
    from inkex import PathElement
    my_path = PathElement()
    
    # add one property to style
    my_path.style['stroke'] = 'blue'
    # update style from dictionary 
    my_style = {'fill': 'red', 'stroke-width': '2px'}
    my_path.style.update(my_style)
    # add path attribute
    my_path.set('d', 'M 10 15 50 75 40 175 z')
    # add path to current layer
    current_layer = self.svg.get_current_layer()
    current_layer.append(my_path)
  4. #4
    blueDie blueDie @blueDie

    Hi inklinea,

    I have created a solution as below.

    parent = self.svg.getElementById("myParentLayer")

    myPathElement=etree.SubElement(parent,inkex.addNS('path','svg'))

    of course i added myPath style,id,attribute etc.

    But your code

    from inkex import PathElement()

    my_path = PathElement()

    simple and looks better , really thank you