# Are there any "best" or at least "common" practices to handle allowances in OpenSCAD code?

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 "5 mm diameter pin" to fasten two pieces together, how much larger than 5 mm will the holes / how much smaller than 5 mm 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.

• I suspect that OpenSCAD is too niche to have such conventions. What you are doing is very similar to my own practices.
– Mick
Dec 20 '17 at 8:05

## 3 Answers

It helps to understand the different aspects of dimensions, so you can use the terminology correctly. This will help you define your variables in OpenSCAD with correct names. (Tolerance is the wrong term to use.) And once you have correct names, you'll understand how to specify the dimensions in OpenSCAD.

• Tolerance is the amount of random deviation or variation permitted for a given dimension.
• Allowance is a planned difference between a nominal or reference value and an exact value.
• Clearance is the intentional space between two parts.
• Interference is the intentional overlap between two parts.

Two other terms

• Accuracy is the maximum dimensional variation between parts. A machine cannot produce parts with a tighter tolerance than its accuracy.
• Precision is the size of the steps your machine is capable of. It is often confused with accuracy.

In your case you need to define the allowance in order to create the clearance you desire.

To design your 5 mm pin and 5 mm hole, you need to understand your machine's accuracy. The printer could print the pin larger than 5 mm or smaller than 5 mm. Or it could print the hole larger than 5 mm or smaller than 5 mm. You'll need to print some pins and holes and measure the differences between what you defined and what you printed. The difference between the largest and smallest measurements you take is your machine's accuracy. And be sure to check the accuracy in your X, Y, and Z dimensions; your printer might have a difference between them that would impact the roundness of the parts.

Let's say that your printer's measured accuracy is ± 0.2 mm.

Then, we move to clearance. What is the minimum gap between parts you are looking for, and what is the maximum you can accept?

Let's say you want a clearance of at least 0.2 mm between the pin and hole, but no more than 1.0 mm. Since your accuracy is ± 0.2 mm, your pin will be 5.0 ± 0.2 mm, so the hole must therefore be 5.6 mm ± 0.2 mm. The minimum tolerance condition would be an minimum sized hole (5.4 mm) and a maximum sized pin (5.2 mm); the maximum tolerance would be a maximum sized hole (5.8 mm) and a minimum sized pin (4.8 mm).

Note that a clearance of 1.0 mm might be too sloppy for your application. You might think to tighten the tolerances to 0.05 mm in order to reduce the clearance. But if your printer can't produce a part that meets your specified tolerances, you would need to find a different way to manufacture or finish the parts.

• Thank you for providing me with the proper English vocabulary to communicate with other designers effectively! I updated my question accordingly. However my question is specifically about organising OpenSCAD code, not about the theory and practice of allowances (which I already understood, albeit ignoring the proper English terms). :) May I suggest that you create a wiki-style question (option when you edit the question) like "What are the differences between allowance and tolerance?" and move your text there? This is very useful information, but it isn't an answer to my question, alas!
– mac
Dec 31 '17 at 2:13
• ...and of course I'd be the first to upvote that... just let me know in the comments if you get around to do it! :)
– mac
Dec 31 '17 at 2:15

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.

• So, are you saying that instead of using a variable for all allowances you create an ad-hoc variable for each and every dimension in your part? If not, can you clarify what is the difference between your approach and the one described in the question itself? Thanks! :)
– mac
Feb 4 '18 at 8:33
• @mac that’s correct. You could still use this pattern with a more global tolerance variable and you would have the flexibility to use it where you can or to be as granular as you need. Some things may need a tight fit. Others should have some give. Feb 4 '18 at 12:26

Well, the tolerances will depend on material to be used for fabrication of the required part and also where the part will go and fit. Remember the all parts need some clearance to fit properly.

Few years ago (10 years) I was working as Quality Engineer and some Design Engineers were complaining about a Dupont pin was not fitting on the PCB so they told me that I need to force the PCB manufacturing to increase the holes to the higher tolerance. Which I had to ask him firstly the pin size and told me 0.70 mm and hole size 0.80 and maximum 0.90 - hmmm and maximum size of the pin? I asked, and they told me proudly 0.78mm so the part will fit perfectly. - Oh, so one square pin of 0.78mm will fit on one hole of 0.9mm, but what about the diagonal dimension? if the pin on the higher dimension is close to 1.2mm.

Imagine what happened later, engineering changes and modifying other designs due improper tolerances. pro-engineer software was unable to calculate what the designers needed.

Material has shrinkage, warpage, and other conditions that is needed to know like malleability and hardness and some of this data is on the specification material or the part specification.

• This does not answer the question in any way.
– tjb1
Jan 2 '18 at 12:31
• @tjb1 This make you think about considering tolerances even if you are using the best cad software. Jan 2 '18 at 22:03
• The question is asking how to apply tolerances inside of OpenSCAD when coding, not how tolerances apply to a real part.
– tjb1
Jan 3 '18 at 0:44
• @tjb1 So, the user will never plan to use in real parts? Jan 3 '18 at 5:21
• Regardless if it's tolerances or allowances, the question is about how to apply them in the code inside OpenSCAD that is generating the model, see the bullet points of the question. StackExchange is not a forum and your answer is largely a story about a previous job, but not an answer to the question.
– tjb1
Jan 3 '18 at 12:04