I recently had to print about 30 unique items with a similar geometry but with different detailing. They were all an awkward shape to print – there was no way of aligning them so that there were no overhangs. I found a way of batch processing them to get them all ready for printing.
To make them slice and print correctly I decided to print each one in two parts and then glue together. The operation I wanted to do looked like this:
I made a simple OpenSCAD script to import the stl and do the necessary cuts and rotations (download here). However running the file 30 times seemed a lot like hard work so I found this handy link which explained how to use OpenSCAD from the command line. You can tell OpenSCAD to generate an stl using a particular OpenSCAD script and save it with a particular name. For the example file I uploaded
openscad.com -o output_file_name.stl -D param1=\"input_file_name.stl\" OpenSCAD_Chopper.scad
typed from the windows command line would create the chopped output in “
param1” is the poorly chosen name of the input file name in the OpenSCAD script.
There were a couple of tweaks I had to make to make this work in windows. First of all I had to add OpenSCAD to the windows PATH environment variable so that it would find openscad.com when typed as a command. Before I started messing with the Raspberry Pi for BeerBot I would have had no clue what all that means, but fortunately the struggles with learning Linux have caused at least some things to sink into my brain. All it means is that you need to tell windows that before it tells the user “I can’t find this command you are giving me” it should first of all search through all the directories included in the PATH variable to see if it can be found. This webpage provides a good description of how to change the PATH variable in windows. For me I just had to add “
C:\Program Files\OpenSCAD” which is the directory where I have installed OpenSCAD.
The other tweak I had to make was with the escape characters for the input file name. This almost drove me nuts. Even trying to replicate it just now a few weeks after trying this the first time confused me again. The OpenSCAD user manual uses single quotes to escape the double quote character so it is properly passed through to OpenSCAD and not interpreted as a quote by the shell, i.e.
However from the windows command line this will cause an error. I eventually worked out that you need to do
i.e. no single quotes and escape the double quotes with backslashes. This link helped.
Once I’d worked out how to do this stuff from the command prompt I just needed a batch file to run the command on every file I wanted it to. I’d never created a batch file like this before so I relied heavily on this guide which explains how to make a batch file that will step through text in a .txt file and run a command using the parameters on each line. I only had one parameter (the name of the file). My batch file looks like is this:
echo "Goes through a list of files and runs an OpenSCAD script on each one"
FOR /F %%G IN (FileList.txt) DO openscad.com -o FIX_%%G -D param1=\"%%G\" OpenSCAD_Chopper.scad
I put the list of files I want to process in a separate file in the same directory called FileList.txt and then just run the batch file.
There was a lot of wailing and gnashing of teeth while doing this though, as I discovered that many of the stl files had errors that caused OpenSCAD to reject them. Usually all I do in this case is heal it with Netfabb desktop version, but there were some files that still wouldn’t process even after NetFabb said they were OK. I found this thread which showed that I’m not the first person to see this problem but there was no solution mentioned. I tried everything and was about to give up when I tried opening and saving with 123D Print. This is Autodesk’s print utility which comes bundled which Meshmixer. This fixed it. I have been unimpressed with Autodesk’s stuff before – 123D Design was really slow when I tried it – however Meshmixer and 123D Print seem decent.
What I learned this time
- Batch files are very powerful, I’m sure I will use this trick a lot
- I should write stuff up sooner – I’ve been on holiday since I made the batch file and I could barely remember how I did all this stuff
Random blog related stuff
Because I’ve been on holiday I have a lot of photos that other people claim to want to see. The problem always is that when I try to email photos they are always too big and they need to be adjusted in size before I can send them, which is a pain. Sometimes I even end up saving the reduced resolution version over the top of the original. I found a nice utility called Robosizer which helps with this by automatically detecting when you are trying to upload an image and resizing the version sent to the website. It seems to work for wordpress too which gets around the problem I have with uploading images bigger than 1.5 Mb.