1. About
  2. Features
  3. Explore

I'm designing a few mechanisms with OpenSCAD, and one of the parameters that need adjustment between printers/filaments is allowances between pieces that need to be assembled together (for example, if I want a "5mm diameter pin" to fasten two pieces together, how much larger than 5mm will the holes / how much smaller than 5mm will the pin need to be).

Currently I approach the problem by setting a global variable allowance and manually using it in the code, something like:

module pin(radius) { cylinder(r = radius + allowance) } module hole(radius) { cylinder(r = radius - allowance) } 

I have no real world experience with design though, so I wonder if there are common or coding best practices to account for allowances when designing parts like for example:

  • specific modules to be used,
  • conventional names for variables
  • specific techniques to be used (scaling? vectors?)
  • conventions (like only use tolerances on the fastener, not the fastened object)
  • ...?

To clarify: I'm not looking on advice on how to plan the dimensions of my designs. Rather, I am looking for advice on how to organise the OpenSCAD code generating them.

1 Answer 1

I’m not aware of a standard in Openscad but I can share what I have done in the past.

cutoutActualDiameter = 10; cutoutDiameterClearance = 0.1; cutoutDiameter = cutoutActualDiameter + cutoutDiameterClearance; 

I know this is verbose but unfortunately in my experience that is a necessity if you want your code to be maintainable in Openscad. The benefit of this is that up until you need any clearance added you can just use the variable cutoutDiameterand then if and when you do need clearance added you can rename that variable and you don’t have to change any of the code where the variable is consumed.

Would love to hear how others manage this though.