Convert DXF to SVG in Inkscape CLI while keeping layers

坚强是说给别人听的谎言 提交于 2019-12-10 09:39:58

问题


In the Inkscape GUI, there is this awesome feature, that lets me 'save as -> file type -> layers as individual SVGs' (the last one at the bottom). Is there any way of doing the same thing from the CLI?

What I have so far:

inkscape -z -l output.svg input.dxf

This converts the 'input.dxf' to 'output.svg', but I can't find the layers within this SVG.


回答1:


With help of the Inkscape community (special thanks to @rindolf), I could come up with a solution.

Prerequisites

  • Python 2.7 (It won't work on newer versions)
  • lxml ("pip install lxml")

Adjust Inkscape

Change 'GROUP = "{http://www.w3.org/2000/svg}g"' on line 36 of "tar_layers.py" in "Inkscape\share\extensions" to 'GROUP = "g"'. This has to be done, because your layers won't have that namespace.

Convert the DXF to multiple SVGs (one per layer)

  1. Create an Inkscape SVG from the DXF:

    python share/extensions/dxf_input.py input.dxf > output.svg

  2. Export the layers as individual SVGs inside a tar:

    python share/extensions/tar_layers.py output.svg > output.tar

Now, you should have a 'output.tar' file with Inkscape SVGs inside of it. If you need regular SVG, you have to export them like this:

inkscape -z -l output.svg input.svg

More information about the Inkscape CLI.



来源:https://stackoverflow.com/questions/36719846/convert-dxf-to-svg-in-inkscape-cli-while-keeping-layers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!