Scott Hanselman

Creating exact 3D Models for 3D Printing with JavaScript and OpenJSCAD

February 01, 2015 Comment on this post [18] Posted in 3D Printing | Musings
Sponsored By

I have this 3D Printed Spool Holder on the top of my Printrbot Simple Metal 3D Printerl that looks like this:

Printrbot Simple Metal

It works great and fits my RioRand generic PLA Filament spool exactly. However, I went down to Fry's Electronics to get some filament today and all they had was small Makerbot spools. They were cheap, so I got two. When I got home I noticed that the hole in the spool is HUGE. It totally won't fit my spool holder.

This brings us to..

The Three Rules of 3D Printing

  1. All problems in 3D Printing can be solved by 3D Printing something
  2. The only things that 3D Printing people print is stuff to make their 3D printers work better.
  3. See rules 1 and 2.

So, I needed an adapter for my 3D Printer (which I have nearly a week of experience with, so fear me) and opened up Tinkercad.com to create it. Someone recommended Tinkercad as a great HTML5 website for doing quick designs.

image

I got lost in this app. I couldn't find a way to make two cylinders and simply center them within each other. You can nudge them around but can't center them against their own centers. I actually found forum posts going back to 2012 with members of the team saying "yes, we need that feature" but couldn't figure it out. It's a lovely app and my kids enjoy it but I feel like if you want absolute precision this may not be the place. Then I realized that perhaps this 3D Model was more of a math problem than a modeling problem.

Now I realize I'm biased, and I am a programmer, but with a small set of digital calipers and the excellent OpenJSCAD documentation I was able to create my adapter in just 10 minutes of hacking and just 7 to 12 lines of JavaScript (depending on how you count).

function main() {
return union(
difference(
cylinder({h: 40, r:26, center:true}),
cylinder({h: 40, r:15.5, center:true})
),
difference(
cylinder({start: [0,0,0], end: [0,0,24], r1: 52.5, r2: 26, fn: 50}).translate([0,0,-44]),
cylinder({start: [0,0,0], end: [0,0,24], r1: 32.5, r2: 15.5, fn: 50}).translate([0,0,-44])
)
).translate([0,0,45]);
}

From here I downloaded my STL (the 3D description of the object)...

OpenJSCAD

I then ran it through the Microsoft 3D Model Repair Service (a good idea to make sure all your designs are manifold and watertight).

Repetier

Then into Repetier and sliced into G-Code (instructions to the printer on how to move) and printed it with OctoPrint on my OctoPi.

image

I'm clearly not a 3D designer or modeler and I apparently don't have the patience for CAD tools that won't let me type in a direct number. I KNOW this should be 31mm in diameter, don't force me to use a mouse to "eyeball it." I was thoroughly impressed with the concept and execution of OpenJSCAD. Of course, OpenJSCAD is a JavaScript implementation of OpenSCAD, the "Programmers Solid 3D CAD Modeler" so I'll be exploring their software and amazing gallery as well! If you're creating anything with regularity that's more mechanical and less organic, OpenJSCAD or OpenSCAD is the way to go, clearly.


Sponsor: Big thanks to Amyuni for sponsoring the feed this week! Amyuni PDF Converter and Creator for .NET enables you to integrate powerful PDF functionality with just a few lines of code. Generate and process optimized PDFs with industry proven technology. Switch Now!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
February 01, 2015 15:30
You can align the centers of two objects in Tinkercad by selecting both, then using "Adjust" (top toolbar) / "Align" and then selecting the middle "node" for both X & Y axes. It'll move both objects to be middle-aligned. It took me a while to figure it out, but once you see it, it's pretty obvious :).
February 01, 2015 16:37
A more advanced free CAD application is FreeCAD:
http://www.freecadweb.org/

The CAD exchange format is STEP by the way. STL is just a primitive format.
February 02, 2015 0:04
I suggest you dig up a copy of AutoCAD. There's a reason it's dominated for like 30 years now.
February 02, 2015 0:15
This is my favorite feature of SketchUp - you can just draw something, then punch in the exact dimensions you want.
February 02, 2015 2:15
John - Doh!
Daniel - Thanks!
Bryan - I will! I was really good at it 20-25 years ago.
Andrew - Good advice, I'll check it out.
February 02, 2015 9:31
I use AutoCAD everyday at work, and it's great. There are edge cases where using something else makes sense.

