* Added AreaNthSelector Added AreaNthSelector that is useful for nested features selection. Especially to select one of coplanar nested wires for subsequent extrusion, cutting or filleting. * LengthNthSelector * Explicitly marked _NthSelector class and _NthSelector.key(..) method as abstract using standard abc package * AreaNthSelector ignores "bad" Wires AreaNthSelector.key raises ValueError if temporary face creation fails for a wire for any reason (non-planar, non-closed). That causes _NthSelector that it inherits to ignore such wires. Done so for consistency with RadiusNthSelector that ignores anything it can not get radius from. Co-authored-by: Marcus Boyd <mwb@geosol.com.au>
48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
import cadquery as cq
|
|
from cadquery.selectors import AreaNthSelector
|
|
|
|
case_bottom = (
|
|
cq.Workplane("XY")
|
|
.rect(20, 20)
|
|
.extrude(10) # solid 20x20x10 box
|
|
.edges("|Z or <Z")
|
|
.fillet(2) # rounding all edges except 4 edges of the top face
|
|
.faces(">Z")
|
|
.shell(2) # shell of thickness 2 with top face open
|
|
.faces(">Z")
|
|
.wires(AreaNthSelector(-1)) # selecting top outer wire
|
|
.toPending()
|
|
.workplane()
|
|
.offset2D(-1) # creating centerline wire of case seam face
|
|
.extrude(1) # covering the sell with temporary "lid"
|
|
.faces(">Z[-2]")
|
|
.wires(AreaNthSelector(0)) # selecting case crossection wire
|
|
.toPending()
|
|
.workplane()
|
|
.cutBlind(2) # cutting through the "lid" leaving a lip on case seam surface
|
|
)
|
|
|
|
# similar process repeated for the top part
|
|
# but instead of "growing" an inner lip
|
|
# material is removed inside case seam centerline
|
|
# to create an outer lip
|
|
case_top = (
|
|
cq.Workplane("XY")
|
|
.move(25)
|
|
.rect(20, 20)
|
|
.extrude(5)
|
|
.edges("|Z or >Z")
|
|
.fillet(2)
|
|
.faces("<Z")
|
|
.shell(2)
|
|
.faces("<Z")
|
|
.wires(AreaNthSelector(-1))
|
|
.toPending()
|
|
.workplane()
|
|
.offset2D(-1)
|
|
.cutBlind(-1)
|
|
)
|
|
|
|
show_object(case_bottom)
|
|
show_object(case_top, options={"alpha": 0.5})
|