Inkscape.org
Creating New Extensions Live Path Effect in extension
  1. #1
    dr_erk dr_erk @dr_erk

    I'm trying to make use off the LPE offset in the extension below, but it  does not work. The effect onley shows if I manualy change some path effect parameter either in the xml-editor or in the path effect menu. Am I missing something?

    Or is there an easier way to make an offset without distortion on multiple paths?

    from inkex import EffectExtension, PathEffect
    
    class OffsetMultiple(EffectExtension):
        def add_arguments(self, pars):
            pars.add_argument("--offset", type=str)
        def effect(self):
            paths_element= []
            for element in self.svg.selection:
                if element.TAG == 'path':
                    paths_element.append(element)
            
            if not paths_element:
                errormsg("Please select at least one path" )
    
            #offset is a parameter from the extension ui.
            offset = self.options.offset
            offset_param_dict = {"update_on_knot_move": "true", 
                                      "attempt_force_join": "false", 
                                      "miter_limit": "4", 
                                      "offset": offset, 
                                      "unit": "mm",
                                      "linejoin_type": "round",
                                      "lpeversion": "1.2",
                                      "is_visible": "true",
                                      "effect": "offset"}
    
            for p in paths_element:
                effect = PathEffect()
                for key in offset_param_dict:
                    effect.set(key, offset_param_dict[key])          
    
                self.svg.defs.add(effect)
                p.set('inkscape:original-d', p.attrib["d"])
                p.set('inkscape:path-effect', effect.get_id(as_url = 1))    
    
    
    if __name__ == '__main__':
        OffsetMultiple().run()


                
    Br Erik

  2. #2
    Kaalleen Kaalleen @Kaalleen

    If you only want to apply the lpe, you are almost there. But you will need to remove the path itself from the element (it will be updated automatically afterwards).

    After setting the path effect url at the end of your code write p.pop('d')

  3. #3
    dr_erk dr_erk @dr_erk

    Thank you!

  4. #4
    rickyrlr rickyrlr @rickyrlr

    Thanks for posting this example. It is exactly what I was looking for.

    I'm getting an incorrect (larger) offset than I should as a result. If I "jiggle" the path afterwards, it recalculates and the correct offset is applied. The path effect options are correct when I look at them before and after moving the path. The 'd' attribute in the xml recalculates when I "jiggle" the path.

    I'm using Inkscape 1.2.2

    Any help would be appreciated.