standard logo    Personal Education

laquo 3D Central



Importing SVG

Sometimes designing a complicated polygon is not worth the effort in OpenSCAD. It can be far more efficient to make the shape using another program. OpenSCAD (since version 2019.05) can import any shape you can create in a program like Inkscape.

Let's look at a reasonably simple example and take care of the biggest SVG "gotcha" at the same time.

I open up Inkscape (currently using version 1.1) and create a small square. I chose 96px by 96px to make a 1 inch square. When I save the SVG, I can start OpenSCAD (currently version 2021.01) and use the code import("square.svg", convexity=2); Here comes the gotcha. Clicking <F5> to get a preview may or may not reveal the imported square. The problem is that it's a small square and it imports to OpenSCAD based on exactly where we put the square in Inkscape. The default page size of Inkscape is European standard paper page size: A4. If we put the small square in the middle of the page, it will mean the square is not at the center of the OpenSCAD default view. We are effectively zoomed in too close. If we back out with the zoom out control, and there it is, about a hundred units right and 150 units up the x and y scales of OpenSCAD units.

That's not useful to us. A shape is easier to use in OpenSCAD if we can conveniently reposition it where we want it. Starting so many units away from the OpenSCAD origin makes that very difficult.

small centered square

Let's look closer at the problem.

First: Location matters
Inkscape uses the top-left corner as its origin (0,0).
But OpenSCAD expects the bottom-left corner, so we must deal with that.
In this simple pair of images, I've made a 96px square in Inkscape which has its origin at the typical top-left corner.
And, I've made the page just wide enough for the little square (while double its height).
Notice how the OpenSCAD puts it 25.4 units above the origin.
Inkscape origin
Second: The shape's corner may not be the best to be at OpenSCAD's corner
For a simple square, we might expect that putting the shape so it fits just at the bottom-left corner is best. After all the OpenSCAD native square fits that way.
Shift to OpenSCAD origin at OpenSCAD origin
Third: Easy repositioning
It is much easier to translate and rotate an object that "starts" centered, the object's center fixed originally at OpenSCAD's origin.
bridge the corner

Let's wrap up with a realistic example. You might create a complicated svg image like this one, based on the Free Software Foundation GNU logo.