onsdag 4. mai 2011

Inkscape to OpenSCAD dxf tutorial



As some people are having problems with this, I present a small tutorial, as I believe I have found both an explanation and a solution. Inkscape is a wonderful program, and teamed up with OpenSCAD it makes a lot of cool stuff possible.

It works with Inkscape 0.47 and 0.48 without no extra plugins.

Update 2012.06.01 : Changed code on step 9 to use the preferred child import().
Update 2012.09.16 : Added information about "add nodes" on step 6.
Update 2012.10.09 : Added information about "flatten beziers" on step 6. Thanks to zeptomoon for the suggestion!

If you don't want to read my ramblings, the trick is easy: Make all the curved segments lines before you export to dxf.

Now, commence indepth tutorial:



1 First off, let's make a simple object, like this ellipse.

Note the square and round handles on the object, which indicates this is an .svg style object which you can modify according to the specific rules of said object.


2  This is of course no good, as OpenSCAD / dxf can't read this format. What we need to do is convert it to a path. [Shift+Ctrl+C]


3  Select the node tool [N], and notice how the handles on the object now look like gray squares. This indicates we now have a path.


Drag-select, or press [Ctrl+A] to select every node. With the nodes selected, notice how the handles changed again. The lines with spheres at the end tells us the segments between the nodes are curved. (Try fiddling with the points if you like).

This, again, is no good for the standard .dxf plugin in Inkscape, which only exports straight lines. (See point 8).


5  With every node selected, press the indicated button to "Make selected segment lines".

The lines with spheres on the handles are gone, so we now have only straight lines between the nodes. This would work, but doesn't look very smooth, does it? Undo your last action and continue to next point in the tutorial, where you learn to do it the right way. (Sorry about that).


6  With every node selected, initialize some mouseclicking action on the indicated button "Insert new nodes into selected segments".

This, well, inserts new nodes into selected segments, following the curve.

Press a few times if you want a smoother object, but don't overdo it now, you hear?

You could also use "Extensions - Modify Path - Add Nodes" for dense, even distribution of nodes all over complex parts.

Even better is to use "Extensions - Modify Path - Flatten Beziers", which will only add nodes at curved areas, resulting in less useless nodes. A value of 0.3 is a good value to start with. Thanks to zeptomoon for the suggestion!


7  Feel free to once more click "Make selected segment lines".

This looks much better. The lines are straight, but due to the sheer numbers, they simulate a curve! Victory!

You can of course select only part of the nodes, if you only want part of the model smooth.


Now save the file as "test.dxf". You will need to select "Desktop Cutting Plotter (R13)" in the type drop down box.

Notice the help tells us we can only export certain elements. What we have done now is create only lowpolylines, which exports beautifully.



9 Start up OpenSCAD and use the following code to open up the file. (You need to put the .scad and .dxf file in the same directory).
linear_extrude(height = 10) import("test.dxf");
There you go! Enjoy your Inkscape paths in OpenSCAD.



10  This works fine with any objects, advanced or not. Just remember to union the different paths.

Also note the part "Rap" is not just white text, it's a proper hole made with difference.

You can of course export several .dxf files and combine them in OpenSCAD if you need different height on some parts.

It can sometimes be difficult work with the .dxf file in OpenSCAD, as Inkscape exports the entire page, and it can be a bit tricky to locate where the object are. I recommend you select everything, go to Document Properties [Shift+Ctrl+D] and "Fit page to selection".  Edit: See below. The problem is a bit difficult to explain, but you'll understand it once you have experienced it.

Take care not to overwrite your original .svg file if you want to be able to edit things later. It's much easier to work with objects than paths.













Edit 16.09.2011: I have found it easier to align the objects to point 0x0 (the bottom left corner of the page in Inkscape) and not center the object in OpenSCAD. Then you can easily stack several .dxf files in different heights.



Now go forth and make something awesome! Remember to share your .svg files on thingiverse, to go with the .scad files!