Last year, I had a mobile printed at Shapeways for my niece and her parents. It consisted of four structures that were a union of 600 convex hulls of pairs of spheres. This was a way of building an arbitrary wireframe mesh. AutoCAD refused to do the union, but OpenSCAD soldiered through it.
February 02, 2015 12:47
Mr Hanselman,

I once answered a question ot one you blogs about whether to apply Xaml, SVG, and HTML5 and recommended all methods are best. I also provided a link to Off-Screen site at the time or as was suggested Off-Scream developing, which was good, but the idea has evolved over time, and thought you might find my presentation supporting your topic interesting, since you have quite the technology knowledge base, but I'm trying to look at a rather simple method of design as a World start-up standard based through named shapes.

The concept is being considered for 3D Printing as slide deck, where not complete deck needs to published for virtual web design but selected slides connected for publication. The algorithm is incredibly simple and can work with any technology. It is mind boggling somewhat because it might be a little 2 to the N but alas right now it's 360 radian to 255. Radian also have to be normalized to the exact point, if a requirement of 3D Printing.

The method is at the home page address, at Azure, sure wish Azure or BizSpark membership would provide me with carte blanch at Azure for continued experimenting, since I'm an out of pocket developer, but in any case, take a look at the method, if you would. If you would like to reach me for ideas about the concept and how it is evolving or feedback, I'd like to invite you or anyone who wants to take a look and will answer any questions about possible method evolution. The method is open technology, for anyone to learn.
Thank you, for the opportunity to write at your blog, respects for your work.
peterbisson@outlook.com


February 02, 2015 12:49
Thought home page link would show in blog. If interested in the above, plsase link to: http://inteckness.azurewebsites.net/
February 02, 2015 14:01
All this is fine and well... But if the reason you bought uncompatible filament was that you were out of filament... Wouldn't the adapter be hard to make? ;)
February 02, 2015 14:15
I am mechanical engineer.

AutoCAD is not good for 3D. A simple to learn but professional CAD software is Dassault Solidworks. When wanting to use Autodesk tools Inventor is the tool for 3D modelling.
February 02, 2015 22:05
Scott,
Thanks for all of your recent posts on 3D printing. My son and I have the exact same Printrbot model (heated bed on the way) and an unused Raspberry Pi sitting around and you were right, we've REALLY enjoyed Octoprint! We are having one recurring error though that has ruined a few prints. Did you ever experience a SerialException in Octoprint, and if so, how did you solve it?

Unexpected error while reading serial port: SerialException: 'device reports readiness to read but returned no data (device disconnected or multiple access on port?)' @ comm.py:_readline:987
February 03, 2015 13:55
Or you can find some more 3D models on this search engine http://www.yobi3d.com
February 03, 2015 22:07
I had the same reaction you did when trying to work with other CAD programs. "I'm I programmer, can't I just tell it where to put the piece and how big to make it?" And then I discovered OpenSCAD and have loved it. I've been designing (or replicating) small ship models and it has been working wonderfully. Here's a "family picture" of the models I've made to date. The large one is about 5 3/8 inches tall.

I love how you can design a piece, turn it into a function, then put it in a for() loop and make multiple copies looping over position and/or rotation. That's how I do the engines and some of the other features that are repeated on the models. It doesn't work for more organic type objects but for more mechanical type things, it is great.
February 07, 2015 6:30
That knob you made better go to 11 or it is against the law.
February 12, 2015 21:52
We solved all of our issues with stability with Octoprint (earlier question) by improving the power supply to the pi. Even though the brick I was using claimed to be 1500 milliamps, it couldn't keep up when the pi was being pushed. Heated bed kit required upgrading to ATX power supply which now powers pi, USB hub and printer. Plenty of power == rock-solid printing.
February 15, 2015 11:58
Loren - I saw that issue also and for me it was a bad USB cable. I swapped it out.
February 24, 2015 7:15
I had some Makerbot spools too and didn't like how they sat on this spool holder but then I realized I could hang them on the filament guide arm vertically. I might try making a remix too though, just for the practice. I'm one step behind you all the way :)
March 03, 2015 0:09
Scott,

Similar to OpenJSCAD, TinkerCad allows you build your own 3-D models using javascript that you can share with the community. You need to create a design, unhide the tool bar on the right, open the "Shape Generators", open "Your Shape Generators" and click on "New Shape Generator"

-Sev

Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.