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()
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:
To bake in `Path Effects` needs a command call to `object-to-path`
ok, thanks!