Mar 15, 2017

BlocksCAD 104: 3D Modeling a Multi-compartment Box with Code

BlocksCAD combines two of my favorite things: Coding and 3D Modeling. I've written about BlocksCAD before - to show the basics of how code can be used to produce 3D Models - and more recently I found a real world use for this tool that I just had to share.
Note: This is basically the 4th in a series of posts about modeling with BlocksCAD. The first is here.


A while back I created a small "Battery Holder Box" - which was specifically designed to hold one type of button battery - the CR2032. This small battery has specific dimensions, so my 3D Model was made to fit that specific battery. I made a single model with specially sized compartments to hold 10 of these batteries.

About a week later, I needed another similar box to hold LR44 batteries, which are slightly different dimensions than the first - so I went through the painstaking process of reproducing the battery box to those dimensions.

Then a few weeks after that, I wanted a similar box to hold SD cards - and again, I grimaced while I considered repeating all the steps to create a specially sized box to hold a dozen SD cards. Then it struck me - I can CODE THIS!

The Power of BlocksCAD

As a software engineer, I'm trained to recognize patterns like this - and it's exciting when a pattern as obvious as the above can be turned into code. That's what BlocksCAD lets me do! Using code to produce storage boxes like this, I can use parameters (variables) to change the measurements in my code, and within seconds, have practically ANY size compartment and box configuration!

How I Made AnyBox - an overview

I'm going to give you just the basics here - I won't describe every line of code (or, in this case block of code).

I start by creating ONE compartment. It's basically a hollowed out rectangle meant to hold something - a box. From there, I simply make a bunch of those compartments by repeating the same code as many times as necessary. I do this in two dimensions - so I can have, for example, 3 across and 4 down, or 1 across and 3 down - similar to what a book case might look like. Once the boxes are done, I create a TOP - with the exact configuration of n across and m down as the boxes, but with a more flat extrusion vertically.

That's the high level story - below is the detail...

Making the First Box

I start by creating ONE box, one compartment - using 3 variables - the width (X), the length (Y) and the height (Z). These measurements are the measurements of the INSIDE of the compartment that I wanted. So I basically measure the dimensions of the object I'm trying to hold in the box, and use those for X, Y and Z.

The "CUBE" block in BlocksCAD easily produces the cube with those dimensions. But I don't actually want a solid cube, I want a hollow cube.  To achieve a hollow cube, I have to use the TRANSFORM / MINUS block to subtract this cube from a slightly larger cube.

