Loading

Inkscape to OpenSCAD converter v7

by Neon22, published

Inkscape to OpenSCAD converter v7 by Neon22 Oct 11, 2015

Contents

Design Tools

Inkscape OpenSCAD

A part of these Groups

View All

License

GNU - GPL
Inkscape to OpenSCAD converter v7 by Neon22 is licensed under the GNU - GPL license.

Use This Project

Give a Shout Out

If you print this Thing and display it in public proudly give attribution by printing and displaying this tag.

Print Thing Tag

Thing Statistics

2506Views 1145Downloads Found in 3D Printing

Summary

A series of mods to Dan Newman's excellent paths2openscad program.
These include:

  • separating the paths themselves into variables so they can be used in other ways.
  • adding helper functions to enable them to be rescaled easily.
  • automatically saving unclosed lines as lines and not as joined up closed curves.
  • adding an option to save any closed curve as a line if desired.

For Inkscape 0.91 and above

Notes

Once you run the program. You'll get a .scad program with three main sections in it.

The first has the global variables. You can edit these directly to change the height and width of the resulting openSCAD file. There are also helper function sin there if you want to rescale the shapes to fit a desired size in openSCAD instead of relying on their apparent size (in mm) in Inkscape. (see at end).

profile_scale = 25.4/90; //made in inkscape in mm

// helper functions to determine the X,Y dimensions of the profiles
function min_x(shape_points) = min([ for (x = shape_points) min(x[0])]);
function max_x(shape_points) = max([ for (x = shape_points) max(x[0])]);
function min_y(shape_points) = min([ for (x = shape_points) min(x[1])]);
function max_y(shape_points) = max([ for (x = shape_points) max(x[1])]);

height = 5;
width = 0.20000000298;

Next will be a group of line definitions. These are named after the internal inkscape name for the thing. These may be well named or not - depends on how they were made.
Probably a whole pile of these. Here is one.

path4807_0_points = [[-5.845255,2.425518],[-3.310449,-0.509821],[-1.975026,-1.552367],[-0.578824,-2.215045],[0.889731,-2.425518],[2.442214,-2.111448],[4.090197,-1.200495],[5.845255,0.379678]];

module poly_path4807(h, w, res=4)  {
  scale([profile_scale, -profile_scale, 1])
  union()  {
    for (t = [0: len(path4807_0_points)-2]) {
      hull() {
        translate(path4807_0_points[t]) 
          cylinder(h=h, r=w/2, $fn=res);
        translate(path4807_0_points[t + 1]) 
          cylinder(h=h, r=w/2, $fn=res);
      }
    }
  }
}

Some will have NNNN_paths as well as NNNN_points variables. These are for more complex nested shapes like (say) the capital letter B.

Finally at the end will be a block where each of the shapes defined above is called, evaluated and turned into an object.
E.g.

// The shapes
poly_XDiv2(height, width);
poly_YDiv2(height, width);
poly_YDiv1(height, width);
poly_rect4809(height, width);
poly_YDiv3(height, width);
poly_path4702(height, width);
poly_path4736(height, width);

You can comment some of these lines out if you want to isolate some shapes.

Finally there are 4 helper functions which have been added in the first section. If you want to rescale the shapes to be a different scale you can use them to find the min and max, X or Y values, of the shape and rescale to a new size.
To do that you might create a line like this:

// Calculate the proper scale for an arbitrary drawn curve,
//  so that its profile height = wanted_height.
// where shape is the NNN_points variable.
new_scale = wanted_height / (max_y(shape) - min_y(shape));

Then do a scale(new_scale) {...} in openSCAD above the polygon. This will scale it to be wanted_height in Y.

More from 3D Printing

view more

All Apps

Upgrade this Thing with Thingiverse Apps

Tools and Utilities

Repair, slice, or enhance this Thing


Auto-magically prepare your 3D models for 3D printing. A cloud based 3D models Preparing and Healing solution for 3D Printing, MakePrintable provides features for model repairing, wall thickness...

App Info Launch App

I also keep getting a similar error as others in windows. Not sure what the issue is I tried both .91 and .92 versions.

Traceback (most recent call last):
File "paths2openscad.py", line 1005, in
e.affect()
File "C:\Program Files\Inkscape\share\extensions\inkex.py", line 283, in affect
self.effect()
File "paths2openscad.py", line 948, in effect
self.recursivelyTraverseSvg( [self.selected[id]], transform )
File "paths2openscad.py", line 861, in recursivelyTraverseSvg
inkex.errormsg( gettext.gettext( 'Warning: unable to draw bitmap images; ' +
NameError: global name 'gettext' is not defined

2 days ago - Modified 2 days ago
Neon22 - in reply to Athruz

ok so for some reason on your system its not finding gettext. Could be based on where you have it installed, or where you're running it from...
You could try commenting it out and not get the error message translated at all.
The gettext() is doing language translation and if you're ok with english maybe you don't need it.
e.g. just remove gettext.gettext( and its closing bracket ) from that line (or any line using gettext)

0.92 is out now and there was a change to internal dimensions. I need to post a new version.
its only the size that is off.
to get the right size you need to change one line in the resulting scad file:.

Change:
profile_scale = 25.4/90; //made in inkscape in mm

to:
profile_scale = 1;

Hi, I keep getting this error, can you shed some light please? Cheers

Traceback (most recent call last):
File "paths2openscad.py", line 1005, in
e.affect()
File "C:\Program Files\Inkscape\share\extensions\inkex.py", line 268, in affect
self.effect()
File "paths2openscad.py", line 948, in effect
self.recursivelyTraverseSvg( [self.selected[id]], transform )
File "paths2openscad.py", line 652, in recursivelyTraverseSvg
self.recursivelyTraverseSvg( node, matNew, v )
File "paths2openscad.py", line 861, in recursivelyTraverseSvg
inkex.errormsg( gettext.gettext( 'Warning: unable to draw bitmap images; ' +
NameError: global name 'gettext' is not defined

The gettext thing is part of the localisation. Is it possible you're not using inkscape 0.91 or 0.48?
(They are about to release 0.92 in a day or two)
Or it could be something to do with localisation which I just don't know much about sorry...

Apr 6, 2016 - Modified Apr 6, 2016

I am trying to use this app and whenever I push apply it says ""Paths to OpenSCAD" is working, please wait..." and then nothing else happens. How to I get my image to appear in OpenSCAD?

Thanks,

Timmy

Apr 6, 2016 - Modified May 30, 2016
Neon22 - in reply to InTimmydator

The extension should generate a file as shown in the UI - It is called profile.scad and its in your home directory by default.
Look for this file. Open it in openSCAD - Simple Double L click should work.

If the program does not seem to be doing anything then check:

  • if you have nothing selected then everything will be converted.
  • if you have a shape selected then only that shape will be converted (or group of shapes).
  • Try a small object first if you think maybe your real object is too big or complex and its taking forever.
    Let me know if this works.

Couldn't get V6 to work for me, but this version worked perfectly.
Thanks.

Windows 7
Inkscape 0.91
OpenSCAD Version 2015.03-2

Top