Finding the Tightest Tolerance in a Technical Drawing
Overview
When developing a pricing or quoting engine, you may need to determine the tightest tolerance in a technical drawing. This information is valuable because:
Stricter tolerances increase manufacturing costs, which may warrant a price premium. Looser tolerances simplify manufacturing, potentially allowing you to offer discounts. By using WERK24’s AI-driven analysis, you can automatically extract tolerances from a drawing within seconds. Once you receive the extracted tolerances, all that remains is to define what "tightest" means and filter for it.
Decide which tolerances are relevant for you
Tight tolerances can appear in various aspects of a technical drawing. To ensure your analysis, pricing, or manufacturing process is optimized, you must decide which tolerances matter most for your application.
Common Tolerance Categories
-
Bore Depths – Critical when precise hole depths are required for fasteners, press fits, or fluid channels.
-
Bore Diameters – Essential for hole fits, bearings, and interference fits, ensuring proper function and assembly.
-
Chamfer Sizes – Important in edge finishing, stress reduction, and assembly alignment.
-
Dimensions – The most general category, covering linear, angular, and positional tolerances across the drawing.
-
Thread Tolerances – Necessary for threaded components, where minor deviations can affect screw fit, load distribution, and sealing properties.
Which Should You Consider? For most applications, focusing on: * Bore Diameters * Chamfer Sizes * Dimensions
…provides the most value, as they directly impact machinability, fit, and cost. However, if your industry requires precise threading or depth control, you should include Thread Tolerances and Bore Depths as well.
Define what "Smallest Tolerance" means
The concept of smallest tolerance can be interpreted in different ways, depending on the context of your application.
Two Common Approaches:
-
Smallest Interval – The absolute smallest tolerance width, calculated as: $$ Tolerance Width = Upper Deviation - Lower Deviation $$ While simple, this approach does not consider the nominal size of the feature, which can lead to misleading conclusions.
-
IT Grade-Based Smallest Tolerance (Recommended) – Instead of just measuring the interval, we use the International Tolerance (IT) Grade, which considers the relationship between the nominal size and tolerance width.
- This method is more meaningful in engineering since a ±0.01 mm tolerance on a 5 mm part is much stricter than the same tolerance on a 500 mm part.
- IT Grades provide a normalized way to compare tolerances across different feature sizes.
Note
If you're not familiar with IT Grades, check out our IT Grade Guide for a deeper understanding.
Codify the Smallest IT Grade
To automate the process of identifying the smallest IT Grade from a technical drawing, we need to:
- Extract relevant tolerances from dimensions, bores, and chamfers.
- Determine the smallest IT Grade, as lower IT numbers indicate higher precision.
- Compare and update the smallest IT Grade across all extracted tolerances.
This function will be called for each page in the drawing!
Ensure your implementation correctly processes multiple pages by accumulating, comparing, or filtering the extracted data across all pages.
import asyncio
from werk24 import (
Werk24Client, AskMetaData, TechreadMessage, Hook, get_test_drawing, ResponseFeaturesComponentDrawing
)
smallest_it_grade = float("inf") # Initialize smallest IT grade variable
def recv(message: TechreadMessage):
"""
Processes the received message and extracts the smallest IT grade from tolerances.
Args:
-----
- message (TechreadMessage): The response from Werk24 containing feature data.
"""
global smallest_it_grade # Access global variable
# Ignore unsuccessful responses
if not message.is_successful:
return
# Extract features from the response
features: ResponseFeaturesComponentDrawing = message.payload_dict
# Collect relevant tolerances
tolerances = [d.size.tolerance for d in features.dimensions]
tolerances += [b.diameter.tolerance for b in features.bores]
tolerances += [c.size.tolerance for c in features.chamfers]
# Find the smallest IT grade from extracted tolerances
c_smallest_it_grade = min(
(int(t.tolerance_grade.replace("IT", "")) for t in tolerances if t is not None),
default=None
)
# Update the smallest IT grade if a smaller one is found
if c_smallest_it_grade is not None:
smallest_it_grade = min(smallest_it_grade, c_smallest_it_grade)
Manage the completion of the task
Once all pages of the technical drawing have been processed, you need to determine what actions to take. This could involve:
- Logging the smallest IT Grade for reference.
- Triggering additional processing steps (e.g., cost estimation or quality validation).
- Returning results to an API caller or UI.
def inform_caller(message: TechreadMessage):
"""
Handles the final completion status after all pages have been processed.
Args:
-----
- message (TechreadMessage): The final message indicating completion status.
"""
global smallest_it_grade
# Handle failure cases
if not message.is_successful:
print("Task Failed: Could not process the drawing.")
return
# Output the smallest IT Grade across all pages
if smallest_it_grade < float("inf"):
print(f"Smallest IT Grade across all pages: IT{smallest_it_grade}")
else:
print("No tolerances found in the drawing.")
Trigger the Execution
Now that we have defined the logic to extract the smallest IT Grade, we need to send the technical drawing to Werk24 and trigger the execution.
import asyncio
from werk24 import Werk24Client, AskFeatures, Hook
async def read_drawing(path: str):
"""
Sends a technical drawing to Werk24 and processes the extracted features.
Args:
-----
- path (str): The file path of the technical drawing to process.
"""
# Define the request (AskFeatures) and the response handler (recv)
hooks = [
Hook(ask=AskFeatures(), function=recv),
Hook(
message_type=TechreadMessageType.PROGRESS,
message_subtype=TechreadMessageSubtype.PROGRESS_COMPLETED,
function=inform_caller
)
]
# Open the file and send it for processing
with open(path, "rb") as fid:
async with Werk24Client() as client:
await client.read_drawing_with_hooks(fid, hooks)
# Run the asynchronous function
asyncio.run(read_drawing("<path-to-drawing>"))