To decide how much larger that outer cube should be, I have another variable which holds the "Wall Thickness" (let's call that W here) of the box I want - and I add that to the original X, Y and Z dimensions to get the outer cube dimensions. Now the outer box can be defined as X+W, Y+W, Z+W.

Watch The Box Multiply

Now that I have ONE compartment successfully made, I can repeat the creation to make an array of boxes connected to each other to get the "cubby" look I'm aiming for. Remember the original reason for this was to hold several of the same item - button batteries in my case.

One of the great things about programming is that once you figure out how to do something, you can re-use the code to do it again. So in this case, now that I know how to make a box in the dimensions I want, I can just repeat the code to do it again. All I have to do is start the second box just next to the first, and then again, start the third box, just next to the second, etc.

I do this with a LOOP (in coding, it is also called "iteration") to simply repeat the running of that box-creation code over and over again, as many times as the number of boxes I want. Since I want the option to have multi-dimensional cubbies - I also need a second loop around that first loop to repeat that whole set of boxes again, making another set of n boxes next to the first set of n boxes.

This is a very common pattern in coding whenever you are dealing with any sort of array - in this case it happens to be the physical creation of a multi-dimensional array object.

Making The Box Top

Before worrying about the complicated box top needed to cover this multi-box configuration I've now created, I need to make a TOP for that ONE compartment first. To do this, I'll use the same X, Y measurements from earlier - but I really don't need the Z, as the top will be mostly a flat top with minimal depth.

I start by creating a simple rectangle which is the same dimensions as the outer dimensions of the box - that is X+W by Y+W - which accounts for the width of the box walls again. Now, instead of hollowing out, like we did for the box, this time we want to create a slightly raised, slightly smaller panel which fits snugly inside the top of the box to hold the top on. This is done by creating another rectangle on top of the first which does NOT include the wall thickness, but just the inside dimensions X and Y.

Now that we have one box compartment, we simply do the same thing we did with the box, and use a double loop to create the same number of tops connected to each other as we the box had.

Practical Addition From Testing

Along the way, of course I tested the creation of the single box, then multiple boxes in one row, then multiple boxes in an array of 2 x 3 and larger. The box was working quite well! But once I actually put objects in the box, button batteries in my case, I found a slight problem. There was no great way to get the objects OUT of the box! I had to turn over the box to get one object out, which of course dumped all the objects out.

To solve this, I added one small feature - or should I say, I subtracted something. I created a small circular hole at the bottom of each compartment  (by subtracting a centered cylinder from the base of each box) - which can be used to push objects out of their compartment when needed (using a paperclip or other small pointy object). This worked just fine!

The Missing Steps Have The Real Learning

Like with all great projects, the description above doesn't really tell the whole story. There are many details left out. I don't do this to torture you, but rather because I can't remember all the smaller tweaks and adjustments I had to make to make this project work - AND, because that is where all the learning is! If I gave you every detail, you'd learn much less than if you had to figure out some of the stuff yourself.

Chances are, in doing this project yourself, you'll discover a completely new way to do this project or perhaps invent some other cool object I didn't think about!

NOTE: this is the FOURTH in a 4-part series on making models with BlocksCAD code.
Part-1 - Making 3D Models with Code Blocks (aka Intro to BlocksCAD)
Part 2 - BlocksCAD 102 - Coding a #3D Box that Grows

Jan 8, 2017

The NewMatter Mod-T 3D Printer - reviewed and liked!

I'm not the fastest to review things - and this one is no exception. It's been about 18 months since I first saw this Mod-T printer from NewMatter - and I finally got to use it and review it a few months ago. Well, It took me even longer to mention it on my blog - but here it is!

Watch the video - or I've posted the text version below it...

I’m always looking for great 3D Printers - at reasonable prices for practically anyone - but especially for educators. The NewMatter Mod-t 3D Printer is a great find in this quest.
I first saw this printer at the NYC makerfaire in 2015, and even back then, just the look and elegance of the printer’s industrial design stopped me in my tracks. Almost a year later, I finally got to test one out for myself. The bottom line is that I like this printer and would definitely recommend it especially for people with a budget under $500.

The unboxing was a pleasant experience - a well-protected printer body, which required almost no assembly, and a well-organized set of well-labeled boxes for the minor parts that had to be assembled and the tools which come with the device.

The clear instructions direct you to their online site to get fully set up - where I had to create an account to continue. While slightly annoying, it was reasonable and worthwhile given the pleasant experience that followed. The newMatter software for set up is not web-based, it runs on windows and Mac - but was easy to get installed. After setup of the software, I was instructed to “download firmware updates” - which went smoothly.

Connecting the printer to my home wifi was mostly easy - but 5Ghz networks were not recognized so you need a 2.4 Ghz network to get up and running. There were some small bumps getting through the complete printer connection process - but within a few minutes I got through that and realized with delight that I would be able to control my printer now from a web interface, which gave super clear instructions on how to finish the printer setup. The site also has simple button controls to do things like load the filament and see the status of the printer. I mounted the light blue 1.75mm PLA filament which came with the printer onto the plastic spool holder which connects to the back of the printer, and loaded it into the hole clearly marked “filament” in the back. Then, I used the web-based printer controls to get the filament fully loaded.

My first print was something simple and small - I picked my simple pegboard hook that I know only takes about 10 minutes to print. Once I figured out how to upload my own models - which wasn’t as clear as I would have liked - but has become easier in latest updates - I uploaded my model and used the clear online controls to setup the parameters for printing. It was set a bit hot - 210C - so I lowered it to 185C and started it up.

There aren’t quite as many printing options as something like Cura for printers which require GCode to be directly loaded - but that’s the whole point of the Mod-T - to make printing simple. So the advanced options are somewhat out of the way intentionally. While there were some general usability issues with the online printing interface, practically all my main concerns have already been addressed - and while it is simple and not for the advanced 3D printing professional, it is easy to use.

At the start of the print, there was certainly lots of print bed movement - which is clearly a process to home the print bed and perhaps auto-level it - but this was not excessive - and after the printer extruded a line of filament on the side of the bed to prep for printing, my object began to print.

The fan of this printer is quite loud without the cover on, but once the cover is on, the printer is pretty quiet - so I can see how that makes it more friendly than other printers which have no enclosure.

I was very pleased with the way the model adheres to this print bed - which is clearly made of a special material which is intended to be good for this purpose. This is becoming more common in printers - and with the dozen prints I did, I had no problems with models adhering to the bed - and used no additional materials like hairspray. Note that I ONLY USED PLA - I did not attempt ABS.

The subsequent tests I did included one of my favorites - a single-print hinge. This model has a bunch of one-half millimeter gaps between parts that are intended to move freely - and you can see in the video that it printed rather well and just required a bit of forcing to freely move the hinge - almost exactly the same amount as that required when this model is printed on a printer which is literally 4 times the price of this one. I was very happy with the results here.

I also printed a few other models including a thin-walled desk organizer in the shape of my initials - which has lots of curves  - and it came out quite smooth - a great result on the first try.

While the Mod-T has a very innovative mechanical design for the bed movement, which completely avoids belts and allows the bed to easily be removed and replaced - it is not necessarily space efficient. The footprint is approximately 15 inches square with the filament spool and 13.5 inches tall. The build envelope is 6 x 4 x 5 inches - 120 cubic inches - which is pretty good for most hobby projects.

I’m not thrilled with the process of changing filament color - but that’s pretty much par for the course for most 3D printers. I’m spoiled by the ease of filament changes in the Polar3D printer.

Overall, the Mod-T seems like an incredible value for an elegant, easy to use 3D printer. While no 3D printer these days is a completely user-friendly appliance - the Mod-T comes closer than many I’ve tried and it’s elegant external design could be on display in your home or even the museum of modern art. At $399, it’s definitely one of my top recommendations for printers under $500 - and while I haven’t used it long enough to call it reliable, I would say that I’ve had no clogs, no failed prints due to adherence to the bed and generally no issues with the software.

Yet Another 3D Printed Phone Stand

I got tired of laying my phone down next to my computer - so I wanted a simple phone stand that would stand my phone upright or sideways so I could see it and use it. Of course there are likely cheap phone stands or 3D Models that would suit my purpose somewhere - but I had two reasons why I "needed" to make my own:

First, I wanted it to suit my needs and fit my phone exactly.

Second, I like to make stuff - so why pass up the opportunity to invent something new!?

Design Requirements

The basic requirement of this design was to firmly hold my phone upright without tipping over. But there were other things I had to consider in this design. Here's the full list:
  • Hold phone upright (portrait) without tipping and with firmness that let me tap the screen.
  • Hold phone in sideways (landscape) too. (hopeful on this one)
  • Have a slight angle so it is easy to see on my desk.
  • Nothing should block ANY of the screen.
  • Simple & Fast to print - no supports, flat bottom surface to grip print bed, minimal mass.
  • Able to hold phones approximately the size of my Nexus 6P with or without a case.
Things I decided not to worry about for this first design included a way to dock the phone on the charging cable or making the stand portable to fit in my pocket. As with any product, sometimes it's just as important to pick things you're NOT trying to solve as it is to pick those problems you ARE trying to solve.

The 3D Model

This one was not as simple as it looks. The requirements I had to be simple and low mass made it more of a challenge - otherwise, I could have simply used a big block (as I've seen in many other phone holders).

I started with a block. I imagined the shape I wanted to be more like a wedge, holding the phone on the front, then angled back to the bottom surface.

To get the right shape of the front which would hold the phone, I created a 3D Model of my phone - not to be printed, but to be used as a shape to SUBTRACT from the wedge block to leave behind a perfectly shaped area to hold my phone. I then subtracted a large chunk of the block from the angled front for the area where the phone screen would be seen, leaving about 5mm on each side, about 3mm thick, to hold the phone in place by the edges.

Now, as with any subtraction operation like this, the fit would be too tight if I just printed it as is - so I pushed out the insides of the phone holding area by 0.5mm on each side, and the back by 1mm.

Landscape works too!
To reduce the mass of the wedge, I wanted to cut out a large part of the back - so I made a copy of the whole wedge, and scaled it down to be a subtraction shape. I made it smaller by about 5-8 mm on each side and the part behind the phone, and then subtracted it from the back of the wedge - leaving the back of the wedge with no material at all.

The shape I got was pretty much what I imagined! I finished it up by softening all the edges with a "Filet" operation (in Autodesk 123D) and gave it a first print.

Making it more useful

Landscape is great for video watching

I measured the space for my phone with the case - so the space for the phone was actually bigger than the phone itself by a few mm on each side.

The first print actually worked well with the phone that had the case on it, as it was a tight enough fit to really hold the phone firmly. But when I removed the case from the phone, the fit was so loose, that the weight of the phone leaning against the back of the stand let the stand slide up the phone and pop off the top.

I needed to create some friction or pressure for phones without cases - I had no intention of making a new stand for every phone or for phones without cases.

I decided to try a flexible "bow" in the back - just a very thin (1mm) printed flat strap, which would be stuck into two small holes into the inside of the phone holding area - creating pressure against the back of the phone and holding in in place when there was no case on it.
This worked!

The Model is published HERE.