Categories
Uncategorized

OpenSCAD Improvements

Trying to improve my own code to make things easier, cleaner, and more easily explainable…

When writing code for yourself you can choose to leave it messy and confusing (though you may not want to) and when writing code that other people will see it may be a good idea to attempt to be clear and organized. I’m trying to be more clear an organized. Which you know, can help your Future Self as well.

Here’s a recent project. It’s a 3D model of a simple foot switch. There are two 3D printed parts (a base and a cover) and one non-printed part (a push button) and sometimes I want to see one part, and sometimes I want to see all of the parts together.

Another thing I’m hoping this helps with is that since you need to export each part individually for slicing and printing I used to just add a line that said “Uncomment this to export” above each item to be exported.

I figure this is a bit cleaner as you just need to toggle some values between 0 and 1. (And yes, you can do an export that is all parts laid out ready to print but I tend to not do that.)

Anyway, I’ve never really read up on best practices for writing OpenSCAD code. I’ve picked up things over the years from looking at code others have written, and from making my own mistakes and wanting to improve them.

If you know of any good tricks or have some tips, let me know!

Update: Someone asked why I was using 0 and 1 instead of false and true. I am not an expert on this but I believe since OpenSCAD is not strongly typed that 0 and 1 pretty much work as Boolean values and the only real difference is readability. If so, it’s really just a personal choice. (Let me know if that is incorrect.)