Convert 2D SVG to 3D SCAD models
thingiverse
Edit I no longer use this tool as someone suggested a better solution: https://www.thingiverse.com/thing:25036 Introduction I'm working on a SCAD project that requires objects made from various Bezier curves. There are several solutions available, and this is just another one, but I like it, so I'm sharing it. The principle is simple: Draw your beautiful curves with a 2D tool like Inkscape to create an SVG file, Convert the Bezier path to a line path using Inkscape, Extract the 'path' elements from the SVG and generate SCAD code with path-to-scad.js, Include the generated file and use its modules in your 3D model. Installation This is straightforward: Install nodejs, Check that nodejs and npm commands are in your path after installation in a console, Uncompress the archive file in any directory, which gives you 2 files and a test directory, In this directory, type this command: npm update. First Execution Try it on a provided test: Run this command in the installation directory: nodejs path-to-scad.js -i test/sample-blobs.svg -o test/generated-blobs.scad You now have a file test/generated-blobs.scad that you can test by opening the file sample-path-to-scad.scad in your SCAD software (I use OpenSCAD). The script command line can be shown with this command: nodejs path-to-scad.js Prepare File with Inkscape There are some constraints in the SVG file. You can see one from the previous step because the SVG intentionally contains a 'path' that cannot be imported (the green blob called 'Cloud'). Actually, the script doesn't handle Bezier curves; they must be converted to straight lines using Inkscape: The script extracts paths, so you need to convert objects to paths, It's better to give a readable ID to the path in the object properties, This ID will be used to generate the associated module name, so don't use spaces or special characters, Select the path and enter node edit mode (F2), Select all path nodes (Ctrl+a), Use the command 'Make selected segments lines', If this breaks too many curves, use the command 'Insert new nodes into selected segments' one or multiple times before, Do this for all the shapes you want to export and then execute path-to-scad.js. Changes This section records different versions I uploaded: path-to-scad-v002.zip: New option --keep-pos to keep polygons positions as they are presented in SVG. By default, polygons are centered at [0,0]. path-to-scad-v003.zip: New option -v|--verbose for console logs, Changed option -w|--width to -c|--columns, New option -w|--watch to watch file changes and automatically regenerate, Removed linear_extrude in generated polygons to let the user choose between 2D and 3D results, Now uses bigdecimal for precision in relative computations, Fix: Now handle well subpaths for hollows, Fix: Svg 'm' command is relative to the start of the previous subpath, not the end. How I Designed This Why this script? Before making this script, I searched a bit what was available and found 2 main approaches to get Bezier curves in SCAD designs: Solution 1: SCAD Bezier generator Here's an example of this solution: Public Domain OpenScad Bezier Function This has 2 main drawbacks to me: The rendering takes ages, and you get this every time you reopen your work and generate, even if the Bezier curves didn't change, The positioning of control points is very hard; you make your changes step by step, one point after another. Solution 2: DXF import Another solution was the import of SVG files. This solution was better to me because the Bezier computation is made only once by Inkscape. But it has some drawbacks too: SCAD cannot import svg; you must convert them to DXF after a lot of manipulations that are error-prone (just look at this), Every time you render the SCAD software must read and interpret the DXF. Solution 3: Convert to SCAD code This is the solution I developed with this script Of course, it has drawbacks too: You must call a (very fast) script after every modification of the SVG, You must install nodejs (but this is so easy). But it has some advantages I needed: No time spent in waiting for the Bezier part of the rendering; the result polygons are statics, No complicated procedures to prepare the SVG before conversion, Easy designing of the curves allowed by the powerful Inkscape tool designed for this job, No time spent in import; the product of the generator is SCAD language.
With this file you will be able to print Convert 2D SVG to 3D SCAD models with your 3D printer. Click on the button and save the file on your computer to work, edit or customize your design. You can also find more 3D designs for printers on Convert 2D SVG to 3D SCAD models.