Skip to content

Added unit handling to STEP import and export#2023

Merged
adam-urbanczyk merged 35 commits into
masterfrom
unit-import-export
May 14, 2026
Merged

Added unit handling to STEP import and export#2023
adam-urbanczyk merged 35 commits into
masterfrom
unit-import-export

Conversation

@jmwright
Copy link
Copy Markdown
Member

@jmwright jmwright commented Mar 30, 2026

@adam-urbanczyk @lorenzncode This fixes a long-standing issue where things are at the wrong scale when exchanging STEP files because CadQuery did not use OCCT's units mechanism.

Fixes #1449, fixes #1829

@jmwright
Copy link
Copy Markdown
Member Author

Related issues that should be closed after this is merged: #1829 #1449

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 31, 2026

Codecov Report

❌ Patch coverage is 96.55172% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 95.62%. Comparing base (f86ff79) to head (250032c).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
cadquery/assembly.py 88.88% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2023   +/-   ##
=======================================
  Coverage   95.61%   95.62%           
=======================================
  Files          30       30           
  Lines        8881     8893   +12     
  Branches     1311     1311           
=======================================
+ Hits         8492     8504   +12     
  Misses        240      240           
  Partials      149      149           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@adam-urbanczyk
Copy link
Copy Markdown
Member

adam-urbanczyk commented Mar 31, 2026

Thanks for picking this up @jmwright , this is very needed! Could you also add another option to export (e.g. outputUnit : STEPUnitLiterals | None = None) that would control the output unit and make unit control the document unit too? The default behavior being document unit == output unit? Cf. xstep.cascade.unit and write.step.unit OCCT options.

@adam-urbanczyk
Copy link
Copy Markdown
Member

@jmwright
Copy link
Copy Markdown
Member Author

@adam-urbanczyk Is the current implementation that you had in mind?

@adam-urbanczyk
Copy link
Copy Markdown
Member

Yes, thanks! Just give me some time to review.

Copy link
Copy Markdown
Member

@adam-urbanczyk adam-urbanczyk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I found a few things:

  1. It would be nice to support mm on top of MM
  2. I think import should reply on "cascade.unit"
  3. Would it be possible to support xbf an xml too?

Comment thread cadquery/occ_impl/shapes.py Outdated
Comment thread cadquery/occ_impl/shapes.py Outdated
Comment thread cadquery/occ_impl/importers/assembly.py Outdated
Comment thread doc/importexport.rst Outdated
Comment thread cadquery/occ_impl/importers/assembly.py Outdated
jmwright and others added 3 commits April 5, 2026 17:28
Co-authored-by: AU <adam-urbanczyk@users.noreply.github.com>
Co-authored-by: AU <adam-urbanczyk@users.noreply.github.com>
Co-authored-by: AU <adam-urbanczyk@users.noreply.github.com>
@jmwright
Copy link
Copy Markdown
Member Author

jmwright commented Apr 5, 2026

@adam-urbanczyk Are the mypy errors I'm getting now related to the ones you are getting on the nurbs PR?

@adam-urbanczyk
Copy link
Copy Markdown
Member

Not really, new release of mypy got more strict (as it usually does).

Comment thread cadquery/occ_impl/shapes.py Outdated
@adam-urbanczyk
Copy link
Copy Markdown
Member

@jmwright do you mind if I'm going to try to add units to xbf and xml import/export too? Or shall we try this in another PR?

Comment thread cadquery/occ_impl/types.py Outdated
Co-authored-by: AU <adam-urbanczyk@users.noreply.github.com>
@jmwright
Copy link
Copy Markdown
Member Author

do you mind if I'm going to try to add units to xbf and xml import/export too?

@adam-urbanczyk Feel free, if you would like. However, it's a slightly different mechanism for setting the units for non-STEP formats, if I understand correctly.

Comment thread cadquery/assembly.py
Comment thread cadquery/assembly.py
Co-authored-by: AU <adam-urbanczyk@users.noreply.github.com>
Comment thread cadquery/occ_impl/exporters/assembly.py Outdated
Comment thread cadquery/occ_impl/exporters/assembly.py Outdated
Comment thread cadquery/occ_impl/exporters/assembly.py Outdated
@adam-urbanczyk
Copy link
Copy Markdown
Member

I added (STEP only, not sure how to make this work for xbf/xml) unit handling for export/load. @lorenzncode do you want to take a look, or shall I merge?

Comment thread cadquery/assembly.py Outdated
Comment thread doc/importexport.rst Outdated
Comment thread cadquery/assembly.py Outdated
Comment thread cadquery/assembly.py
@adam-urbanczyk
Copy link
Copy Markdown
Member

@lorenzncode thanks for taking a look! I think I resolved all of the issues.

Copy link
Copy Markdown
Member

@lorenzncode lorenzncode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @adam-urbanczyk @jmwright ! I found one more doc issue to check.

Comment thread doc/importexport.rst Outdated
Comment thread doc/importexport.rst Outdated
Comment thread doc/importexport.rst Outdated
@adam-urbanczyk
Copy link
Copy Markdown
Member

Alright, merging. Thanks a lot for the implementation @jmwright and reviewing @lorenzncode!

@adam-urbanczyk adam-urbanczyk merged commit a637795 into master May 14, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow to specify units when importing STEP files [feature request] embed user selectable length units in step file outputs

3 participants