Inkscape.org
Creating New Extensions I am unable to find help on inkex
  1. #1
    FrankI4466 FrankI4466 @FrankI4466
    *

    2 examples : 

    • for debug(what) there is a comment: Print debug message if debugging is switched on
      But how can i switch debug  on
    • in a line like 
      for node in self.svg.selection.filter(inkex.PathElement)
      i use filter but there is no informations on other filter. Is it possible to use something like not(pathElement) ? I want to modify all element that are not svg path lihe circle, line or polygon.
      Is there a way to find help on this. I'm going on (https://inkscape.gitlab.io/extensions/documentation/source/inkex.elements._selected.html#inkex.elements._selected.ElementList) and find this :
      filter(*types)[source]
      Filter selected elements of the given type, returns a new SelectedElements object
      But nothing about the type and no link.

    Is there a more functional way to find help.

     

  2. #2
    inklinea inklinea @inklinea⛰️

    I think you can just use the inkex element types so for example Inkex.Rectangle or Inkex.PathElement or Inkex.Circle

    The same types you would use to create an element.

    filtered_elements = self.svg.selection.filter(inkex.PathElement, inkex.Rectangle)
    
    for element in filtered_elements:
        inkex.errormsg(f'{element.TAG} : {element.get_id()}')
    return

    Or if you want a list you could use the tags:

    for element in selection_list:
        if element.TAG != 'rect' and element.TAG != 'circle' and element.TAG != 'text':
            inkex.errormsg(f'{element.TAG} : {element.get_id()}')

    Or just make a custom xpath list:

    drawable_elements = self.svg.xpath('//svg:circle | //svg:ellipse | //svg:image | //svg:line | //svg:path | '
                                                 '//svg:polygon | //svg:polyline | //svg:rect | //svg:svg | //svg:text | '
                                                 '//svg:use')

  3. #3
    FrankI4466 FrankI4466 @FrankI4466

    Thanks that's what I was looking for.


    But how can I find all filter types on my own. I don't wanna to ask at every time.

    And  how can i switch on debug .

     

     

  4. #4
    inklinea inklinea @inklinea⛰️
    *

    Each section in inkex.elements api reference should give you the correct type class.

    However for any object in python you can use this piece of code to return attributes etc:

    def get_attributes(self):

        attribute_string = ''
        for att in dir(self):
            try:
                attribute = (att, getattr(self, att))
                attribute_string = attribute_string + str(attribute) + '\n'
            except:
                None
                
        return attribute_string

    If you try for the inkex module: 
        
    attributes_string = get_attributes(inkex)

    then just get lines which contain 'elements._'

    for line in attributes_string.splitlines():
        if 'elements._'
    in line:
            inkex.errormsg(line)


    Gives:

    ('Anchor', <class 'inkex.elements._groups.Anchor'>)
    ('BaseElement', <class 'inkex.elements._base.BaseElement'>)
    ('Circle', <class 'inkex.elements._polygons.Circle'>)
    ('ClipPath', <class 'inkex.elements._groups.ClipPath'>)
    ('Defs', <class 'inkex.elements._meta.Defs'>)
    ('Desc', <class 'inkex.elements._meta.Desc'>)
    ('Ellipse', <class 'inkex.elements._polygons.Ellipse'>)
    ('Filter', <class 'inkex.elements._filters.Filter'>)
    ('FlowDiv', <class 'inkex.elements._text.FlowDiv'>)
    ('FlowPara', <class 'inkex.elements._text.FlowPara'>)
    ('FlowRegion', <class 'inkex.elements._text.FlowRegion'>)
    ('FlowRoot', <class 'inkex.elements._text.FlowRoot'>)
    ('FlowSpan', <class 'inkex.elements._text.FlowSpan'>)
    ('FontFace', <class 'inkex.elements._text.FontFace'>)
    ('ForeignObject', <class 'inkex.elements._meta.ForeignObject'>)
    ('Glyph', <class 'inkex.elements._text.Glyph'>)
    ('Gradient', <class 'inkex.elements._filters.Gradient'>)
    ('Grid', <class 'inkex.elements._meta.Grid'>)
    ('Group', <class 'inkex.elements._groups.Group'>)
    ('Guide', <class 'inkex.elements._meta.Guide'>)
    ('Image', <class 'inkex.elements._image.Image'>)
    ('Layer', <class 'inkex.elements._groups.Layer'>)
    ('Line', <class 'inkex.elements._polygons.Line'>)
    ('LinearGradient', <class 'inkex.elements._filters.LinearGradient'>)
    ('Marker', <class 'inkex.elements._groups.Marker'>)
    ('Mask', <class 'inkex.elements._groups.Mask'>)
    ('MeshGradient', <class 'inkex.elements._filters.MeshGradient'>)
    ('MeshPatch', <class 'inkex.elements._filters.MeshPatch'>)
    ('MeshRow', <class 'inkex.elements._filters.MeshRow'>)
    ('Metadata', <class 'inkex.elements._meta.Metadata'>)
    ('MissingGlyph', <class 'inkex.elements._text.MissingGlyph'>)
    ('NamedView', <class 'inkex.elements._meta.NamedView'>)
    ('Page', <class 'inkex.elements._meta.Page'>)
    ('PathEffect', <class 'inkex.elements._filters.PathEffect'>)
    ('PathElement', <class 'inkex.elements._polygons.PathElement'>)
    ('Pattern', <class 'inkex.elements._filters.Pattern'>)
    ('Polygon', <class 'inkex.elements._polygons.Polygon'>)
    ('Polyline', <class 'inkex.elements._polygons.Polyline'>)
    ('RadialGradient', <class 'inkex.elements._filters.RadialGradient'>)
    ('Rectangle', <class 'inkex.elements._polygons.Rectangle'>)
    ('SVGfont', <class 'inkex.elements._text.SVGfont'>)
    ('Script', <class 'inkex.elements._meta.Script'>)
    ('ShapeElement', <class 'inkex.elements._base.ShapeElement'>)
    ('Stop', <class 'inkex.elements._filters.Stop'>)
    ('StyleElement', <class 'inkex.elements._meta.StyleElement'>)
    ('SvgDocumentElement', <class 'inkex.elements._svg.SvgDocumentElement'>)
    ('Switch', <class 'inkex.elements._meta.Switch'>)
    ('Symbol', <class 'inkex.elements._use.Symbol'>)
    ('TextElement', <class 'inkex.elements._text.TextElement'>)
    ('TextPath', <class 'inkex.elements._text.TextPath'>)
    ('Title', <class 'inkex.elements._meta.Title'>)
    ('Tspan', <class 'inkex.elements._text.Tspan'>)
    ('Use', <class 'inkex.elements._use.Use'>)

  5. #5
    FrankI4466 FrankI4466 @FrankI4466

    Thank's a lot.

Inkscape Inkscape.org Inkscape Forum Creating New Extensions I am unable to find help on inkex