Inkscape.org
Creating New Extensions export selected paths and add path effect to te
  1. #1
    dr_erk dr_erk @dr_erk
    *

    Hi!
    Im trying to export a selection of svg paths. The expoted svg is to be used with a laser cutter so i want to add a path effect offset to take the kerf into account.
    The problem is that i cant  bake in the path effect to  'd' .

    here is the code i have so far:

     

    # -*- coding: utf-8 -*-
    """
    Created on Fri Jan 20 20:56:49 2023
    
    @author: Erik
    """
    
    
    from inkex import EffectExtension, PathEffect, errormsg
    import inkex
    from lxml import etree
    import os
    from copy import deepcopy
    class OffsetAndExport(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 = 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))
                #p.pop('d')
    
    
            # Create a new SVG document
            new_svg = etree.Element('svg', nsmap=self.svg.nsmap)
            for element in self.svg.selection:
                if element.tag == inkex.addNS('path', 'svg'):
                    new_element = deepcopy(element)
                    new_svg.append(new_element)
    
    
            # Output the new SVG document
            output_svg = etree.tostring(new_svg, pretty_print=True, xml_declaration=True, encoding='UTF-8')
    
            #set  file name as the parent group id:
            file_name = element.getparent().get('id')
        
            with open(file_name + '.svg', 'wb') as f:
                f.write(output_svg)
                
    
    
    
    
    if __name__ == '__main__':
        OffsetAndExport().run()
    <?xml version="1.0" encoding="UTF-8"?>
    <inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
      <name>Export selected with offset</name>
      <id>org.inkscape.marquentry.Export_selected</id>
      <param name="offset" type="string" gui-text="Offset (kerf devided by two ):">name</param>
      <effect>
        <effects-menu>
          <submenu name="Marquetry"/>
        </effects-menu>
      </effect>
      <script>
        <command location="inx" interpreter="python">export_selected_paths_with_kerf_offset.py</command>
      </script>
    </inkscape-extension>
    

     

  2. #2
    inklinea inklinea @inklinea⛰️

    To bake in `Path Effects` needs a command call to `object-to-path`

  3. #3
    dr_erk dr_erk @dr_erk

    ok, thanks!

Inkscape Inkscape.org Inkscape Forum Creating New Extensions export selected paths and add path effect to te