codeCAD/drops.py
2026-01-20 11:20:36 +01:00

450 lines
14 KiB
Python

#%%
from build123d import *
from ocp_vscode import *
from bd_animation import AnimationGroup, clone, normalize_track
import copy
#%%
text = Text("z",
font_size=8.0,
font_path="/usr/share/fonts/truetype/ebgaramond/EBGaramond12-Bold.ttf",
font_style=FontStyle.BOLD,)
show(text)
set_defaults(reset_camera=Camera.KEEP, render_joints=True, helper_scale=8)
#%%
ri=3
r=4
with BuildPart() as drops:
# Start with the plan of the key cap and extrude it
with BuildSketch() as plan:
RegularPolygon(ri,7,rotation=90)
with BuildSketch(Plane.XY.offset(2)) as planb:
Circle(r)
loft()
with BuildSketch(Plane.XY.offset(2)) as planc:
Circle(r)
extrude(amount=2)
with BuildSketch() as txt:
add(text)
extrude(amount=0.25, mode=Mode.SUBTRACT)
#chamfer(drops.edges(), length=0.05)
mirror(about=Plane.XZ, mode=Mode.REPLACE)
show(drops)
# %%
with BuildPart() as pezdrops:
# Start with the plan of the key cap and extrude it
with BuildSketch() as plan:
RectangleRounded(15,8, 3)
extrude(amount=5)
with BuildSketch(Plane.XY) as planb:
RectangleRounded(11,4, 0.5)
with BuildSketch(Plane.XY.offset(2)) as planc:
SlotCenterToCenter(7,2)
loft(mode=Mode.SUBTRACT)
fillet(pezdrops.faces().sort_by(Axis.Z)[0].edges(), radius=1)
show(pezdrops)
# %%
with BuildPart() as mold:
with Locations((0,0,1)):
Box(108,108,3)
with GridLocations(7+1, 8, 10, 10):
add(copy.copy(drops), mode=Mode.SUBTRACT)
show(mold)
# %%
with BuildPart() as pezmold:
with Locations((0,0,2)):
Box(116,112,7)
with Locations((0,0,1.5)):
Box(112,108,6,mode=Mode.SUBTRACT)
with GridLocations(17, 10, 6, 10,align=(Align.CENTER, Align.CENTER)):
add(copy.copy(pezdrops))
show(pezmold)
# %%
with BuildPart() as mold_for_mold:
n = 10
pad = 5
dxy=10
w = (dxy)*n+2*pad
wi = w-4
with Locations((0,0,1)):
Box(w, w, 6)
with Locations((0,0,1)):
Box(wi,wi,3, mode=Mode.SUBTRACT)
#with HexLocations(r+1,10,8):
with GridLocations(dxy, dxy, n, n):
add(copy.copy(drops), mode=Mode.ADD, rotation=(0,0,0))
with Locations((0,0,-2.5)):
Box(wi,wi,4, mode=Mode.SUBTRACT)
#add(mold, mode=Mode.SUBTRACT,rotation=180)
show(mold_for_mold)
# %%
#export_step(mold_for_mold.part, "zdrops8mm_mold_for_mold2.step")
# %%
#export_step(pezmold.part, "pezmold.step")
# %%
nHoles = 10
vol_ml = 1.0 # millilitiers = 1/1000 * 10cm*10cm*10cm = 100mm*100mm*100mm/1000 = 1000mm³
vol = vol_ml * 1000
r = 4 # millimeters
ri = 2
rrod=1
rodlen=100
tol = 0.05
A = 3.14*r*r
t = 2*vol/A # liter/meter
wt = 1
l, w, h = (r*2+wt)*(nHoles+0.5)+8, t+8, (r+wt)*2
with BuildPart() as pumpcylindercutout:
with BuildSketch(Plane.XZ) as holes_sk:
Circle(r)
extrude(amount=t)
with BuildSketch(pumpcylindercutout.faces().sort_by(Axis.Y)[0]) as rodhole_sk:
Circle(rrod+tol)
extrude(amount=10)
chamfer(pumpcylindercutout.edges().sort_by(Axis.Y)[3],2)
with BuildSketch(pumpcylindercutout.faces().sort_by(Axis.Y)[0]) as rodhole_sk:
Circle(r)
Circle(rrod+2, mode=Mode.SUBTRACT)
extrude(amount=10)
show(pumpcylindercutout,pumpcylindercutout.edges().sort_by(Axis.Y)[2])
#%%
with BuildPart() as pumpcylinderblock:
Box(l,w,h)
f = pumpcylinderblock.faces()[5].offset(-t)
#with GridLocations()
with Locations((0,t/2+4)):
with GridLocations(r+wt+r,0,nHoles,1):
add(pumpcylindercutout,mode=Mode.SUBTRACT)
#chamfer(pumpcylinderblock.edges().group_by(Axis.Z)[-1].filter_by(GeomType.CIRCLE), 0.4)
RigidJoint("slide", joint_location=Location(Plane.XY))
with BuildSketch(pumpcylinderblock.faces().sort_by(Axis.Z)[-1].translate((0,5,0))):
RectangleRounded(l-10,r*2+0.1, 2)
extrude(amount=-r,mode=Mode.SUBTRACT)
with BuildSketch(Plane.XY.offset(h/2)) as holes:
with Locations((0,5,0)):
with GridLocations(l-6,w-6-10,2,2):
Circle(1.5)
extrude(amount=-h,mode=Mode.SUBTRACT)
with BuildSketch(Plane.XZ.offset(25)) as holes:
with GridLocations(l-6,h-5,2,1):
Circle(1.5)
extrude(amount=-h,mode=Mode.SUBTRACT)
show(pumpcylinderblock)
#%%
with BuildPart() as oese:
c=Cylinder(3,2,rotation=(0,90,0))
fillet(c.edges().filter_by(GeomType.CIRCLE), 0.9)
Cylinder(1.5,2,rotation=(0,90,0), mode=Mode.SUBTRACT)
show(oese)
#%%
with BuildPart() as pumpvalverod:
rodlen=60
#Cylinder(3,4)
#with Locations((0,0,rodlen/2-10)):
# Cylinder(rrod,rodlen)
with BuildSketch(Plane.XY) as sk:
with BuildLine() as outline:
d=2
hn=1
l1=CenterArc((0,-rrod),rrod,270,90)
l2=Line(l1@1,(rrod,hn))
l3=Line(l2@1,(rrod+d,hn+d))
l4=Line(l3@1,(rrod,hn+2*d))
l5=Line(l4@1,(rrod,rodlen))
l6=CenterArc((0,rodlen),rrod,0,90)
l7=Line(l6@1,l1@0)
make_face()
revolve(axis=Axis.Y)
fillet(pumpvalverod.edges().sort_by(Axis.Y)[5],0.5)
with Locations((0,rodlen-3,0),(0,rodlen-9,0)):
with Locations((-rrod,0,0),(rrod,0,0)):
Box(rrod,3,4, mode=Mode.SUBTRACT)
show(pumpvalverod)
# %%
with BuildPart() as pumpcylinder:
rodlen=50
clen=8
elen=10
slen= 20
dy=-13
with BuildSketch(Plane.XZ.offset(dy)) as cl_sk:
Circle(r)
Circle(ri,mode=Mode.SUBTRACT)
extrude(amount=clen)
chamfer(pumpcylinder.edges().group_by(Axis.Y)[0][1],1)
with BuildSketch(pumpcylinder.faces().sort_by(Axis.Y)[-1]) as rods_sk:
with PolarLocations(r-(r-ri)/2,3,90):
Circle((r-ri)/2)
extrude(amount=slen)
with BuildSketch(Plane.XZ.offset(dy-slen-clen)) as cl_sk:
Circle(r)
Circle(rrod+0.05, mode=Mode.SUBTRACT)
extrude(amount=elen)
with BuildSketch(pumpcylinder.faces().sort_by(Axis.Y)[-1]) as rods_sk:
with PolarLocations(r-(r-ri)/2,2,0):
Rectangle((r-ri)/2,r)
#Circle((r-ri)/2)
extrude(amount=rodlen-clen-slen-elen)
with Locations((0,rodlen-1.5,r-0.25),(0,rodlen-1.5,-r+0.25)):
Box(15,3,5,mode=Mode.SUBTRACT)
show(pumpcylinder,pumpvalverod)
#%%
# MACHINE ASSEMBLY
openstate = False
pumped = True
trlen =2
pumplen=5
loc_rods = (0,-18-openstate*trlen+pumped*pumplen,0)
loc_cyls = (0,-20-openstate*trlen+pumped*pumplen,0)
with BuildPart() as pumpcylinderrods:
with Locations(loc_rods):
with GridLocations(r+wt+r,0,nHoles,1):
add(copy.copy(pumpvalverod))
with BuildPart() as pumpcylinders:
with Locations(loc_cyls):
with GridLocations(r+wt+r,0,nHoles,1):
add(copy.copy(pumpcylinder),rotation=(0,0,0),)
LinearJoint("cylinders", axis=Axis.Z, linear_range=(-t, t))
pumpcylinderblock.part.joints["slide"].connect_to(pumpcylinders.joints["cylinders"])
show(pumpcylinderblock,pumpcylinderrods,pumpcylinders,render_joints=True)#, pumpcylindercutout)# %%
#%%
with BuildPart() as nozzle:
#with BuildLine(Plane.XZ) as pipe:
# RadiusArc((0,0),(-10,-10,), -10)
dn=10
with BuildSketch(Plane.XZ) as profile:
Circle(rrod+3)
with BuildSketch(Plane.XY.offset(-dn).rotated((-45,0,0))) as endprofile:
with Locations((0,-dn)):
Circle(rrod+1)
#sweep(sections=[profile.sketch, endprofile.sketch], path=pipe)
loft()
#offset(amount=3,openings=[nozzle.faces().sort_by(Axis.X)[-1], nozzle.faces().sort_by(Axis.Z)[0]],side=Side.LEFT,)
e= nozzle.edges().sort_by(Axis.Z)[0]
fillet(e, radius=0.7)
with BuildSketch(Plane.XZ) as profile:
Circle(rrod)
with BuildSketch(Plane.XY.offset(-dn).rotated((-45,0,0))) as endprofile:
with Locations((0,-dn)):
Circle(rrod)
#sweep(sections=[profile.sketch, endprofile.sketch], path=pipe)
loft(mode=Mode.SUBTRACT)
show(e,nozzle)
# %%
with BuildPart() as nozzleplate:
tp = 2
with Locations((0,-w/2-tp/2,0)):
Box(l,tp,h)
with Locations((0,-w/2-tp,0)):
with GridLocations(r+wt+r,0,nHoles,1):
add(copy.copy(nozzle.part),rotation=(0,0,0))
with Locations((0,-w/2-tp/2,0)):
with GridLocations(r+wt+r,0,nHoles,1):
Cylinder(rrod,tp,mode=Mode.SUBTRACT,rotation=(90,0,0))
show(pumpcylinderblock, nozzleplate)
#%%
with BuildPart() as rodcollector:
loc_col=list(loc_rods)
dyc = rodlen-14-openstate*trlen +pumped*pumplen#+ loc_col[1]
loc_col[1] = dyc
loc_col[2]=-2
with Locations(tuple(loc_col)):
Box(l,10,2)
with GridLocations(r+wt+r,0,nHoles,1):
with Locations((-rrod,dyc-3,0), (rrod,dyc-3,0),(-rrod,dyc+3,0), (rrod,dyc+3,0)):
Box(rrod,3,rrod*2)
with Locations((-rrod*1.5,dyc,0), (rrod*1.5,dyc,0)):
Box(rrod,10,rrod*2)
with Locations((-rrod*4,dyc-2.5,-2), (rrod*4,dyc-2.5,-2)):
Box(4*rrod,5,2,mode=Mode.SUBTRACT)
#fillet(rodcollector.edges(Select.LAST).group_by(Axis.Z)[0].filter_by(lambda a: a.length==10), radius=1)
show(rodcollector)
#%%
with BuildPart() as cylindercollector:
dyc = rodlen-21.5 +pumped*pumplen
with Locations((0,dyc,1.7),(0,dyc,-1.7)):
Box(l,3-0.1,0.77)
with Locations((0,dyc,3),(0,dyc,-3)):
Box(l+20,10, 2)
with Locations((0,dyc,0),(0,dyc,0)):
with GridLocations(l+10,0,2,1,):
Cylinder(3.1/2,20,mode=Mode.SUBTRACT)
show(rodcollector,cylindercollector,nozzleplate,pumpcylinderblock,pumpcylinderrods,pumpcylinders)#, pumpcylindercutout)
# %%
show(rodcollector.edges(Select.LAST).group_by(Axis.Z)[0].filter_by(lambda a: a.length==10))
# %%
with BuildPart() as hopper:
with BuildSketch(Plane.XY.offset(h/2)) as down_sk:
with Locations((0,5)):
Rectangle(l-8,15)
with BuildSketch(Plane.XY.offset(160).rotated((-45,0,0))) as up_sk:
with Locations((0,50)):
Rectangle(230,200)
loft()
offset(amount=-1, openings=[hopper.faces().sort_by(Axis.Z)[0],\
hopper.faces().sort_by(Axis.Z)[-1]])
with BuildSketch(Plane.XY.offset(h/2)) as downs_sk:
Rectangle(l,w)
with Locations((0,5)):
Rectangle(l-10,20, mode=Mode.SUBTRACT)
extrude(amount=1)
with BuildSketch(Plane.XY.offset(h/2+2)) as holes:
with Locations((0,5,0)):
with GridLocations(l-6,w-6-10,2,2):
Circle(1.5)
extrude(amount=-h,mode=Mode.SUBTRACT)
#show(hopper)
show(rodcollector,cylindercollector,nozzleplate,pumpcylinderblock,pumpcylinderrods,pumpcylinders,hopper,render_joints=True)#, pumpcylindercutout)# %%
# %%
# %%
hopperblock = pumpcylinderblock.part + hopper.part
show(hopperblock)
# %%
with BuildPart() as stand:
ws = 120
wsx=60
with Locations((0,0,-h/2)):
Box(wsx,ws,4)
Box(wsx-4,ws-4,4,mode=Mode.SUBTRACT)
Box(wsx,4,4)
Box(4,ws,4)
with Locations((0,0,-1)):
Box(l+2,w+2,h+2)
Box(l,w,h, mode=Mode.SUBTRACT)
with BuildSketch(Plane.XY.offset(-(h+2)/2+3)):
RectangleRounded(l-3,w-3,3)
extrude(amount=-10, mode=Mode.SUBTRACT)
with BuildPart() as standfoot:
hs=50
ws=12
Box(ws,ws,hs)
ds=2
with Locations((-ds,-ds,0)):
Box(ws-ds,ws-ds,hs,mode=Mode.SUBTRACT)
with Locations((0,0,hs/2-2)):
Box(ws,4,4,mode=Mode.SUBTRACT)
Box(4,ws,4,mode=Mode.SUBTRACT)
#extrude(amount=4)
#offset(amount=-1.9, openings=[stand.faces().sort_by(Axis.Z)[-1]])
show(standfoot)
# %%
#export_step(hopperblock, "machineparts/hopperblock.step")
#export_step(stand.part, "machineparts/stand.step")
#export_step(standfoot.part, "machineparts/standfoot.step")
#export_step(pumpvalverod.part, "machineparts/valverod.step")
#export_step(pumpcylinder.part, "machineparts/pumpcylinder.step")
# %%
with BuildPart() as idb_holder:
Box(24,46,8)
with Locations((0,0,1)):
with GridLocations(7,7,3,6):
Cylinder(2.3,6,mode=Mode.SUBTRACT)
fillet(idb_holder.edges().filter_by(GeomType.CIRCLE), radius=1)
fillet(idb_holder.edges().filter_by(Axis.Z), radius=5)
fillet(idb_holder.edges().group_by(Axis.Z)[-1].filter_by(GeomType.LINE)[0], radius=1.5)
show(idb_holder)
# %%
export_step(idb_holder.part, "idb_holder.step")
# %%
def step_profile(stepfile="/home/hbrs/Downloads/tmp/I_slot_5_20x40.stp"):
iprofile = import_step(stepfile)
iface = iprofile.faces().sort_by(Axis.Z)[0]
def buildfn(length=50):
with BuildPart() as profile:
with BuildSketch() as profile_sk:
add(iface)
extrude(amount=length)
return Pos(0,13.3765,0)*Rot(0,0,90)*profile.part
return buildfn
iprofile=step_profile()
# %%
hp = 260
w = 240
w1 = w+40
w2 =hp+20
w3 = hp + 40
profiles= [ \
Pos(0,0,0)*Rot(0,0,90)*iprofile(hp), \
Pos(w1,0,0)*Rot(0,0,90)*iprofile(hp), \
Pos(0,w2,0)*Rot(0,0,90)*iprofile(hp), \
Pos(w1,w2,0)*Rot(0,0,90)*iprofile(hp), \
Pos(0,w2,0)*Rot(90,90,0)*iprofile(w), \
Pos(0,0,0)*Rot(90,90,0)*iprofile(w), \
Pos(-40,20,40)*Rot(-90,0,0)*iprofile(hp), \
Pos(hp,20,40)*Rot(-90,0,0)*iprofile(hp), \
Pos(0,0,w2)*Rot(-90,0,90)*iprofile(w3), \
Pos(w2,0,w2)*Rot(-90,0,90)*iprofile(w3), \
Pos(w2/2,0,60)*Rot(-90,0,90)*iprofile(w3), \
]
show(*profiles)#, hopperblock)
# %%
#ASSEMBLY
extruder = Compound(label="Extruder",children=[rodcollector.part,cylindercollector.part,nozzleplate.part,\
pumpcylinderblock.part,pumpcylinderrods.part,pumpcylinders.part,hopper.part])
extruder=Pos(120,170,168)*Rot(45,0,0)*extruder
#extruder.translate((hp/2,0,0))
show(*profiles,extruder)#, pumpcylindercutout)# %%
# %%
railpath = "/home/hbrs/Downloads/8381K54_Miniature Ball Bearing Carriage and Guide Rail.STEP"
carriagepath = "/home/hbrs/Downloads/6725K531_12 mm Wide x 200 mm Long Rail for Ball Bearing Carriage.STEP"
rail = import_step(railpath)
carriage = import_step(carriagepath)
show(carriage)
# %%
#cmpds = rail.compound()
shapes = rail.entities(topo_type=Part)
# %# %%
len(shapes)# %%
# %%
show(shapes[0])
# %%