Replies: 1 comment
-
import cadquery as cq
from cadquery.selectors import BoxSelector, AreaNthSelector
portOD = 80
hoseOD = 50
wallThickness = 4
portLength = 40
hoseLength = 40
transitionLength = 30
clearance = 0.5
hoseClipOffset = 5
hoseClipDepth = 4
hoseClipWidth = 20
numClipWedges = 5
hoseClipHeight = hoseClipDepth * numClipWedges
s_clip = (
cq.Sketch()
.push([(-hoseClipDepth / 2, -hoseClipDepth / 2)]) # to center
.rarray(hoseClipDepth, hoseClipDepth, 1, numClipWedges)
.segment((0, 0), (0.1, 0)) # to have clean face
.segment((0.1, 0), (hoseClipDepth, hoseClipDepth))
.segment((0, hoseClipDepth))
.close()
.assemble()
)
clip = cq.Workplane("XZ").placeSketch(s_clip).extrude(hoseClipWidth / 2, both=True)
clip = (
clip.translate(
(hoseOD / 2 + hoseClipDepth + hoseClipOffset, 0, hoseClipHeight / 2 + 5)
)
.solids()
.tag("clip")
.faces("<X")
.tag("xface")
)
# points on the inside of the adapter
pts = [
(hoseOD / 2 - clearance, 0),
(hoseOD / 2 - clearance, hoseLength),
(portOD / 2 + wallThickness + clearance, hoseLength + transitionLength),
(
portOD / 2 + wallThickness + clearance,
hoseLength + transitionLength + portLength,
),
]
# add outside points and close
pts.extend([(p[0] + wallThickness, p[1]) for p in reversed(pts)])
pts.append(pts[0])
result = cq.Workplane("XZ").sketch().polygon(pts).finalize().revolve()
# Box selector returns two faces (from hose portion)
# Area selector 0 = inner, 1 outer
face_adapter = result.faces(
BoxSelector(
(-hoseOD / 2 - wallThickness, -hoseOD / 2 - wallThickness, 0.1),
(hoseOD / 2 + wallThickness, hoseOD / 2 + wallThickness, hoseLength - 0.1),
)
).faces(AreaNthSelector(1))
face_project = clip.val().project(face_adapter.val(), (-1, 0, 0))
join = cq.Solid.makeLoft(
[clip.faces(tag="xface").val().Wires()[0], face_project.Wires()[0]]
)
result = result.union(join).union(clip.solids(tag="clip")) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Using cq-editor v0.2.0 (and later cadquery==2.2.0b2 and cadquery-server==0.4.1)
I've been having a lot of fun playing with cadquery and but have unfortunately been running into some behaviors I can't explain. Not sure if these are me misunderstanding the tool or actual bugs.
I'm trying to build design an adapter for my vacuum hose which has a little clip on the side to secure it (The hose has a arm that hooks onto the wedge on the adapter). I was running into issues building it, and then tried to create a minimal example. The full code for what I was originally trying to build is included at the bottom.
Bug 1:
(Also reducing the extrude amount to be below 5 gives
Null TopoDS_Shape object
error.. not sure why). Increasing the amount makes the box longer but not thicker.Bug 2:
I converted this to use another workplane instead of the wires and for some reason got the same result until I used
centerOption="CenterOfMass"
. I then "shelled" the cylinder since that was causing a problem in the original code.Sure enough,
.extrude(1)
worked fine, but.extrude(2)
actually crashedcq-editor
! I then switched to using cadquery==2.2.0b2 and cadquery-server==0.4.1 in vscode to see if it would help.With the new version of cadquery, the code below no longer crashes but the box disappears, showing only the hollow cylinder.
Bug 3:
What I would ideally like is to just extrude the rect until it hits the side of the hollow tube, but the "next" option to extrude doesn't do what I would expect either. Why is it going all the way through the cylinder to the other side?
Original code:
I've included my original attempt (cadquery==2.2.0b2 cadquery-server==0.4.1) here in case it helps with context and/or in case anyone has any suggestions on how I could write it better.
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions