Skip to content

(Part 2/3) Project 3D part to plane#2002

Merged
adam-urbanczyk merged 19 commits into
CadQuery:masterfrom
antonysigma:project-to-viewpoint
Jul 15, 2026
Merged

(Part 2/3) Project 3D part to plane#2002
adam-urbanczyk merged 19 commits into
CadQuery:masterfrom
antonysigma:project-to-viewpoint

Conversation

@antonysigma

Copy link
Copy Markdown
Contributor

Simulate the API from Build123d project_to_viewpoint: Given a 3D vector representing the camera position pointing at the origin (0,0,0), render all visible edges/arcs/splines representing the outline of the 3D part projected to the camera.

Also render all hidden edges/arcs/splines.

Provide and example script tests/test_projection.py where a generic part (A bracket with rounded corners and a countersunk hole) is projected to top view, side view, front view, and orthogonal view, and then exported to DXF 2D drawings.

Reference: https://build123d.readthedocs.io/en/latest/tech_drawing_tutorial.html

Expected output from tests/test_projection.py:

image

Follow-up of MR #2001 .
Related to: #122, #1767

Comment thread tests/test_projection.py Outdated
Comment thread tests/test_projection.py Outdated
Comment thread cadquery/occ_impl/projection.py Outdated
@antonysigma
antonysigma force-pushed the project-to-viewpoint branch 2 times, most recently from 97a6903 to d975b18 Compare February 27, 2026 21:23
@adam-urbanczyk

Copy link
Copy Markdown
Member

OK, let's get this going. @antonysigma could you run our version of black in the codebase?

@antonysigma
antonysigma force-pushed the project-to-viewpoint branch from d975b18 to 8de8187 Compare March 12, 2026 17:43
@antonysigma

Copy link
Copy Markdown
Contributor Author

OK, let's get this going. @antonysigma could you run our version of black in the codebase?

Done running black and pushed the new commit. Let me know if you need anything else.

@adam-urbanczyk

Copy link
Copy Markdown
Member

Still failing on black, did you use our version of the tool?

@antonysigma
antonysigma force-pushed the project-to-viewpoint branch from 8de8187 to c646aee Compare March 15, 2026 00:38
@antonysigma

Copy link
Copy Markdown
Contributor Author

Still failing on black, did you use our version of the tool?

My apologies. I mixed up darker with black. I pushed the revisions again.

@adam-urbanczyk

Copy link
Copy Markdown
Member

OK, next step to make the CI green is to fix mypy errors. Are you up to it @antonysigma ?

@antonysigma

Copy link
Copy Markdown
Contributor Author

OK, next step to make the CI green is to fix mypy errors. Are you up to it @antonysigma ?

I can help resolve new mypy errors caused by this PR, but I don't where the rest of the errors originated from. Were those errors introduced before my PR? Could you teach me how to program Appveyor's CI to ignore errors before my PR?

@adam-urbanczyk

Copy link
Copy Markdown
Member

There are no mypy issues on HEAD according to our CI. So I assume that everything is on your side. No need to do anything with appveyor,, you can run mypy locally and simply fix all the errors. If this sounds too complicated, we can probably help.

Simulate the API from Build123d `project_to_viewpoint`: Given a 3D
vector representing the camera position pointing at the origin
`(0,0,0)`, render all visible edges/arcs/splines representing the outline
of the 3D part projected to the camera.

Also render all hidden edges/arcs/splines.

Provide and example script `tests/test_projection.py` where a generic
part (A bracket with rounded corners and a countersunk hole) is
projected to top view, side view, front view, and orthogonal view, and
then exported to DXF 2D drawings.

Reference: https://build123d.readthedocs.io/en/latest/tech_drawing_tutorial.html
@antonysigma
antonysigma force-pushed the project-to-viewpoint branch from c646aee to 4552668 Compare March 23, 2026 18:42

@antonysigma antonysigma left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi @adam-urbanczyk ,

Yes, I need help resolving mypy errors, especially those exists before this PR.

Please refer to the inline comments for the out-of-scope errors.

-Antony

