wire = cq.Wire.makeHelix(pitch, height, radius)
cut_path cq.Workplane("XY").newObject([wire]).translate((0, 0, pitch))
profile = (
cq.Workplane("XZ")
.polyline(profile_points)
.close()
.sweep(cut_path, isFrenet=True)
)
body = (
cq.Workplane("XY")
.circle(radius)
.extrude(height+pitch)
)
result = body.cut(profile)
pitch = 6
depth = 3
radius = 20.0
height = 20.0
profile_points = (
(radius+depth, 0.1),
(radius+0.1, 0.1),
(radius-depth, pitch/2),
(radius+0.1, pitch+0.1),
(radius+depth, pitch+0.1)
)
wire = cq.Wire.makeHelix(pitch, height+pitch, radius)
import cadquery as cq
pitch = 6
depth = 3
radius = 20.0
height = 20.0
profile_points = (
(radius+depth, 0.1),
(radius+0.1, 0.1),
(radius-depth, pitch/2),
(radius+0.1, pitch+0.1),
(radius+depth, pitch+0.1)
)
#wire = cq.Wire.makeHelix(pitch, height, radius)
wire = cq.Wire.makeHelix(pitch, height+pitch, radius)
cut_path = cq.Workplane("XY").newObject([wire]).translate((0, 0, pitch))
profile = (
cq.Workplane("XZ")
.polyline(profile_points)
.close()
.sweep(cut_path, isFrenet=True)
)
body = (
cq.Workplane("XY")
.circle(radius)
.extrude(height+pitch)
)
result = body.cut(profile)
result.val().exportStl('/home/jwright/Downloads/test_stl.stl', precision=0.001)
show_object(result)
import cadquery as cq
def _helical_path(pitch, height, radius):
"""
Make a helix on the XY plane, growing in Z.
"""
wire = cq.Wire.makeHelix(pitch, height, radius)
return cq.Workplane("XY").newObject([wire])
def make_thread(pitch, radius, height, profile_points):
"""
Make a solid threaded object.
:param pitch: Thread pitch.
:param radius: Thread radius.
:param height: Thread height.
:param profile_points: Sequence of X,Y tuples defining the *inverse* of the profile profile.
:returns: CQ.Solid
"""
single_turn = _helical_path(pitch, pitch, radius)
profile = (
cq.Workplane("XZ")
.polyline(profile_points)
.close()
.sweep(single_turn, isFrenet=True)
)
cross_section = (
cq.Workplane("XY")
.workplane(offset=-pitch / 2.)
.circle(radius)
.extrude(pitch / 2.)
.cut(profile)
.faces(">Z")
)
cross_section_face = cross_section.val() # cadquery.Face
cross_section_wire = cross_section_face.Wires().pop()
full_helix = _helical_path(pitch, height, radius)
result = cq.Workplane("XY").newObject([cross_section_wire])
result._addPendingWire(cross_section_wire)
result = result.sweep(full_helix, isFrenet=True, multisection=False).combine()
return result
lid_thickness = 2
lid_height = 20 - lid_thickness
lid_radius = 54.5 - lid_thickness
cylinder = (
cq.Workplane("XY")
.circle(lid_radius)
.extrude(lid_height)
)
pitch = 5
thread_radius = lid_radius
thread_height = lid_height + 2
points = (
(thread_radius+0.1, 0),
(thread_radius-pitch, pitch/2),
(thread_radius+0.1, pitch)
)
torus = cq.Solid.makeTorus(
32, 12,
pnt=cq.Vector(0,0,lid_height),
dir=cq.Vector(0,0,1),
angleDegrees1=0,
angleDegrees2=360
)
lid = cylinder.cut(torus)
lid = lid.faces("-Z").shell(lid_thickness)
tap = make_thread(pitch, thread_radius, thread_height, points)
tap = tap.translate((0, 0, -1))
thread_cylinder = (
cq.Workplane("XY")
.circle(thread_radius+(lid_thickness/2))
.extrude(lid_height)
)
thread_cylinder = thread_cylinder.cut(tap)
lid = thread_cylinder.union(lid)
if __name__ != "__main__":
show_object(lid)
else:
print("Exporting...")
with open("biscuit_lid.amf", "wb",) as outfile:
cq.exporters.exportShape(lid, cq.exporters.ExportTypes.AMF, outfile)
# modifications begin
thread_cylinder = (
cq.Workplane("XY")
.circle(lid_radius+lid_thickness)
.extrude(lid_height+lid_thickness)
)
thread_cylinder = thread_cylinder.cut(tap)
thread_cylinder = thread_cylinder.union(torus) .\
faces(">Z[-2]").split(keepTop=False, keepBottom=True) .\
faces(">Z").workplane().circle(32+12).circle(32-12).cutBlind(-lid_thickness) .\
edges(">Z").fillet(lid_thickness-0.1)
show_object(thread_cylinder)
# modifications end
#lid = thread_cylinder.union(lid)
#if __name__ != "__main__":
# show_object(lid)
#else:
# print("Exporting...")
# with open("biscuit_lid.amf", "wb",) as outfile:
# cq.exporters.exportShape(lid, cq.exporters.ExportTypes.AMF, outfile)
te o código aqui...
thread_cylinder = (
cq.Workplane("XY")
.circle(thread_radius+(lid_thickness/2))
.extrude(lid_height)
)
thread_cylinder = thread_cylinder.cut(tap)
lid = thread_cylinder.union(lid)
lid.val().exportStl('lid.stl',1e-3,1e-1)
from cadquery import *
from math import *
def helix(r0,r_eps,p,h,d=0,frac=1e-1):
def func(t):
if t>frac and t<1-frac:
z = h*t + d
r = r0+r_eps
elif t<=frac:
z = h*t + d*sin(pi/2 *t/frac)
r = r0 + r_eps*sin(pi/2 *t/frac)
else:
z = h*t - d*sin(2*pi - pi/2*(1-t)/frac)
r = r0 - r_eps*sin(2*pi - pi/2*(1-t)/frac)
x = r*sin(-2*pi/(p/h)*t)
y = r*cos(2*pi/(p/h)*t)
return x,y,z
return func
def thread(radius, pitch, height, d, radius_eps, aspect= 10):
e1_bottom = (cq.Workplane("XY")
.parametricCurve(helix(radius,0,pitch,height,-d)).val()
)
e1_top = (cq.Workplane("XY")
.parametricCurve(helix(radius,0,pitch,height,d)).val()
)
e2_bottom = (cq.Workplane("XY")
.parametricCurve(helix(radius,radius_eps,pitch,height,-d/aspect)).val()
)
e2_top = (cq.Workplane("XY")
.parametricCurve(helix(radius,radius_eps,pitch,height,d/aspect)).val()
)
f1 = Face.makeRuledSurface(e1_bottom, e1_top)
f2 = Face.makeRuledSurface(e2_bottom, e2_top)
f3 = Face.makeRuledSurface(e1_bottom, e2_bottom)
f4 = Face.makeRuledSurface(e1_top, e2_top)
sh = Shell.makeShell([f1,f2,f3,f4])
rv = Solid.makeSolid(sh)
return rv
radius = 4
pitch = 2
height = 4
d = pitch/4
radius_eps = 0.5
eps=1e-3
core = cq.Workplane("XY",origin=(0,0,-d)).circle(radius-1-eps).circle(radius+eps).extrude(height+1.75*d)
th1 = thread(radius,pitch,height,d,radius_eps)
th2 =thread(radius-1,pitch,height,d,-radius_eps)
res = core.union(Compound.makeCompound([th1,th2]))
show_object(res)
Example: https://github.com/CadQuery/cadquery/blob/master/examples/Ex005_Extruded_Lines_and_Arcs.py
You can use moveTo to move the point without drawing. 2D drawing with CQ is tedious, but doable. DXF import has been recently added, which for static 2D profiles can be very helpful.
Thanks for your response. Do you want to tell me - then - that creation of a single-edge wire is not possible?
best regards,
Adrian