2D to 3D

A while ago I tried and failed to come up with an easy way to get text into OpenSCAD.  The difficulty lies in the fact that OpenSCAD doesn't have complete support for all DXF entities that most tools like autotrace and Inkscape output.  This past weekend I wanted to create a simple business card-like object for our hackerspace at Berks CoLab that I could print out and give to people.  At first, I was just going to re-design the logo in something else like Sketchup, when I stumbled on this page about other 2D formats in the OpenSCAD manual which suggests using Inkscape to first convert SVG files into EPS files and then using pstoedit to convert the EPS into a DXF that OpenSCAD can read. (woah alphabet soup overload)

Since I had already created the logo using Inkscape, the first thing I wanted to do was to separate out each part of the logo into individual files so that I could extrude the text and shapes in different ways.  The first thing you'll want to do is give each object in inkscape a recognizable name by right clicking on it and going to object properties like this:

You'll also want to remove any effects like stroke outlines.  I found this ended up causing the final dxf file to cause import problems in OpenSCAD.  Next, you'll want to do a File -> Save As and chose EPS, not DXF since Inkscape outputs DXF that OpenSCAD can't process.  When you save the EPS a window will come up that lets you limit export to the object with ID that you set in the last step.  You'll also want to make sure convert texts to paths and rasterize filter effects is checked on this screen:

Now you'll need pstoedit.  I'm on a mac and I use Mac Ports so all I had to do to install it is "sudo port install pstoedit" on the terminal.  Using pstoedit you can convert the EPS file into an OpenSCAD compatible DXF file using this command "pstoedit -dt -f dxf:-polyaslines in.eps out.dxf".  Here's the result, I use eDrawings to view DXF files on OSX:

Now you should be able to extrude the DXF in OpenSCAD.  One of the interesting things about cutting up a logo piece by piece like this is that the resulting DXF files import into OpenSCAD exactly where they should go.  In other words I exported the circle, the gear, and the words Berks and CoLab as separate objects and when I imported them into OpenSCAD - they all lined up exactly as they were laid out in the original SVG file.

Here's the code I used to extrude just the gear:

color([100/255, 190/255, 50/255]) {
  linear_extrude(
    file="gear.dxf",
    layer="0",
    height=5,
    scale=20,
    origin=[5.85,4.15]
  );
}

You'll have to play around with the scale and the origin to get it to be roughly the right size and centered correctly.

 

I posted all the files used to create the Berks CoLab name tag to thing:5517 or on github. The next thing I'd like to do is make a name tag using green, white, and black plastic as a multipart thing that snaps together like wulfdesign's thing. It should also be possible to write an Inkscape extension that shells out to pstoedit to let you save OpenSCAD compatible DXF files directly from Inkscape - better yet, someone else could do it, plz k thnx!

 

Just as I was writing this post, I realized my original attempt could now be accomplished with an extra step to create arbitrary text into a 3D printable STL from the command line like so:

convert -size 400x400 -background transparent -fill black -stroke black -gravity center -kerning -30 -font Helvetica-Bold caption:"Tony Buser" tmp.png

autotrace --output-file=tmp.eps tmp.png

pstoedit -dt -f dxf:-polyaslines tmp.eps tmp.dxf

/Applications/OpenSCAD.app/Contents/MacOS/OpenSCAD -m make -s tmp.stl tmp.scad

 

I turned it into a simple shell script you can find the code at thing:5518 or better yet on github.

 

Filed under  //   inkscape   makerbot   openscad   reprap  

Comments [9]

CloudSCAD

This is a little premature, but I wanted to share some progress I've made today on an idea I've been thinking about for a while now.  When I'm not hacking on 3D printers, my day job is web development so it's about time I start using my real skills for this stuff.  I call it CloudSCAD - it's OpenSCAD for the web.  It lets you write, share, mashup, and customize parametric 3D models using the OpenSCAD scripting language all within the browser and doesn't require anything to be installed locally.

As you can see in this screenshot, one of the cool things it does is parse the OpenSCAD script looking for parameters.  Then presents those variables in a friendly HTML form so that people can modify an object for their needs and click a button to download the customized STL file suitable for printing on a 3D printer.  They don't have to know anything about OpenSCAD, install anything, or touch a line of code.  Also, the author of the script doesn't have to do anything special - just put some well placed comments in their code.

What you can't see is the edit page.  I'm using Bespin to provide a syntax color coded editor for writing scripts.  I hope it will eventually include code completion and a few other things.  In some ways this is (or could be) even better than the editor in OpenSCAD itself.

There is a REST api.  For instance, you'd be able to download this script by going to http://cloudscad.com/scripts/1.scad and the stl output by going to http://cloudscad.com/scripts/1.stl and say you wanted the hole to be 8mm in diameter you could say http://cloudscad.com/scripts/1.stl?hole_diameter=8 Eventually you may even be able to say http://cloudscad.com/scripts/1.gcode, but I'm getting ahead of myself...

Like I said, this is pretty premature.  I've registered CloudSCAD.com but there's nothing there for you to see yet.  Everything you see in that screenshot and what I've described is finished, though.  Not too bad for one days work.  ;)

Filed under  //   makerbot   openscad   rails   reprap   ruby   rubyonrails  

Comments [22]

Dome Raising

EFFALO designed these nifty geodesic dome connectors.  Since you need a ton of these parts, they started a distributed manufacturing experiment to crowdsource the printing of a dome.  They're offering $2 per connector and whoever sends in the first usable part gets to pick a microfunding project to donate $20 to in your name.  I thought it would be pretty cool to make a personalized part to differentiate my contribution.  So since the connectors were already designed in OpenSCAD, it was pretty easy for me to add my OpenSCAD bitmap module and emboss my initials and my logo on top.  I released my mashup script so others could do the same with their initials.

I ended up being one of the first people to send some - I tied with someone else.  So I got to choose a project to donate $10.  I decided to send it to the OpenPCR project.  OpenPCR is working on making an open source Polymerase Chain Reaction machine for under $400.  Commercial machines cost $4,000 or more.  It could help do for biotech what MakerBot is doing for 3D printing.  I don't know if I'd ever make one myself, but I might just so I could feed it into an Open Gel Box and take pictures of my DNA in my basement.  HA!  How awesome is that?  There is a great video overview.

Filed under  //   makerbot   openpcr   openscad   programming  

Comments [1]

3D Text and OpenSCAD Bitmaps


Recently there was a challenge posted to the MakerBot Operators list to come up with a way to create 3D logos.  Some people discussed ways of taking an image and automatically turning it into a 3D design.  So I decided to take a break from Mendel production and started looking around for a way to do just that.  I found a cool utility called autotrace that can take a bitmap and convert it into a vector graphic format including DXF.  I thought cool, I could use the output and feed it into OpenSCAD which can extrude 2D DXF drawings into 3D shapes.  I could even automate it all on the command line by generating an image using ImageMagick and any true type font like so:

 

convert -size 400x400 -background transparent -fill black -stroke black -gravity center -kerning -30 -font Helvetica-Bold caption:'Tony Buser' foo.png

 

autotrace --output-file=foo.dxf foo.png

 

/Applications/OpenSCAD.app/Contents/MacOS/OpenSCAD -m make -s foo.stl foo.scad

 

Unfortunately, that didn't work out...

 

You see, OpenSCAD doesn't support just any old DXF file.  It only supports very simple DXF files and unfortunately the output from autotrace isn't simple enough.  So I could either add support to OpenSCAD for POLYLINE or change autotrace to output a different flavor of DXF.  I'm not really prepared to tackle either option... then someone mentioned making a set of simple block fonts in DXF that we could import into OpenSCAD.  That gave me the idea to try and implement a bitmap font system in OpenSCAD code itself.

I had never really used OpenSCAD much, but once I got over the limitations (like no string handling, inability to like ya know properly set the value of a variable, ugh) I came up with a pretty good bitmap module.  It works by passing an array of 1's and 0's and it generates cubes of a specific width and height in a grid pattern and then combines them into a single shape.  Then I went looking for a set of 8bit fonts and settled on the good old Atari font.  I probably should have wrote a program to generate the arrays from the image data... but I ended up encoding each character by hand.  I actually found it kind of relaxing to do while my MakerBot buzzed and whirred in the background.  Also kind of reminded me of making ascii art back in the BBS days.  Another cool thing is that I made it easy for anyone to create their own bitmap arrays and the arrays can be of any dimension.  The 8bit fonts are 8x8 matrixes, but you could make smoother fonts if you want at 16x16 or 64x64 cube "pixels".  (although bitmaps that large might make OpenSCAD choke, but theoretically there's no limit)  Someone even suggested a braille font set which would be really cool.

I've checked it all into github and you can also find it on Thingiverse as well as two examples showing how it can be used for a Parametric Name Tag and Parametric Alphabet Block.  It's been a "Featured Thing" on Thingiverse and has also been on the MakerBot Blog!

I have some ideas I'd like to work on such as:
  • a personalized parametric clip-on name tag for your MakerBot (clip onto the edge of the body of your bot)
  • "height maps" Instead of just 1's and 0's each bit in the array you could specify the height of the cube pixel.  Could also then write a script to convert a grayscale image into an array, like a terrain height map
  • a web service where you can type a message and have it spit out an STL file for you to print, maybe a web based bitmap editor 

But for now, I'm going back to printing RepRap Mendel parts...

Filed under  //   makerbot   openscad   programming  

Comments [1]