I hope this helped, and clarified some things. If you have further questions or suggestions, feel free to comment.




-Nudel 

14 kommentarer:

  1. Thanks for the tutorial! I've been trying to figure that out for a while

    SvarSlett
  2. Glad to help! :) It's easy and fast to do, once you know how.

    I haven't tested how the stl files end up if you smooth the path in inkscape a whole lot before export. The mesh might very well end up bloated and take an awful long time to run through skeinforge.

    SvarSlett
  3. my imports are winding up as 'outlined' objects, not solid objects, in openscad

    SvarSlett
  4. @decora
    That happens if OpenSCAD can't figure out what part of the object is the inside and should be filled.

    If you try to export several objects from Inkscape, it often fixes itself if you select all the parts in Inkscape and use "Path - Union".

    It might happen if some lines intersects each other, which can be a bit harder to find and fix. It's best to avoid this by converting the object to a path as the last thing before export.

    If all else fails, export the objects one at a time and arrange them in OpenSCAD.

    SvarSlett
  5. Hi, many thanks for your tutorial. I tried it with an existing vector graphic I have here, opened it with Inkscape>union>saved again as dxf. But then I always get "WARNING: No top level geometry to render" Do you have any idea where I do something wrong ?

    SvarSlett
    Svar
    1. @Reoschu
      Glad to be of service! If you followed the tutorial and have a clean non-intersecting straight-lines-only path before you export to dxf, you should be good. But here's a few things to try:

      Make sure the .dxf and .scad is in the same folder.

      Try using the preferred "child import()" like this:
      linear_extrude(height=10) import("filename.dxf");

      I've updated the tutorial and removed the deprecated code.

      Slett
  6. Denne kommentaren har blitt fjernet av en bloggadministrator.

    SvarSlett
  7. Great, easy to follow tutorial here..

    I just tried it with Inkscape 0.48.4 r9939 & OpenSCAD 2013.06 but unfortunately I cannot seem to get and output in openSCAD,
    No matter how simple the object is I get the messages:
    WARNING: Duplicate vertices and/or intersecting lines found during DXF Tessellation.
    WARNING: Modify the polygon to be a Simple Polygon. Render is incomplete.
    And also you can only save as AutoCAD R14 dxf files,
    Any ideas?
    Thanks again ..

    SvarSlett
    Svar
    1. Thanks. Sorry about the late reply. Are you sure you made the object a single union path in inkscape? First make the objects paths, then use union (ctrl++).
      If you have issues with complex shapes, try a simple one first to make sure you got it right. Sometimes I have to modify certain vertices by hand in inkscape if they mess up somehow.
      You can mail me the inkscape file and I'll have a look at it if you want.

      Slett
  8. Everytime I try to compile and render it in OpenSCAD, it says;

    Saved backup file: C:/Users/BOOM-DESKTOP/Documents/OpenSCAD/backups/unsaved-backup-gqHp1376.scad
    Compiling design (CSG Tree generation)...
    WARNING: Ignoring unknown variable 'fanwidth'.
    Rendering Polygon Mesh using CGAL...
    PolySets in cache: 0
    PolySet cache size in bytes: 0
    CGAL Polyhedrons in cache: 3
    CGAL cache size in bytes: 0
    Total rendering time: 0 hours, 0 minutes, 0 seconds
    WARNING: No top level geometry to render

    HELP!

    SvarSlett
  9. Thank you so much! Much time fooling around with 3D design software when all I wanted to do was extrude 2D parts. Very much appreciated!

    SvarSlett
  10. wow really superb you had posted one nice piece of information through this. Definitely, it will be useful for many people. So please keep update like this.
    3D Laser Scanning Services in California

    SvarSlett
  11. This is most informative and also this post most user-friendly and super navigation to all posts.
    Plant Engineering services in Minnesota
    3d Laser Scanning Services in California

    SvarSlett