Comment thread cadquery/occ_impl/exporters/svg.py
Comment thread cadquery/occ_impl/exporters/svg.py
@codecov

codecov Bot commented Apr 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.75281% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.70%. Comparing base (3e34909) to head (0e03c1c).

Files with missing lines Patch % Lines
cadquery/occ_impl/exporters/dxf.py 81.81% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2002   +/-   ##
=======================================
  Coverage   95.70%   95.70%           
=======================================
  Files          30       30           
  Lines        9447     9479   +32     
  Branches     1406     1410    +4     
=======================================
+ Hits         9041     9072   +31     
- Misses        252      253    +1     
  Partials      154      154           

☔ View full report in Codecov by Harness.
📢 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.

Comment thread cadquery/occ_impl/shapes.py Outdated
Comment thread cadquery/occ_impl/shapes.py Outdated
@antonysigma

Copy link
Copy Markdown
Contributor Author

Thank you for doing the dirty laundry for me. It is certainly a daunting process for me to understand the legacy DXF code in the repo, not to mention patching it. I appreciate the effort.

Comment thread cadquery/occ_impl/shapes.py
Comment thread cadquery/occ_impl/shapes.py Outdated
Comment thread cadquery/occ_impl/shapes.py Outdated
@lorenzncode

Copy link
Copy Markdown
Member

@antonysigma This results in the same result as your DXF screenshot from the description above:

exporters.exportDXFProjection(drilled, "ortho.dxf", (1, 1, 1))

Now you also have the option to specify "up" direction.

exporters.exportDXFProjection(drilled, "ortho_zup.dxf", (1, 1, 1), up=(0, 0, 1))
image

@lorenzncode

Copy link
Copy Markdown
Member

Example generating a PNG screenshot with cadquery.vis:

from cadquery import Workplane
from cadquery.func import hlr
from cadquery.vis import show, style

# Based on examples/Ex102_DXF_with_HLR.py.
width = 10
depth = 10
height = 10
hole_dia = 3.0

baseplate = Workplane("XY").box(width, depth, height).edges("|Z").fillet(2.0)
drilled = baseplate.faces(">Z").workplane().cskHole(hole_dia, hole_dia * 2, 82.0)

# Create an isometric orthographic projection with world +Z pointing upward.
hlr_result = hlr(drilled.val(), (1, -1, 1), up=(0, 0, 1))

show(
    style(hlr_result.visible, edgecolor="black", markersize=0),
    style(hlr_result.hidden, edgecolor="gray", linewidth=1, markersize=0,),
    interact=False,
    screenshot="img.png",
    width=800,
    height=800,
    roll=0,
    elevation=0,
    trihedron=False,
    gradient=False,
    bgcolor=(1, 1, 1),  # (this is also default color)
)

@antonysigma

antonysigma commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

@lorenzncode Thanks for refactoring the projection APIs. I haven't run the new example code on my computer yet, but I looks good to me at first glance. Feel free to merge it.

There is also Part 3/3 of the 2D projection feature: orthogonal projections and titlecard generation for 2D CAD drawings. I will rebase my branch to this PR later to make use of the modified APIs, before submitting the part 3 PR for code review.

@adam-urbanczyk

Copy link
Copy Markdown
Member

@lorenzncode LGTM, shall we merge?

@lorenzncode

Copy link
Copy Markdown
Member

Yes, ready to merge.

@antonysigma

Copy link
Copy Markdown
Contributor Author

@lorenzncode @jmwright @adam-urbanczyk I just submitted the draft PR, showcasing the final integration to the technical drawing feature. That should represent almost all of my use-cases for the API cq.exporters.exportDXFProjection.

Question: how do I configure Github PR webpage to "rebase" to this PR? Or, make this PR the dependency?

#2068

@adam-urbanczyk
adam-urbanczyk merged commit b47f7b7 into CadQuery:master Jul 15, 2026
4 checks passed
@adam-urbanczyk

Copy link
Copy Markdown
Member

Not sure what you mean. Just merge master to your branch and it should be fine.

@antonysigma
antonysigma deleted the project-to-viewpoint branch July 15, 2026 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants