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.


Posted 2017-12-20T02:26:21.183

Reputation: 4 437

1I suspect that OpenSCAD is too niche to have such conventions. What you are doing is very similar to my own practices. – Mick – 2017-12-20T08:05:29.550



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.

John Deters

Posted 2017-12-20T02:26:21.183

Reputation: 173

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 – 2017-12-31T02:13:42.093

...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 – 2017-12-31T02:15:44.000


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.

Nick Dancer

Posted 2017-12-20T02:26:21.183

Reputation: 106

1So, 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 – 2018-02-04T08:33:01.917

@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. – Nick Dancer – 2018-02-04T12:26:56.223


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.

Fernando Baltazar

Posted 2017-12-20T02:26:21.183

Reputation: 1 280

1This does not answer the question in any way. – tjb1 – 2018-01-02T12:31:29.890

@tjb1 This make you think about considering tolerances even if you are using the best cad software. – Fernando Baltazar – 2018-01-02T22:03:05.630

1The question is asking how to apply tolerances inside of OpenSCAD when coding, not how tolerances apply to a real part. – tjb1 – 2018-01-03T00:44:39.733

@tjb1 So, the user will never plan to use in real parts? – Fernando Baltazar – 2018-01-03T05:21:13.503

@tjb1 Now the question has changed to allowance instead tolerances. – Fernando Baltazar – 2018-01-03T05:30:40.403

1Regardless 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 – 2018-01-03T12:04:29.607

@tjb1 Certainly my answer is about a tolerances wrong applied due lack of knowledge whom were believing in a software to do his job. So my answer is to not let the job to the sofware or there will be problems on final product. Forum? I´m away from them and i´m not pretend to do or participate on any. I prefer to say "stories" in companies where I have to lead to improve his process (quality management); there are people who don't like the stories, they have to quit the company because they can't have a good approaching to the company goals. – Fernando Baltazar – 2018-01-03T21:42:52.900