SVG Import

Issue #179 resolved
Juan Pablo Caram repo owner created an issue

SVG -> Geometry -> SVG.

For export see #197.

Comments (32)

  1. Juan Pablo Caram reporter

    Try the feature in the development version by opening the shell and running:

    import_svg tests/svg/drawing.svg -outname mysvg
    

    The SVG file is included in the repository. It was created using Inkscape 0.48.4-3ubuntu2.

  2. Juan Pablo Caram reporter

    The error you are getting is because there was no support for units and your file was using something like "273mm" somewhere. I just added support for parsing the units, but to ignore them (5 minutes ago). For best results right now, make sure all your units are "px". In Inkscape, got to File -> Document Properties and set default units and those in "Custom size" to "px".

    "px" in SVG are known as "User units" and is equivalent to having no units. To use anything different we would have to specify a DPI quantity to relate pixels to absolute units. It's and SVG thing.

    Please play around with it now and tell me what you think.

  3. Marius Stanciu

    Yes, I had the document defined in a A4 size, in mm, as I find it useful in my applications.

    I tried again and it is working for linear shapes (triangle, star, square) but it is not showing an ellipse. "Unknown kind: ellipse" b.JPG

    But if I try to make a circle it will load nothing at all. c.JPG

  4. Juan Pablo Caram reporter

    Yes! No ellipse support yet!

    I can add that easily, but you are welcome to try it yourself. This is all in the file svgparse.py.

  5. Marius Stanciu

    Well, I do not have knowledge of object based programming (what programming I do is C for microcontrollers). But I will try :)

  6. Juan Pablo Caram reporter

    You don't have to write any code yourself. You can look up the specs for SVG ellipses and post a formula here on how to calculate the points.

    Or you can keep finding bugs! Any help is appreciated!

  7. Roberto Lo Giacco

    This feature would really save my day... looking forward to it and I can live without round rect 😈

  8. Roberto Lo Giacco

    :-( I'm a Windows user (yeah, I know....) and I don't know how to build the exe, I'm a Java/JS developer with some limited C/C++ knowledge (Arduino stuff)...

    Can you help me out?

    BTW, if Windows XP is still supported, I can report an error on that platform...

  9. Roberto Lo Giacco

    I've found the problem, it's the additional space at the end of the points sequence. I believe the Python function to trim a string is strip(), which I believe should be appended to line 349:

    for match in re.finditer(r'(\s*,\s*)|(\s+)', ptliststr):
    

    I belive should become

    for match in re.finditer(r'(\s*,\s*)|(\s+)', ptliststr.strip()):
    

    but I've no experience with python, so I'll let you decide if that's the correct way to do it ;)

  10. Piotr Curious

    SVG import seems broken for me. I am using recent git snapshot. svg_import.jpg here is an example. I've tried various svg's - generated by eagle, potrace and inkscape, and all of them do have problems.

  11. Juan Pablo Caram reporter

    @curious_pl , I understand that you did not get what you expected when you imported the SVG into FlatCAM, but it's not totally unexpected:

    • You are importing into a Geometry Object, which is just made of lines. So everything with a solid interior in the SVG is not going to "look" the same.
    • It seems you are interested in treating the SVG as a Gerber, i.e. a collection of solid areas. I suggest you try the shell command "import_svg" with the "-type gerber" option, which should import it into a Gerber Object instead.

    The SVG import feature may never be perfect since what you see on the screen in a program like Inkscape is the "rendered" version of the SVG. You may see a black/solid region on the screen, but it can be made of all sorts of garbage. Since it's all black, it looks as a single solid even though it is not. FlatCAM will correctly understand the lines, without their thickness, and the perimeters of polygons, circles and ellipses.

    I would be willing to reopen this issue, but there must be a clear consensus about what is broken and what is the expected behavior.

  12. Piotr Curious

    tried to import using -type gerber, and this produces error like that, and no import at all :

    "import_svg -gerber /home/curious/Desktop/obiekty3d/liquid/tests/nnn_190.svg"

    import_svg -type gerber /home/curious/Desktop/obiekty3d/liquid/tests/nnn_190.svg Object (gerber) created: nnn_190.svg Opened: /home/curious/Desktop/obiekty3d/liquid/tests/nnn_190.svg ERROR: list indices must be integers, not str Python traceback: <type 'exceptions.TypeError'> File "/home/curious/Desktop/flatcam/flatcam/tclCommands/TclCommand.py", line 373, in wait_signal > raise ex[0] File "/usr/lib64/python2.7/contextlib.py", line 24, in exit > self.gen.next() File "/home/curious/Desktop/flatcam/flatcam/tclCommands/TclCommand.py", line 404, in execute_wrapper > self.app.worker_task.emit({'fcn': self.execute_call, 'params': [args, unnamed_args]}) while executing "import_svg -type gerber /home/curious/Desktop/obiekty3d/liquid/tests/nnn_190.svg"

  13. Log in to comment