ink2scad

A plugin for inkscape, which exports a path (or a set of paths) to openSCAD. You can then perform simple openSCAD transformations, such as linear_extrude, or use more powerful custom modules, such as the included 'extrude_along_edges' module, which lets you add decorative moldings around the edge of your extrusion. You can use the same module to cut around the edges, to make chamfers, or more decorative edge effects.

The logo above shows some letters exported from inkscape by ink2scad, and the the "2" has had a curve extruded around its edge. That curve was also exported from inkscape using ink2scad. The openSCAD code for the logo is just this :

include <ink2scad_tools.scad>
include <gen_logo.scad>

//Red
color( [0.8,0,0] ) {
    // The fancy molding around the "2"
    extrude_along_edges( two, convexity=6 ) { scale(1/5) ink2scad( edge ); }
    // The letters "scad"
    linear_extrude( 2.5, convexity=6 ) ink2scad( scad, relativeTo=two );
    // The letters 'ink'
    linear_extrude(0.01) ink2scad( ink, relativeTo=two );
}

// The main part of the "2"
linear_extrude( 2, convexity=10) ink2scad( two );

Installation

Download, unzip and place ink2scad.py and ink2scad.inx into inkscape's extensions folder. On linux this is : ~/.config/inkscape/extensions

You need to restart inkscape for it to see the new extension.

To use the accompanying openSCAD modules, copy 'ink2scad_tools.scad' from the zip file into openSCAD's library folder. On linux this is : ~/.local/share/OpenSCAD/libraries

Usage

Open inkscape, and draw an object. ink2scad can only understand simple paths, so if you want to export text, or a rounded rectangle etc, then you first need to convert it to a path using the menu : Path->Object to Path, or the keyboard shortcut Shift+Ctrl+C. When converting text to a path, inkscape makes an object for each letter, and groups them (it even creates a group when there's only one letter). Before using ink2scad ungroup the letters (Ctrl+U), and then combine all the letters into a single path (Ctrl+K).

Give each path a descriptive id, because the id is used as the openSCAD module name. Use Shift+Ctrl+O to edit the currently select object's id.

Select the path(s) you wish to export, and then use the menu : Extensions->Generate from Path->Ink 2 SCAD. If you wish to export everything, then you do not need to select anything.

Parameters

Output File

This is where the generated openSCAD code will be saved. Be careful, because inkscape remembers the last value you chose, so if you switch from one project to another, it will default to the same filename (and you could end up overwriting a file by mistake).

Smoothing

Curves are aproximated to lots of straight lines. This parameter determines how smooth to make the curves. A small value will be smooth, using many lines. A large value will be more angular, using with less lines.

Precision

How many decimal places of precision for each x,y value. If you need really accurate values, increase this value to 6, otherwise, leave it at the default of 3.

Using the Generated Code

Create a new openSCAD document, including the generated code. For example, to create a simple 3D extrusion, with a height of 10mm :

include <generated.scad>
linear_extrude( height=10, convexity=10 ) ink2scad( myshape );

In the example above 'myshape' is the data that was generated from the inkscape diagram.

'ink2scad( myshape )' creates a 2D polygon.

'linear_extrude' is a built-in openSCAD module which takes the 2D polygon, and turns it into a 3D extrusion.

Adding Decorative Moldings

It is easy to add moldings around the edges of your shape, with the help of the 'ink2scad_tools.scad' library.

Copy 'ink2scad_tools.scad' from the zip file into the same folder as your generated code, or into openSCAD's library folder.

In this example, we will add a circular molding around the base.

include <ink2scad_tools.scad>
include <generated.scad>

linear_extrude( height = 10, convexity=10 ) ink2scad( myshape );
extrude_along_edges( myshape ) circle( 1 );

The module 'extrude_along_edges' takes the generated data as its only parameter, and a 2D shape as a 'child'. In this example, the child is a circle, but it could be any 2D object, including a 2D shaped generated by ink2scad!

Outline Only

You can create a 3D outline, by extruding along the edges without extruding the shape itself. For example :

include <ink2scad_tools.scad>
include <generated.scad>

extrude_along_edges( myshape ) square( [1,3] );

This will create an outline of your shape 1mm wide and 3mm high. You can use any 2D shape instead of the square.

Chamfers

In this example, we will chamfer 1mm from the top.

difference() {
    linear_extrude( height=3, convexity=10 ) ink2scad( myshape );
    translate( [0,0,3] ) extrude_along_edges( myshape ) {
        rotate(45) square( sqrt(2), center=true );
    }
}

Use 'linear_extrude' to create the 3D object of 'myshape' 3mm high.

The combination of 'extrude_along_edges' with a square rotate by 45 degrees creates a 45 degree chamfer. The length of the square's edges is sqrt(2), gives a height and depth of 1mm to the chamfer.

Render Speed

When cutting a chamfer from the top/bottom of an extruded shape, openSCAD's preview mode can get very slow.

There are a few solutions :

1) Use "rough" chamfers most of the time, and turn off the roughtness when doing the final rendering. To make a single chamfer rough, set 'extrude_along_edges's 'rough' parameter to true. To make all chamfers rough, set the global variable 'INK2SCAD_ROUGH=true'.

This speeds things up a lot, because it doesn't do an expensive 'intersection', which is really expensive when combined with 'difference' to form a chamfer.

The down side : Internal corners of chamfers and exterior corners of moldings will be rendered incorrectly when using 'rough'.

2) Turn off the chamfers and moldings most of the time, and only turn them back on when testing the chamfers/moldings and when doing the final render.

To turn off a single chamfer/moldings, set 'extrude_along_edges's 'render' parameter to false. To turn off all chamfers/moldings, set the global variable 'INK2SCAD_EXTRUDE_ALONG_EDGES' to false.

3) Use 'render() { }' around some, or all of your code. This will cause the preview to render slowly at first, but once it has rendered, scrolling and rotating will be fast. You will lose some features only availabe in preview mode (such as '#' to highlight parts of your model).