python - CadQuery Stack Nagivation: how to unparent "XY" plane from `transformed`-made workplane - Stack Overf

admin2025-04-16  5

Beginner at CadQuery,

Trying to do basic modeling.

I want to drill multiple holes from different direction in an object,

so I:

  • make the object, and then
  • use .faces("XY") to get the top plane and then
  • use .transforms(...) to rotate the plane to a specific direction then
  • use .hole(...) to drill holes.

however, workspace got from faces() seem to be parented to the previous one, and make the rotation aggregated.

I have very few understandings of the cadquery stack in general, so I try:

  • .first() before or after the drilling holes
  • .last() before or after the drilling holes
  • .end() before or after the drilling holes
  • unrotate at each iteration

So, how can I achieve desired task, and what is the best practice(s) for that?

import cadquery as cq

thickness = 2
rad = 5
leng = 10

# Making the Soild
result = (
    cq
    .Workplane("XY")
    .tag("top")
    .sphere(rad + thickness)
    .faces("XY")
    .split(keepTop=True)
    .faces("<Z")
    .workplane()
    .circle(rad + thickness)
    .extrude(leng)
    .faces("<Z")
    .shell(thickness)
    )

# Drilling Holes
for i in range(3):
    result = (
        result
        # .first() 
        # .last()
        
        .faces("XY")
        .transformed(rotate=(0,30,0))
        .transformed(rotate=(0,0,i*120))
        .hole(1)
        
        # .transformed(rotate=(0,0,-i*120))
        # .transformed(rotate=(0,-30,0))
    )

show_object(result)

Expected Result

转载请注明原文地址:http://anycun.com/QandA/1744776276a87465.html