add every older ipynb file

This commit is contained in:
Marius Unsel 2026-02-27 02:05:50 +01:00
parent 8d3459dddb
commit d678faa305
11 changed files with 4898 additions and 0 deletions

83
HeadphoneRing.ipynb Normal file
View File

@ -0,0 +1,83 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "28e3cc06-aac4-4154-94d7-000f17d4f3fa",
"metadata": {},
"source": [
"# headphone cushing ring"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5ddf6db8-8ffc-4200-940b-797d58e0e9a3",
"metadata": {},
"outputs": [],
"source": [
"import cadquery as cq\n",
"\n",
"\n",
"from jupyter_cadquery import (\n",
" versions,\n",
" show, PartGroup, Part, \n",
" get_viewer, close_viewer, get_viewers, close_viewers, open_viewer, set_defaults, get_defaults, open_viewer,\n",
" get_pick,\n",
")\n",
"from jupyter_cadquery.ocp_utils import webcol_to_cq\n",
"\n",
"from jupyter_cadquery.replay import replay, enable_replay, disable_replay\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "215f449e-c975-43fe-a826-e3904c113025",
"metadata": {},
"outputs": [],
"source": [
"headphone_ring = (cq.Workplane(\"XY\")\n",
".circle(43/2)\n",
".circle(48/2)\n",
".extrude(3)\n",
" #.faces(\"<Z\")\n",
") \\\n",
" - \\\n",
"(cq.Workplane(\"XY\")\n",
".sketch()\n",
" .circle(42.5/2, mode=\"c\", tag=\"circ\") \n",
" .select(\"circ\")\n",
" .wires()\n",
" .distribute(36)\n",
" #.close()\n",
".circle(1)\n",
" .finalize()\n",
" .extrude(10)\n",
")\n",
"\n",
"#cq.exporters.export(headphone_ring, \"headphone_ring.step\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

View File

@ -0,0 +1,4 @@
Code CAD
===
This are 3D CAD files using python and the build123d library.

845
SyncGrips.ipynb Normal file
View File

@ -0,0 +1,845 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "a0a9f44b-e8bc-49c4-b44d-4c327e51e6e8",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting auto display for cadquery Workplane and Shape\n"
]
}
],
"source": [
"import timeit\n",
"tic = timeit.default_timer()\n",
"\n",
"import cadquery as cq\n",
"from build123d import *\n",
"\n",
"from jupyter_cadquery import (\n",
" versions,\n",
" show, PartGroup, Part, \n",
" get_viewer, close_viewer, get_viewers, close_viewers, open_viewer, set_defaults, get_defaults, open_viewer,\n",
" get_pick,\n",
")\n",
"from jupyter_cadquery.ocp_utils import webcol_to_cq\n",
"\n",
"from jupyter_cadquery.replay import replay, enable_replay, disable_replay\n",
"close_viewers()\n",
"set_defaults(\n",
" cad_width=640, \n",
" height=480, \n",
" viewer=\"syncgrips\"\n",
")\n",
"cv = open_viewer(\"syncgrips\",\n",
" anchor=\"right\", \n",
" glass=True, \n",
" theme=\"dark\",\n",
" tools=True) # sets default viewer\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "13eee041-c6d5-4734-aedb-768b0be31bc4",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"100% ⋮————————————————————————————————————————————————————————————⋮ (3/3) 1.10s\n"
]
},
{
"data": {
"text/plain": [
"<cad_viewer_widget.widget.CadViewer at 0x72f00452f670>"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sensor_width = 35\n",
"wall_thickness = 3\n",
"\n",
"w1 = sensor_width + 2* wall_thickness #sensor casing\n",
"w2 = 150 #sensor center \n",
"h = 85 # total height\n",
"h1 = 20 # sensor casing height\n",
"h2 = 12\n",
"h3 = 35# sensor casing + mpu height\n",
"r = 25 #grip radius\n",
"r1 = 8\n",
"locs = ((0,h+10), (-10,h-10),(10,h-10)) #locations of screws\n",
"handle_len = w2+w1-20-6\n",
"\n",
"\n",
"with BuildPart() as slim_cutout:\n",
" with BuildSketch(Plane.XY.offset(12)) as slim_sk:\n",
" Polygon((w2/2+10,50),(w2/2-w1+10,0),\\\n",
" (0,0),(0,60),(60,90),\\\n",
" align=Align.MIN)\n",
" mirror(about=Plane.YZ)\n",
" extrude(amount=-30)\n",
" chamfer(length=12, length2=20, objects=slim_cutout.edges().group_by(Axis.Z)[-1])\n",
"\n",
"slim_cutout2 = (Rotation(0,180,0)*Location((0,0,-w1))*slim_cutout.part)\n",
"\n",
"with BuildPart() as slim_cutout_mpu:\n",
" with BuildSketch(Plane.XY.offset(12)) as slim_sk_mpu:\n",
" with Locations((-w2/2-10,0)):\n",
" Polygon((w2/2-w1+10,0),(w2/2+10,50),\\\n",
" (60,90),(0,60),(-60,90),\\\n",
" (-w2/2-10,35),(-w2/2-w1/2+55,35),(-w2/2-w1/2+55,0),\n",
" align=Align.MIN)\n",
" #mirror(about=Plane.YZ)\n",
" raw_slim_cutout_mpu = extrude(amount=-30)\n",
" chamfer(length=12, length2=20, objects=slim_cutout_mpu.edges().group_by(Axis.Z)[-1][2])\n",
" chamfer(length2=12, length=20, objects=slim_cutout_mpu.edges().group_by(Axis.Z)[-1][2])\n",
" chamfer(length2=12, length=20, objects=slim_cutout_mpu.edges().group_by(Axis.Z)[-1][6])\n",
" chamfer(length2=12, length=10, objects=slim_cutout_mpu.edges().group_by(Axis.Z)[-1][2])\n",
"\n",
"with BuildPart() as slim_cutout2_mpu:\n",
" add(Location((0,0,47))*raw_slim_cutout_mpu)\n",
" chamfer(length=12, length2=20, objects=slim_cutout2_mpu.edges().group_by(Axis.Z)[0][2])\n",
" chamfer(length2=12, length=20, objects=slim_cutout2_mpu.edges().group_by(Axis.Z)[0][2])\n",
" chamfer(length2=12, length=20, objects=slim_cutout2_mpu.edges().group_by(Axis.Z)[0][6])\n",
" chamfer(length2=12, length=10, objects=slim_cutout2_mpu.edges().group_by(Axis.Z)[0][2])\n",
"\n",
"with BuildPart() as inner_cutout:\n",
" with BuildSketch(Plane.XY.offset(w1-10)) as handle_sk:\n",
" with Locations((0,h)):\n",
" Circle(r*2.4)\n",
" extrude(amount=30)\n",
" \n",
"with BuildPart() as screwholes:\n",
" with BuildSketch() as screwholes_sk:\n",
" with Locations(*locs):\n",
" Circle(1.5)\n",
" extrude(amount=12)\n",
" with BuildSketch() as screwholes_sk1:\n",
" with Locations(*locs):\n",
" Circle(3)\n",
" extrude(amount=2)\n",
" \n",
"r_sens = 6\n",
" \n",
"with BuildPart() as sensor_cutout:\n",
" with BuildSketch(Plane.XZ) as sensor_sk1:\n",
" d = 0\n",
" with Locations((w2/2+d,w1/2),(-w2/2-d,w1/2)):\n",
" Rectangle(sensor_width-4, sensor_width-4)\n",
" sensor_space = extrude(amount=-14)\n",
" faces = (sensor_space.edges().group_by(Axis.Y)[-1] | Axis.Z)\n",
" chamfer(objects=faces, length=6)\n",
" \n",
" with BuildSketch(Plane.XZ) as sensor_sk:\n",
" with Locations((w2/2,w1/2),(-w2/2,w1/2)):\n",
" RectangleRounded(sensor_width, sensor_width, r_sens)\n",
" extrude(amount=-10)\n",
" \n",
" \n",
"with BuildPart() as snapfit_cutout:\n",
" d = 2\n",
" l = 10\n",
" hc=3\n",
" with BuildSketch(Plane.XY.offset(w1/2-l/2)) as snap_sk:\n",
" with Locations((w2/2+w1/2-1.5*d,hc),(-w2/2-w1/2+1.5*d,hc)):\n",
" Rectangle(d, d, rotation=45)\n",
" extrude(amount=l)\n",
" \n",
"\n",
"with BuildPart() as cable_paths:\n",
" with BuildSketch(Plane.XZ) as sensor_sk:\n",
" with Locations((w2/2-w1/2+2,w1/2),(-w2/2+w1/2-2,w1/2)):\n",
" Rectangle(2, 4)\n",
" extrude(amount=-12)\n",
" \n",
"with BuildPart() as cable_paths_mpu:\n",
" with BuildSketch(Plane.XZ) as sensor_sk:\n",
" with Locations((w2/2-w1/2+2,w1/2)):\n",
" Rectangle(2, 4)\n",
" extrude(amount=-12)\n",
" with BuildSketch(Plane.XZ) as sensor_sk:\n",
" with Locations((-w2/2+w1/2-2,w1/2)):\n",
" Rectangle(2, 4)\n",
" extrude(amount=-22)\n",
" \n",
"with BuildPart() as tunnels: \n",
" with BuildLine() as tunnel_right:\n",
" Spline((w2/2-w1/2+1,8.5,w1/2),(0,h-r+3,w1/2), tangents=((-0.1,0.05,0),(0,1,0)))\n",
" with BuildSketch(Plane.YZ.offset(w2/2-w1/2+1)) as tunnel_hole:\n",
" with Locations((8.5, w1/2)):\n",
" Circle(3)\n",
" tunnel = sweep(path=tunnel_right, mode=Mode.ADD)\n",
" mirror(objects=tunnel, about=Plane.YZ)\n",
"\n",
"with BuildPart() as tunnels_mpu: \n",
" with BuildLine() as tunnel_right:\n",
" Spline((-w2/2-w1/2+54, h3-15+1.5, w1/2),(0, h-r+3, w1/2), tangents=((0.1,0.05,0),(0,1,0)))\n",
" with BuildSketch(Plane.YZ.offset(-w2/2-w1/2+54)) as tunnel_mpu_r_hole:\n",
" with Locations((h3-15+1.5, w1/2)):\n",
" Circle(3)\n",
" tunnel = sweep(path=tunnel_right, mode=Mode.ADD)\n",
" with BuildLine() as tunnel_left:\n",
" Spline((w2/2-w1/2,8.5,w1/2),(0,h-r+3,w1/2), tangents=((-0.1,0.05,0),(0,1,0)))\n",
" with BuildSketch(Plane.YZ.offset(w2/2-w1/2+1)) as tunnel_mpu_l_hole:\n",
" with Locations((8.5, w1/2)):\n",
" Circle(3)\n",
" sweep(path=tunnel_left, mode=Mode.ADD)\n",
" \n",
"mpu_width = 28\n",
"mpu_len = 53\n",
"mpu_h = 15\n",
"with BuildPart() as mpu_cutout:\n",
" lift = 20\n",
" with BuildSketch(Plane.XZ.offset(-h3-lift)) as mpu_sk:\n",
" with Locations((-w2/2-w1/2+mpu_len/2+2, w1/2)):\n",
" RectangleRounded(mpu_len,28, 4)\n",
" extrude(amount=lift+mpu_h)\n",
" \n",
"with BuildPart() as mpu_standoff:\n",
" standoff_len = 10\n",
" x = -(w2/2+w1/2-mpu_len-1)\n",
" y1 = w1/2-mpu_width/2+standoff_len/2\n",
" y2 = w1/2+mpu_width/2-standoff_len/2\n",
" with BuildSketch(Plane.XZ.offset(-h3+mpu_h)) as standoff_sk:\n",
" with Locations((x, y1),\\\n",
" (x, y2)):\n",
" Rectangle(2,standoff_len)\n",
" extrude(amount=-7)\n",
" \n",
"with BuildPart() as grip:\n",
" with BuildSketch() as base_sk:\n",
" Polygon((w2/2+w1/2,0),(w2/2-w1/2,0),\\\n",
" (w2/2-w1/2-20,h2),(0,h2),(0,h+2.3*r),\\\n",
" (w2/2-w1/2, h1+10),(w2/2+w1/2, h1),\\\n",
" align=Align.MIN)\n",
" mirror(about=Plane.YZ)\n",
" fillet(radius=r,objects=base_sk.vertices().group_by(Axis.Y)[-1])\n",
" fillet(radius=r*2,objects=base_sk.vertices().group_by(Axis.Y)[3])\n",
" fillet(radius=10,objects=base_sk.vertices().group_by(Axis.Y)[2])\n",
" fillet(radius=2*r,objects=base_sk.vertices().group_by(Axis.Y)[1])\n",
" extrude(amount=w1)\n",
" fillet(radius=r1, objects=grip.edges().group_by(Axis.Z)[0].sort_by(Axis.Y)[-1])\n",
" with BuildSketch(Plane.XY.offset(10)) as pole_cutout:\n",
" with Locations((0,h)):\n",
" Circle(r+0.5)\n",
" extrude(amount=100, mode=Mode.SUBTRACT)\n",
" fillet(radius=r1, objects=grip.edges().group_by(Axis.Y)[-6])\n",
" fillet(radius=r1, objects=grip.edges().group_by(Axis.X)[0].sort_by(Axis.Z)[-1])\n",
" add(screwholes,mode=Mode.SUBTRACT)\n",
" add(sensor_cutout,mode=Mode.SUBTRACT)\n",
" add(cable_paths, mode=Mode.SUBTRACT)\n",
" add(slim_cutout,mode=Mode.SUBTRACT)\n",
" add(slim_cutout2,mode=Mode.SUBTRACT)\n",
" add(tunnels,mode=Mode.SUBTRACT)\n",
" add(inner_cutout,mode=Mode.SUBTRACT)\n",
" add(snapfit_cutout, mode=Mode.SUBTRACT)\n",
" \n",
"with BuildPart() as grip_mpu:\n",
" with BuildSketch() as base_sk:\n",
" with Locations((-w2/2-w1/2,0)):\n",
" Polygon((w2/2+w1/2,0),(w2/2-w1/2,0),\\\n",
" (w2/2-w1/2-20,h2),(-w2/2+w1/2+20,h2),(-w2/2+w1/2,0),(-w2/2-w1/2,0),\\\n",
" (-w2/2-w1/2,h3),(-w2/2-w1/2+55,h3+1),\\\n",
" #(-r,h),\\\n",
" (-6.5,h+2.77*r),\\\n",
" #(r,h),\\\n",
" (w2/2-w1/2, h1+10),(w2/2+w1/2, h1),\\\n",
" \n",
" align=Align.MIN)\n",
" #mirror(about=Plane.YZ)\n",
" fillet(radius=r,objects=base_sk.vertices().group_by(Axis.Y)[-1])\n",
" fillet(radius=r,objects=base_sk.vertices().group_by(Axis.Y)[5])\n",
" fillet(radius=r*2,objects=base_sk.vertices().group_by(Axis.Y)[3])\n",
" fillet(radius=10,objects=base_sk.vertices().group_by(Axis.Y)[2])\n",
" fillet(radius=2*r,objects=base_sk.vertices().group_by(Axis.Y)[1])\n",
" extrude(amount=w1)\n",
" #\n",
" with BuildSketch(Plane.XY.offset(10)) as pole_cutout:\n",
" with Locations((0,h)):\n",
" Circle(r+.5)\n",
" extrude(amount=100, mode=Mode.SUBTRACT)\n",
" fillet(radius=r1, objects=grip_mpu.edges().sort_by(Axis.Y)[-7])\n",
" fillet(radius=r1, objects=grip_mpu.edges().sort_by(Axis.Y)[-6])\n",
" fillet(radius=r1, objects=grip_mpu.edges().group_by(Axis.Z)[0].sort_by(Axis.Y)[-1])\n",
" fillet(radius=r1, objects=grip_mpu.edges().group_by(Axis.Z)[-1].sort_by(Axis.Y)[-1])\n",
" add(screwholes, mode=Mode.SUBTRACT)\n",
" add(sensor_cutout, mode=Mode.SUBTRACT)\n",
" add(cable_paths_mpu, mode=Mode.SUBTRACT)\n",
" add(slim_cutout_mpu, mode=Mode.SUBTRACT)\n",
" add(slim_cutout2_mpu, mode=Mode.SUBTRACT)\n",
" add(tunnels_mpu, mode=Mode.SUBTRACT)\n",
" #usb slot\n",
" with BuildSketch(Plane.YZ.offset(-w2/2-w1/2)) as usb_sk:\n",
" with Locations((h3-6, w1/2)):\n",
" SlotCenterToCenter(6,4, rotation=90)\n",
" extrude(amount=10, mode=Mode.SUBTRACT)\n",
" add(mpu_cutout,mode=Mode.SUBTRACT)\n",
" add(inner_cutout,mode=Mode.SUBTRACT)\n",
" add(mpu_standoff)\n",
" add(snapfit_cutout, mode=Mode.SUBTRACT)\n",
"\n",
" \n",
"with BuildPart() as nut_m3_slot:\n",
" with BuildSketch() as base_sk:\n",
" sw = 3.3\n",
" RegularPolygon(sw,6)\n",
" with Locations((50,0)):\n",
" RegularPolygon(sw,6)\n",
" make_hull()\n",
" extrude(amount=3)\n",
"\n",
"with BuildPart() as handle:\n",
" with BuildSketch(Plane.XY.offset(10)) as handle_sk:\n",
" with Locations((0,h)):\n",
" Circle(r)\n",
" extrude(amount=handle_len)\n",
" with BuildSketch(Plane.XY.offset(10)) as screwholes_sk:\n",
" with Locations(*locs):\n",
" Circle(1.5)\n",
" extrude(amount=30, mode=Mode.SUBTRACT)\n",
" with BuildSketch(Plane.XY.offset(10+handle_len)) as screwholes_sk:\n",
" with Locations(*locs):\n",
" Circle(1.5)\n",
" extrude(amount=-30, mode=Mode.SUBTRACT)\n",
" # add tunnel\n",
" with BuildLine(Plane.YZ) as tnl:\n",
" rr=10\n",
" j = JernArc((h-r-0.5,w1/2), (1,0), arc_size=90, radius=rr)\n",
" l = Line(j@1, j@1+(0,handle_len-w1/2-2*rr))\n",
" JernArc(l@1, (0,1), arc_size=90, radius=rr)\n",
" with BuildSketch(Plane.XZ.offset(-h+r+0.5)) as tunnel_hole:\n",
" with Locations((0, w1/2)):\n",
" Circle(3)\n",
" sweep(path=tnl, mode=Mode.SUBTRACT)\n",
" # add nut slots \n",
" with Locations((0,10+h,20), (0,10+h, handle_len),\\\n",
" (10,h-10,20), (10,h-10, handle_len)):\n",
" add(nut_m3_slot, mode=Mode.SUBTRACT)\n",
" with Locations((0,10+h,20), (0,10+h, handle_len),\\\n",
" (10,h-10,20), (10,h-10, handle_len)):\n",
" add(nut_m3_slot, mode=Mode.SUBTRACT)\n",
" with Locations((-10,h-10,20), (-10,h-10, handle_len)):\n",
" add(Rotation(0,0,180)*nut_m3_slot.part, mode=Mode.SUBTRACT)\n",
" \n",
" \n",
"grip = Rotation(0,180,0)*Location((0,0,-handle_len-20))*grip.part\n",
"#show(grip_mpu, tunnels_mpu, transparent=True,reset_camera=False) \n",
"#show(grip,transparent=True,reset_camera=False)\n",
"#show(grip_mpu,mpu_standoff, transparent=True, reset_camera=False)\n",
"#show(grip, inner_cutout, transparent=True,reset_camera=False)\n",
"#show(tunnel_hole,tnl,grip_mpu,Rotation(0,180,0)*Location((0,0,-handle_len-20))*grip.part, handle,transparent=True,reset_camera=False)\n",
"show( grip, grip_mpu, handle,transparent=True, reset_camera=False)\n",
"#show(slim_cutout_mpu, reset_camera=False)\n",
"#show(grip, sensor_cutout, tunnel_right,transparent=True,reset_camera=False)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "ce464618-0d41-45ab-b17b-9ec93350721e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"100% ⋮————————————————————————————————————————————————————————————⋮ (2/2) 0.06s\n"
]
},
{
"data": {
"text/plain": [
"<cad_viewer_widget.widget.CadViewer at 0x7cb5ddd01a20>"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"with BuildPart() as sensorfoot_housing:\n",
" with BuildSketch(Plane.XZ) as housing_sk:\n",
" with Locations((w2/2, w1/2)):\n",
" RectangleRounded(sensor_width-0.0, sensor_width-0.0, r_sens+0.5)\n",
"\n",
" extrude(amount=-6)\n",
" add(Location((-0.25,0,0))*snapfit_cutout.part)\n",
" opening=sensorfoot_housing.faces().sort_by(Axis.Y)[-1]\n",
" \n",
" offset(amount=-1, openings=opening, side=Side.RIGHT)\n",
" \n",
" with Locations((w2/2,-2,w1/2)):\n",
" Cone(bottom_radius=15, top_radius=12, height=6, rotation=(90,0,0), mode=Mode.SUBTRACT)\n",
" with Locations((w2/2-sensor_width/2, 6, w1/2)):\n",
" Box(7,10,7, mode=Mode.SUBTRACT)\n",
" \n",
"\n",
"with BuildPart() as sensorfoot_bbox:\n",
" with BuildSketch(Plane.XZ) as housing_sk:\n",
" with Locations((w2/2, w1/2)):\n",
" RectangleRounded(sensor_width-4, sensor_width-4, r_sens+0.5)\n",
" extrude(amount=20, both=True)\n",
" \n",
"x_sens = 14.25\n",
"with BuildPart() as sensorfoot:\n",
" with Locations((w2/2,-1.5,w1/2)):\n",
" Cone(bottom_radius=15, top_radius=12, height=6, rotation=(90,0,0), mode=Mode.ADD)\n",
" with Locations((w2/2,2.5,w1/2)):\n",
" Cone(bottom_radius=10, top_radius=15, height=2, rotation=(90,0,0), mode=Mode.ADD)\n",
" with Locations((w2/2-sensor_width/2+x_sens, 3.5, w1/2)):\n",
" Box(12,5,30, mode=Mode.SUBTRACT)\n",
" with Locations((w2/2-sensor_width/2+x_sens, 0, w1/2)):\n",
" Cone(bottom_radius=3, top_radius=2, height=2, rotation=(90,0,0), mode=Mode.SUBTRACT)\n",
" \n",
" #with Locations((w2/2-sensor_width/2+x_sens,2,w1/2)):\n",
" # Box(11,2,30)\n",
" with Locations((w2/2-sensor_width/2+5,2,w1/2), (w2/2+sensor_width/2-5,2,w1/2)):\n",
" Box(3,2,30)\n",
" add(sensorfoot_bbox, mode=Mode.INTERSECT)\n",
" \n",
"\n",
"\n",
"show( sensorfoot, sensorfoot_housing,transparent=True,reset_camera=False)"
]
},
{
"cell_type": "code",
"execution_count": 85,
"id": "03be83e0-4493-44b5-b38a-85c8007838c5",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"100% ⋮————————————————————————————————————————————————————————————⋮ (2/2) 0.07s\n"
]
},
{
"data": {
"text/plain": [
"<cad_viewer_widget.widget.CadViewer at 0x7cb5ddd01a20>"
]
},
"execution_count": 85,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"with BuildPart() as mpu_cover:\n",
" lift = 20\n",
" th = 1.\n",
" with BuildSketch(Plane.XZ.offset(-h3)) as mpu_sk:\n",
" with Locations((-w2/2-w1/2+mpu_len/2+2, w1/2)):\n",
" RectangleRounded(mpu_len,28, 4)\n",
" extrude(amount=1)\n",
" with BuildSketch(mpu_cover.faces().sort_by(Axis.Y)[0]) as stand_sk:\n",
" with Locations((0,-14+th/2), (0,14-th/2)):\n",
" Rectangle(20,th)\n",
" extrude(amount=14)\n",
" buttonlocs = ((-mpu_len/2+5,-t), (-mpu_len/2+5,t))\n",
" with BuildSketch(mpu_cover.faces().sort_by(Axis.Y)[-1]) as holes_sk:\n",
" t = 9\n",
" rr = 2\n",
" dd = 6\n",
" ddd = 0.4\n",
" with Locations(*buttonlocs):\n",
" with Locations((1,0)):\n",
" RectangleRounded(dd+4,dd,rr)\n",
" RectangleRounded(dd+4-ddd,dd-ddd,rr-ddd/2, mode=Mode.SUBTRACT)\n",
" with Locations((5,0)):\n",
" Rectangle(6,2, mode=Mode.SUBTRACT)\n",
" extrude(amount=-2, mode=Mode.SUBTRACT)\n",
" with BuildSketch(mpu_cover.faces().sort_by(Axis.Y)[-1]) as buttons_sk:\n",
" with Locations(*buttonlocs):\n",
" RectangleRounded(5,5,1.5)\n",
" extrude(amount=-5)\n",
" with BuildSketch(mpu_cover.faces().sort_by(Axis.Y)[-1]) as buttons_sk:\n",
" with Locations((2.5,0)):\n",
" Rectangle(32.5,19)\n",
" extrude(amount=-3, mode=Mode.SUBTRACT)\n",
" \n",
" \n",
"show(grip_mpu,mpu_cover,transparent=True,reset_camera=False)"
]
},
{
"cell_type": "code",
"execution_count": 86,
"id": "8d3ecdf0-94b8-4e65-95f9-785784f7cf57",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 86,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"assert False\n",
"foldername = \"SyncGripSTEP/\"\n",
"export_step(sensorfoot.part,foldername+\"sensorfoot.step\")\n",
"export_step(sensorfoot_housing.part,foldername+\"sensorfoot-housing.step\")\n",
"export_step(grip,foldername+\"grip.step\")\n",
"export_step(grip_mpu.part,foldername+\"grip-mpu.step\")\n",
"export_step(handle.part,foldername+\"handle.step\")\n",
"export_step(mpu_cover.part, foldername+\"mpu_cover.step\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4ec1e400-2779-4f43-94c5-07a8d18c0023",
"metadata": {},
"outputs": [],
"source": [
"with BuildPart() as nut_m3:\n",
" with BuildSketch() as base_sk:\n",
" RegularPolygon(3.005,6)\n",
" extrude(amount=2.4)\n",
" chamfer(nut_m3.edges(), length=0.2)\n",
" Cylinder(1.5,6, mode=Mode.SUBTRACT)\n",
" \n",
"\n",
" \n",
" \n",
"show(nut_m3, nut_m3_slot, transparent=True, reset_camera=False)"
]
},
{
"cell_type": "markdown",
"id": "1693d74f-3a6d-4206-91cd-51f126a8285d",
"metadata": {},
"source": [
"# export SVG"
]
},
{
"cell_type": "code",
"execution_count": 87,
"id": "09205ef3-d30d-4da8-a2f0-0f82e397b7cd",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"WARNING, exporting non-planar shape to 2D format.\n",
" This is probably not what you want.\n",
" 1820 points found outside the XY plane.\n"
]
}
],
"source": [
"foldername = \"SyncGripSVG/\"\n",
"\n",
"fullgrip = Compound(children=[grip, grip_mpu.part, handle.part])\n",
"grips = (Location((-200,0,0))*mirror(fullgrip, about=Plane.YZ)) + (Location((200,0,0))*Rotation(0,0,0)*fullgrip)\n",
"\n",
"\n",
"exporter = ExportSVG(unit= Unit.MM, \\\n",
" scale= 1, \\\n",
" margin= 0, \\\n",
" fit_to_stroke= True, \\\n",
" precision = 6, \\\n",
" fill_color= None, \\\n",
" line_weight = 0.09)\n",
"exporter.add_layer(\"Layer 1\", fill_color=(0, 0, 0), line_color=(255, 255, 255))\n",
"exporter.add_shape(grip, layer=\"Layer 1\")\n",
"exporter.write(foldername+\"grip.svg\")"
]
},
{
"cell_type": "code",
"execution_count": 110,
"id": "38da9b1c-8880-4ba2-abef-f9ae0bb3ddb5",
"metadata": {},
"outputs": [],
"source": [
"\n",
"def drawSVG(part,view_port_origin, filename):\n",
" visible, hidden = part.project_to_viewport(view_port_origin, viewport_up=(0,1,0))\n",
" max_dimension = max(*Compound(children=visible + hidden).bounding_box().size)\n",
" exporter = ExportSVG(scale=100 / max_dimension,\\\n",
" fill_color=(12,12,12),\n",
" line_weight=1)\n",
" exporter.add_layer(\"Visible\",\\\n",
" line_weight=0.3,\\\n",
" fill_color=None,\\\n",
" line_color=(75,75,75))\n",
" exporter.add_layer(\"Hidden\", \\\n",
" line_color=(144,44,77), \\\n",
" line_weight=0.2,\\\n",
" line_type=LineType.ISO_DOT)\n",
" exporter.add_shape(visible, layer=\"Visible\")\n",
" #exporter.add_shape(hidden, layer=\"Hidden\")\n",
" exporter.write(foldername+filename+\".svg\")"
]
},
{
"cell_type": "code",
"execution_count": 90,
"id": "068bc1c1-0d80-43cc-8773-e0aaba5a3772",
"metadata": {},
"outputs": [],
"source": [
"view_port_origin=(-200, 85, 250)\n",
"fullgrip = Compound(children=[grip, grip_mpu.part, handle.part])\n",
"drawSVG(fullgrip,view_port_origin, \"fullgrip\")"
]
},
{
"cell_type": "code",
"execution_count": 121,
"id": "fa7fbea4-6725-4b48-aca0-748084e43833",
"metadata": {},
"outputs": [],
"source": [
"view_port_origin=(w2/2, 90, -100)\n",
"#sensorfoot_explode = Compound(children=[Location((0,30,0))*sensorfoot.part, sensorfoot_housing.part])\n",
"sensorfoot_normal = Location((0,0,70))*Compound(children=[sensorfoot.part, sensorfoot_housing.part])\n",
"#drawout = Compound(children=[sensorfoot_explode, sensorfoot_normal])\n",
"drawSVG(sensorfoot_normal, view_port_origin, \"sensorfoot\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b5e75454-c676-4ba7-9c4b-156cfe07c475",
"metadata": {},
"outputs": [],
"source": [
"rf = 30.5/2 # radius of a flask\n",
"nrows = 2\n",
"ncols = 3\n",
"\n",
"t = 2 # wall thickness\n",
"ti = 0.4 # wall thickness inbetween flasks\n",
"df = rf * 2 + ti\n",
"flask_locs = list((i*df,j*df) for i in range(ncols) for j in range(nrows))\n",
"\n",
"w = ncols*df-ti+2*t\n",
"d = nrows*df-ti+2*t\n",
"h = 25\n",
"\n",
"dd = rf+0.2\n",
"cuts_locs = list(((i+0.5)*df, j) for i in range(ncols-1) for j in [-rf-t-dd, d-rf-t+dd])\n",
"cuts1_locs = list((j,(i+0.5)*df) for i in range(nrows-1) for j in [-rf-t-dd, w-rf-t+dd])\n",
"\n",
"\n",
"with BuildPart() as flasks_case:\n",
" with BuildSketch() as case_sk:\n",
" with Locations((-rf-t,-rf-t)):\n",
" RectangleRounded(w, d, rf+t, align=Align.MIN)\n",
" with Locations(*cuts_locs):\n",
" Circle(rf+t, mode=Mode.SUBTRACT)\n",
" with Locations(*cuts1_locs):\n",
" Circle(rf+t, mode=Mode.SUBTRACT)\n",
" \n",
" \n",
" extrude(amount=h) \n",
" fillet(flasks_case.edges()|Axis.Z,radius=rf)\n",
" with BuildSketch() as flasks_sk:\n",
" with Locations(*flask_locs):\n",
" Circle(rf) \n",
" extrude(amount=h-t, mode=Mode.SUBTRACT)\n",
" with BuildSketch() as inner_sk:\n",
" with Locations((-rf+t, -rf+t )):\n",
" RectangleRounded(w-4*t, d-4*t, rf, align=Align.MIN)\n",
" extrude(amount=h-t-8, mode=Mode.SUBTRACT)\n",
" fillet(flasks_case.edges().sort_by(Axis.Z)[0], radius=1)\n",
" \n",
"show(flasks_case, reset_camera=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "316a54b1-f07f-4b7c-88d2-288ee0f45306",
"metadata": {},
"outputs": [],
"source": [
"flasks_case.part.export_step(\"flasks.step\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "864538fc-57f4-4c15-bf15-7e76b5b0b5d4",
"metadata": {},
"outputs": [],
"source": [
"from math import sin, cos, asin,pi\n",
"\n",
"def arcd(y):\n",
" return 2*asin(y*0.5)\n",
"\n",
"def secant_phi(length, radius):\n",
" # calculates tht angle of a secant on a circle\n",
" # with given length and the radius of a circle\n",
" return arcd(length/radius)\n",
"\n",
"dt = 2 # how thick the holder should be\n",
"ds = 6 # how big the step at the end of the gripper should be\n",
"r1 = 15.25-dt # the radius of the hole of the weight plate\n",
"h1 = 22 # the height of the gripper\n",
"\n",
"\n",
"dphi = 15./180.*pi # degree of flex\n",
"# how big do i need to make the radius so when it is flexed, \n",
"# the original radius and angle is reached?\n",
"# when flexed, both grippers should be parallel\n",
"phi_flexed_cutout = secant_phi(r1*2 , r)\n",
"phi_flexed = 2*pi - phi_flexed_cutout\n",
"phi_unflexed = phi_flexed - dphi\n",
"# now we need the circumfence of that arc and the new radius\n",
"circ_flexed = 2*(phi_flexed)*r\n",
"r_unflexed = circ_flexed/(2*(phi_unflexed))\n",
"\n",
"r2 = r_unflexed / 2.0\n",
"phi0 = ((2*pi- phi_flexed)/2) - pi/2\n",
"\n",
"p1 = (r_unflexed * cos( phi0), r_unflexed * sin( phi0))\n",
"p2 = (p1[0] +h1*sin(dphi), p1[1]-h1*cos(dphi))\n",
"p3 =(p2[0] + ds *cos(dphi), p2[1]+ ds *sin(dphi))\n",
"\n",
"\n",
"with BuildPart() as calibration_plate_gripper:\n",
" with BuildSketch() as profile_sketch:\n",
" with BuildLine() as line_builder:\n",
" #a = CenterArc(center=(0,0),\\\n",
" # radius=r_unflexed, \\\n",
" # start_angle=phi0, \\\n",
" # arc_size=circ_flexed/2)\n",
" RadiusArc((0,r_unflexed), p1, r_unflexed)\n",
" line = Polyline(\\\n",
" p1,\\\n",
" p2,\\\n",
" p3,\\\n",
" close=False)\n",
" \n",
" \n",
" ##line1 = fillet(radius=6,objects=line.vertices())\n",
" w = offset(amount=dt, side=Side.LEFT) \n",
" \n",
" \n",
" make_face()\n",
" extrude(amount=7)\n",
" mirror(about=Plane.YZ)\n",
" \n",
" \n",
"show(calibration_plate_gripper, Cylinder(25,100),reset_camera=False, transparent=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9cf1c8e8-adff-4fb0-8453-73e5dbd54c8f",
"metadata": {},
"outputs": [],
"source": [
"foldername = \"SyncGripSTEP/\"\n",
"\n",
"calibration_plate_gripper.part.export_step(foldername+\"calibration_plate_gripper.step\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "32b7d490-319f-4aa7-8fa4-056bad961d6f",
"metadata": {},
"outputs": [],
"source": [
"phi_unflexed"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "669af16d-c398-4e9c-a048-5da88fc54efc",
"metadata": {},
"outputs": [],
"source": [
"phi_flexed"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "eb1e25ab-df4d-41a3-b5da-f2952efb8d32",
"metadata": {},
"outputs": [],
"source": [
"phi0"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a5fd2ce3-b39f-4668-89d5-d1810172cdca",
"metadata": {},
"outputs": [],
"source": [
"circ_flexed"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7f02d3a1-4bf3-4dce-ab79-e8cc97ccdf06",
"metadata": {},
"outputs": [],
"source": [
"offset?"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ee4e8291-b51d-403a-a589-e48a0710e77c",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

308
Untitled.ipynb Normal file
View File

@ -0,0 +1,308 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "476d2190-282f-4bb3-a9c0-d9e352235d18",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting auto display for cadquery Workplane and Shape\n"
]
}
],
"source": [
"import timeit\n",
"tic = timeit.default_timer()\n",
"\n",
"import cadquery as cq\n",
"from build123d import *\n",
"\n",
"from jupyter_cadquery import (\n",
" versions,\n",
" show, PartGroup, Part, \n",
" get_viewer, close_viewer, get_viewers, close_viewers, open_viewer, set_defaults, get_defaults, open_viewer,\n",
" get_pick,\n",
")\n",
"from jupyter_cadquery.ocp_utils import webcol_to_cq\n",
"\n",
"from jupyter_cadquery.replay import replay, enable_replay, disable_replay\n",
"close_viewers()\n",
"set_defaults(\n",
" cad_width=640, \n",
" height=480, \n",
" viewer=\"syncgrips_v2\"\n",
")\n",
"cv = open_viewer(\"zementmischer\",\n",
" anchor=\"right\", \n",
" glass=True, \n",
" theme=\"dark\",\n",
" tools=True) # sets default viewer\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "27291ccc-aebc-4828-b447-19603567caa8",
"metadata": {},
"outputs": [],
"source": [
"with BuildPart() as bearing:\n",
" with BuildSketch() as sk:\n",
" Circle(11)\n",
" Circle(4, mode=Mode.SUBTRACT)\n",
" extrude(amount=7)\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "016a58c2-a252-4d58-9617-4626b02e56c5",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"100% ⋮————————————————————————————————————————————————————————————⋮ (2/2) 0.32s\n"
]
},
{
"data": {
"text/plain": [
"<cad_viewer_widget.widget.CadViewer at 0x7394290d26e0>"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"with BuildPart() as holder:\n",
" with BuildSketch(Plane.XY.offset(0)) as slim_sk:\n",
" Polygon((-5,0),(5,0),(0,5), \\\n",
" align=Align.CENTER)\n",
" with BuildSketch(Plane.XY.offset(120)) as slim_sk:\n",
" Polygon((-10,0),(10,0),(0,10), \\\n",
" align=Align.CENTER)\n",
" #mirror(about=Plane.YZ)\n",
" #extrude(amount=-30)\n",
" #sweep()\n",
" loft()\n",
" \n",
"show(holder,bearing, reset_camera=False)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "46db8226-8b74-4c63-bc48-83cc40ae79da",
"metadata": {},
"outputs": [],
"source": [
"d = 10.2\n",
"d1 = 11.3\n",
"l = 38.7\n",
"l1 = 39.7\n",
"l2 = 63\n",
"b = 0.5\n",
"h = 1.8\n",
"h1 = 0.8\n",
"with BuildPart() as camcap:\n",
" with BuildSketch() as sk:\n",
" SlotCenterToCenter(l2-d1+2*b,d1+2*b)\n",
" extrude(amount=h+b)\n",
" f = camcap.faces().sort_by(Axis.Z)[0]\n",
" with BuildSketch(f) as sk1:\n",
" with Locations((-(l2-l1)/2-b,0)):\n",
" SlotCenterToCenter(l-d+b,d)\n",
" extrude(amount=-h, mode=Mode.SUBTRACT)\n",
" with BuildSketch(f) as sk2:\n",
" with Locations((-(l2-l1)/2-b,0)):\n",
" SlotCenterToCenter(l1-d1+b,d1)\n",
" extrude(amount=-h1, mode=Mode.SUBTRACT)\n",
" with BuildSketch(f) as sk3:\n",
" with Locations((-(l2)/2+49.7,0)):\n",
" Circle(9.5/2)\n",
" extrude(amount=-h1, mode=Mode.SUBTRACT)\n",
" fillet(camcap.edges().sort_by(Axis.Z)[-1], radius=0.5)\n",
"camcap"
]
},
{
"cell_type": "code",
"execution_count": 57,
"id": "e16ea143-59f6-4366-9a51-9473eefdce3a",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/tmp/ipykernel_33/1870784379.py:1: DeprecationWarning: Use the `export_step` function instead\n",
" camcap.part.export_step(\"camcap_note10.step\")\n"
]
},
{
"data": {
"text/plain": [
"<IFSelect_ReturnStatus.IFSelect_RetDone: 1>"
]
},
"execution_count": 57,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"camcap.part.export_step(\"camcap_note10.step\")"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "a33280cb-fc8c-4cb7-bf4b-6a707534f02b",
"metadata": {},
"outputs": [],
"source": [
"hs = 9.5\n",
"with BuildPart() as frontcamcap:\n",
" with BuildSketch() as sk:\n",
" Circle(8)\n",
" with Locations((0,8)):\n",
" Rectangle(20, 3)\n",
" make_hull()\n",
" extrude(amount=b)\n",
" chamfer(frontcamcap.edges().sort_by(Axis.Z)[0], length=b*0.9)\n",
" with Locations((0,0,hs)):\n",
" add(frontcamcap.part.mirror(Plane.XY))\n",
" with Locations((0,8+1.5+b/2,hs/2)):\n",
" Box(20,b, hs)\n",
" \n",
" \n",
"frontcamcap"
]
},
{
"cell_type": "code",
"execution_count": 51,
"id": "403932d5-0058-4480-89de-0ec633436000",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"export_step(frontcamcap.part, \"frontcamcap.step\")"
]
},
{
"cell_type": "code",
"execution_count": 64,
"id": "04750084-62c3-4bfa-8c5a-d172b4e70451",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<cad_viewer_widget.widget.CadViewer at 0x7394290d26e0>"
]
},
"execution_count": 64,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"with BuildPart() as akaso_adapter:\n",
" Box(8.5, 70, 20)\n",
" #fillet(akaso_adapter.edges()|Axis.Z, radius=2)\n",
" with Locations((4,0,16)):\n",
" b = Box(16, 14.5, 20)\n",
" with Locations((0,0,3)):\n",
" Cylinder(5.5/2,20, rotation=(90,0,0), mode=Mode.SUBTRACT)\n",
" edgs = b.faces().sort_by(Axis.Z)[-1].edges() | Axis.Y\n",
" fillet(edgs, radius=7.7)\n",
" with Locations((4,0,14)):\n",
" with Locations((0,-2.7*1,2),(0,2.7*1,2)):\n",
" Box(18, 2.7,20, mode=Mode.SUBTRACT)\n",
" fs = akaso_adapter.faces().group_by(Axis.X)[-1].edges().group_by(Axis.Z)[0]\n",
" fillet(fs, radius=7.7)\n",
"show(akaso_adapter, reset_camera=False)"
]
},
{
"cell_type": "code",
"execution_count": 65,
"id": "c30c3133-590e-4f13-be94-eb129e93775f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 65,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"export_step(akaso_adapter.part, \"akaso.step\")"
]
},
{
"cell_type": "code",
"execution_count": 60,
"id": "ca641769-775b-4ce8-99a1-211dcc221ab5",
"metadata": {},
"outputs": [],
"source": [
"akaso_adapter.faces().group_by(Axis.X)[-1].edges().group_by(Axis.Z)[0]# | Axis.Y"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "729fa291-80fa-4aa7-ac9b-6f15a887409a",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

333
dempf.ipynb Normal file
View File

@ -0,0 +1,333 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "f4f3de42-6096-4701-98ff-6b5034dfcc97",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting auto display for cadquery Workplane and Shape\n"
]
}
],
"source": [
"import timeit\n",
"tic = timeit.default_timer()\n",
"\n",
"import cadquery as cq\n",
"from math import sin, cos, pi\n",
"\n",
"\n",
"\n",
"from jupyter_cadquery import (\n",
" versions,\n",
" show, PartGroup, Part, \n",
" get_viewer, close_viewer, get_viewers, close_viewers, open_viewer, set_defaults, get_defaults, open_viewer,\n",
" get_pick,\n",
")\n",
"\n",
"from jupyter_cadquery.replay import replay, enable_replay, disable_replay\n",
"''\n",
"\n",
"from build123d import *"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "be6cd832-8790-46db-aea3-e8b44b8609ca",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'viewer': 'dempf',\n",
" 'anchor': 'right',\n",
" 'cad_width': 600,\n",
" 'tree_width': 250,\n",
" 'height': 600,\n",
" 'theme': 'light',\n",
" 'pinning': False,\n",
" 'angular_tolerance': 0.2,\n",
" 'deviation': 0.1,\n",
" 'edge_accuracy': None,\n",
" 'default_color': (232, 176, 36),\n",
" 'default_edge_color': '#707070',\n",
" 'optimal_bb': False,\n",
" 'render_normals': False,\n",
" 'render_edges': True,\n",
" 'render_mates': False,\n",
" 'parallel': False,\n",
" 'mate_scale': 1,\n",
" 'control': 'trackball',\n",
" 'up': 'Z',\n",
" 'axes': False,\n",
" 'axes0': False,\n",
" 'grid': [False, False, False],\n",
" 'ticks': 10,\n",
" 'ortho': True,\n",
" 'transparent': False,\n",
" 'black_edges': False,\n",
" 'ambient_intensity': 0.75,\n",
" 'direct_intensity': 0.15,\n",
" 'reset_camera': True,\n",
" 'show_parent': True,\n",
" 'show_bbox': False,\n",
" 'position': None,\n",
" 'quaternion': None,\n",
" 'target': None,\n",
" 'zoom': None,\n",
" 'zoom_speed': 1.0,\n",
" 'pan_speed': 1.0,\n",
" 'rotate_speed': 1.0,\n",
" 'collapse': 1,\n",
" 'tools': True,\n",
" 'glass': True,\n",
" 'timeit': False,\n",
" 'js_debug': False}"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"close_viewers()\n",
"\n",
"set_defaults(viewer=\"dempf\",\n",
" cad_width=600, \n",
" #height=480,\n",
" )\n",
"\n",
"\n",
"cv = open_viewer(\"dempf\",\n",
" anchor=\"right\", \n",
" glass=True, \n",
" tools=False) # sets default viewer\n",
"\n",
"\n",
"cv.grid = [not g for g in cv.widget.grid]\n",
"\n",
"cv.axes = not cv.axes\n",
"cv.axes0 = not cv.axes0\n",
"cv.transparent = not cv.transparent\n",
"cv.black_edges = not cv.black_edges\n",
"#enable_replay(False, False)\n",
"#show_object = replay\n",
"\n",
"get_defaults()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "fad67912-407f-4263-a496-287ea7160753",
"metadata": {},
"outputs": [],
"source": [
"def seal_metal_pipe():\n",
" pipe = (cq.Workplane(\"XY\")\n",
" .sketch()\n",
" .circle(20, mode=\"c\", tag=\"circ\") \n",
" .select(\"circ\")\n",
" .wires()\n",
" .distribute(8)\n",
" .rect(2,2)\n",
" .finalize()\n",
" .extrude(2)\n",
" )\n",
" return pipe\n",
"\n",
"#.circle(15)\n",
"## .circle(14)\n",
"# .extrude(60)\n",
"# .faces(\">Z\")\n",
"\n",
"pipe = seal_metal_pipe()\n",
"pipe"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "d6ed6a98-1cc6-489a-8b65-e5d99837d8da",
"metadata": {},
"outputs": [],
"source": [
"cv1 = show(pipe)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "495f885e-5b92-4453-8c96-5c532fd7d46a",
"metadata": {},
"outputs": [],
"source": [
"pipe"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "14a5ae42-0246-4999-9818-0df5e5c0bfc7",
"metadata": {},
"outputs": [],
"source": [
"from cadquery.selectors import AreaNthSelector\n",
"\n",
"result = (\n",
" cq.Workplane(\"XY\")\n",
" .rect(20, 20)\n",
" .extrude(10)\n",
" .edges(\"|Z or <Z\")\n",
" .fillet(2)\n",
" .faces(\">Z\")\n",
" .shell(2)\n",
" .faces(\">Z\")\n",
" .wires(AreaNthSelector(-1))\n",
" .toPending()\n",
" .workplane()\n",
" .offset2D(-1)\n",
" .extrude(1)\n",
" .faces(\">Z[-2]\")\n",
" .wires(AreaNthSelector(0))\n",
" .toPending()\n",
" .workplane()\n",
" .cutBlind(2)\n",
")\n",
"result"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "10ef4488-c40a-4dc2-a723-2061632b8529",
"metadata": {},
"outputs": [],
"source": [
"with BuildPart() as p:\n",
" with BuildSketch() as pipe:\n",
" Circle(20)\n",
" Circle(19, mode=Mode.SUBTRACT)\n",
" extrude(amount=20)\n",
" with BuildSketch() as s:\n",
" with PolarLocations(20,8):\n",
" Rectangle(5,2)\n",
" extrude(amount=2, mode=Mode.SUBTRACT)\n",
" \n",
"p"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "027849ae-2b65-4473-8c5e-744691b85c2e",
"metadata": {},
"outputs": [],
"source": [
"\n",
"pipe = (cq.Workplane(\"XY\")\n",
" .sketch()\n",
" .circle(20)\n",
" .circle(19, mode=\"s\")\n",
" .finalize()\n",
" .extrude(40, both=False)\n",
" )\n",
" \n",
"holes = (pipe.faces(\">Z\")\n",
" .sketch()\n",
" .circle(20, mode=\"c\", tag=\"circ\") \n",
" .select(\"circ\")\n",
" .wires()\n",
" .distribute(8)\n",
" .rect(3,2)\n",
" .finalize()\n",
" .extrude(-2, combine=\"s\")\n",
" .faces(\"<Z\")\n",
" .sketch()\n",
" .circle(20, mode=\"c\", tag=\"circ\") \n",
" .select(\"circ\")\n",
" .wires()\n",
" .distribute(8)\n",
" .rect(3,2)\n",
" .finalize()\n",
" .extrude(2, combine=\"s\")\n",
" )\n",
"holes"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "d793cdb0-ef0b-465d-9dbb-6d1115de1320",
"metadata": {},
"outputs": [
{
"ename": "TypeError",
"evalue": "Workplane.polyline() missing 1 required positional argument: 'listOfXYTuple'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[9], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m yoghurt_extender \u001b[38;5;241m=\u001b[39m(\u001b[43mcq\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mWorkplane\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mXZ\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m----> 2\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpolyline\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;241m.\u001b[39msketch()\n\u001b[1;32m 4\u001b[0m \n\u001b[1;32m 5\u001b[0m \u001b[38;5;241m.\u001b[39mrect(\u001b[38;5;241m2\u001b[39m,\u001b[38;5;241m100\u001b[39m)\n\u001b[1;32m 6\u001b[0m \u001b[38;5;241m.\u001b[39mrect(\u001b[38;5;241m1.5\u001b[39m,\u001b[38;5;241m4\u001b[39m)\n\u001b[1;32m 7\u001b[0m \n\u001b[1;32m 8\u001b[0m )\n\u001b[1;32m 9\u001b[0m yoghurt_extender \n",
"\u001b[0;31mTypeError\u001b[0m: Workplane.polyline() missing 1 required positional argument: 'listOfXYTuple'"
]
}
],
"source": [
"yoghurt_extender =(cq.Workplane(\"XZ\")\n",
" .polyline()\n",
" .sketch()\n",
" \n",
" .rect(2,100)\n",
" .rect(1.5,4)\n",
" \n",
" )\n",
"yoghurt_extender "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "51ec37d0-ea15-433a-9aad-16e05837e93b",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "c4ea0f7f-9ac1-4ff0-9740-787a17cba1bc",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

116
lookup_comparison.ipynb Normal file

File diff suppressed because one or more lines are too long

685
pretosius.ipynb Normal file
View File

@ -0,0 +1,685 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "f027debb-4ad0-4ea0-a564-321f3c1bd63c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting auto display for cadquery Workplane and Shape\n"
]
},
{
"data": {
"text/plain": [
"''"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import timeit\n",
"tic = timeit.default_timer()\n",
"\n",
"import cadquery as cq\n",
"from math import sin, cos, pi\n",
"\n",
"\n",
"\n",
"from jupyter_cadquery import (\n",
" versions,\n",
" show, PartGroup, Part, \n",
" get_viewer, close_viewer, get_viewers, close_viewers, open_viewer, set_defaults, get_defaults, open_viewer,\n",
" get_pick,\n",
")\n",
"\n",
"from jupyter_cadquery.replay import replay, enable_replay, disable_replay\n",
"''"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cde98536-33ac-4609-b1fe-50af35bdc752",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 2,
"id": "6af7a60f-ac0c-46cf-8956-a168cd3246cb",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Enabling jupyter_cadquery replay\n"
]
}
],
"source": [
"cv = open_viewer(\"pretosius\",\n",
" anchor=\"right\", \n",
" glass=True, \n",
" tools=False) # sets default viewer\n",
"\n",
"\n",
"cv.grid = [not g for g in cv.widget.grid]\n",
"\n",
"cv.axes = not cv.axes\n",
"cv.axes0 = not cv.axes0\n",
"cv.transparent = not cv.transparent\n",
"cv.black_edges = not cv.black_edges\n",
"enable_replay(False, False)\n",
"show_object = replay"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "b943c6ad-a678-4af7-8139-b03cad539b33",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Defaulting to user installation because normal site-packages is not writeable\n",
"Collecting git+https://github.com/gumyr/build123d\n",
" Cloning https://github.com/gumyr/build123d to /tmp/pip-req-build-_no6109s\n",
" Running command git clone --filter=blob:none --quiet https://github.com/gumyr/build123d /tmp/pip-req-build-_no6109s\n",
" fatal: unable to access 'https://github.com/gumyr/build123d/': Could not resolve host: github.com\n",
" \u001b[1;31merror\u001b[0m: \u001b[1msubprocess-exited-with-error\u001b[0m\n",
" \n",
" \u001b[31m×\u001b[0m \u001b[32mgit clone --\u001b[0m\u001b[32mfilter\u001b[0m\u001b[32m=\u001b[0m\u001b[32mblob\u001b[0m\u001b[32m:none --quiet \u001b[0m\u001b[4;32mhttps://github.com/gumyr/build123d\u001b[0m\u001b[32m \u001b[0m\u001b[32m/tmp/\u001b[0m\u001b[32mpip-req-build-_no6109s\u001b[0m did not run successfully.\n",
" \u001b[31m│\u001b[0m exit code: \u001b[1;36m128\u001b[0m\n",
" \u001b[31m╰─>\u001b[0m See above for output.\n",
" \n",
" \u001b[1;35mnote\u001b[0m: This error originates from a subprocess, and is likely not a problem with pip.\n",
"\u001b[1;31merror\u001b[0m: \u001b[1msubprocess-exited-with-error\u001b[0m\n",
"\n",
"\u001b[31m×\u001b[0m \u001b[32mgit clone --\u001b[0m\u001b[32mfilter\u001b[0m\u001b[32m=\u001b[0m\u001b[32mblob\u001b[0m\u001b[32m:none --quiet \u001b[0m\u001b[4;32mhttps://github.com/gumyr/build123d\u001b[0m\u001b[32m \u001b[0m\u001b[32m/tmp/\u001b[0m\u001b[32mpip-req-build-_no6109s\u001b[0m did not run successfully.\n",
"\u001b[31m│\u001b[0m exit code: \u001b[1;36m128\u001b[0m\n",
"\u001b[31m╰─>\u001b[0m See above for output.\n",
"\n",
"\u001b[1;35mnote\u001b[0m: This error originates from a subprocess, and is likely not a problem with pip.\n",
"\u001b[33mWARNING: There was an error checking the latest version of pip.\u001b[0m\u001b[33m\n",
"\u001b[0m"
]
}
],
"source": [
"!pip install git+https://github.com/gumyr/build123d"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "44eb609a-c382-4d07-b224-d08cd3bf8107",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Solid at 0x7f27ec7477f0, Center(0.5, 1.0, 1.5)\n",
"└── Shell at 0x7f2857577f70, Center(0.5, 1.0, 1.5)\n",
" ├── Face at 0x7f2857577e70, Center(0.0, 1.0, 1.5)\n",
" ├── Face at 0x7f27ec747630, Center(1.0, 1.0, 1.5)\n",
" ├── Face at 0x7f27ec2af930, Center(0.5, 0.0, 1.5)\n",
" ├── Face at 0x7f27ec2e58b0, Center(0.5, 2.0, 1.5)\n",
" ├── Face at 0x7f27ec10cf70, Center(0.5, 1.0, 0.0)\n",
" └── Face at 0x7f27ec10fe30, Center(0.5, 1.0, 3.0)\n",
"\n"
]
}
],
"source": [
"from build123d import *\n",
"box=Solid.make_box(1,2,3)\n",
"print(box.show_topology(limit_class=\"Face\"))\n",
"box"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "52baf674-915f-4a06-9015-61692f01601e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<cad_viewer_widget.widget.CadViewer at 0x7f28585a1390>"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"width = 3\n",
"height = 6\n",
"ri = 10\n",
"ro = ri+0.3\n",
"\n",
"s = 0.8\n",
"s1 = 0.7\n",
"p = Pos(ri,0,0)\n",
"x = 1.8+ri\n",
"pad = 2\n",
"with BuildPart() as ring:\n",
" with BuildSketch(Plane.XZ) as sk:\n",
" with BuildLine() as outline:\n",
" c1 = Spline([(x,0,-pad),(x,0,height+pad)], tangents=[(1,0),(-1, 0)], tangent_scalars=[s,s])\n",
" c1 = Spline([(x,0,-pad),(x,0,height+pad)], tangents=[(-1,0),(1, 0)], tangent_scalars=[s1,s1])\n",
" make_face()\n",
" revolve(axis=Axis.Z)\n",
" \n",
" \n",
"\n",
"show(ring, transparent=True) \n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "b9016caa-241a-4e76-a7ff-cad8cb0521bc",
"metadata": {},
"outputs": [],
"source": [
"def string_to_binary_string(s:str):\n",
" return ''.join([\"{0:08b}\".format(ord(c)) for c in s])"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "17ba4d69-d787-484f-b04e-a14668b1632b",
"metadata": {},
"outputs": [
{
"ename": "ValueError",
"evalue": "Edges are disconnected",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[6], line 68\u001b[0m\n\u001b[1;32m 66\u001b[0m binstr \u001b[38;5;241m=\u001b[39m string_to_binary_string(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmunsel\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 67\u001b[0m binstr \u001b[38;5;241m=\u001b[39m string_to_binary_string(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mnonpostrans \u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m---> 68\u001b[0m signal \u001b[38;5;241m=\u001b[39m \u001b[43mbuild_signal\u001b[49m\u001b[43m(\u001b[49m\u001b[43mbinstr\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mri\u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43mwidth\u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[38;5;241;43m0.4\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 69\u001b[0m show(signal,ring, transparent\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n",
"Cell \u001b[0;32mIn[6], line 61\u001b[0m, in \u001b[0;36mbuild_signal\u001b[0;34m(binstring, ri)\u001b[0m\n\u001b[1;32m 59\u001b[0m Circle(\u001b[38;5;241m0.5\u001b[39m)\n\u001b[1;32m 60\u001b[0m \u001b[38;5;66;03m#return path_builder\u001b[39;00m\n\u001b[0;32m---> 61\u001b[0m \u001b[43msweep\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtransition\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mTransition\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mROUND\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 62\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m signal\n",
"File \u001b[0;32m~/.local/lib/python3.10/site-packages/build123d/operations_generic.py:989\u001b[0m, in \u001b[0;36msweep\u001b[0;34m(sections, path, multisection, is_frenet, transition, normal, binormal, clean, mode)\u001b[0m\n\u001b[1;32m 987\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m context \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mor\u001b[39;00m context \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m context\u001b[38;5;241m.\u001b[39mpending_edges:\n\u001b[1;32m 988\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpath must be provided\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m--> 989\u001b[0m path_wire \u001b[38;5;241m=\u001b[39m \u001b[43mWire\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcontext\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpending_edges\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 990\u001b[0m context\u001b[38;5;241m.\u001b[39mpending_edges \u001b[38;5;241m=\u001b[39m []\n\u001b[1;32m 991\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n",
"File \u001b[0;32m~/.local/lib/python3.10/site-packages/build123d/topology.py:7789\u001b[0m, in \u001b[0;36mWire.__init__\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 7787\u001b[0m obj \u001b[38;5;241m=\u001b[39m wire\u001b[38;5;241m.\u001b[39mwrapped\n\u001b[1;32m 7788\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m edges:\n\u001b[0;32m-> 7789\u001b[0m obj \u001b[38;5;241m=\u001b[39m \u001b[43mWire\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_make_wire\u001b[49m\u001b[43m(\u001b[49m\u001b[43medges\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43msequenced\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mis\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01melse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43msequenced\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 7791\u001b[0m \u001b[38;5;28msuper\u001b[39m()\u001b[38;5;241m.\u001b[39m\u001b[38;5;21m__init__\u001b[39m(\n\u001b[1;32m 7792\u001b[0m obj\u001b[38;5;241m=\u001b[39mobj,\n\u001b[1;32m 7793\u001b[0m label\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m label \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;28;01melse\u001b[39;00m label,\n\u001b[1;32m 7794\u001b[0m color\u001b[38;5;241m=\u001b[39mcolor,\n\u001b[1;32m 7795\u001b[0m parent\u001b[38;5;241m=\u001b[39mparent,\n\u001b[1;32m 7796\u001b[0m )\n",
"File \u001b[0;32m~/.local/lib/python3.10/site-packages/build123d/topology.py:8085\u001b[0m, in \u001b[0;36mWire._make_wire\u001b[0;34m(cls, edges, sequenced)\u001b[0m\n\u001b[1;32m 8083\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mRuntimeError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mWire is empty\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 8084\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m wire_builder\u001b[38;5;241m.\u001b[39mError() \u001b[38;5;241m==\u001b[39m BRepBuilderAPI_DisconnectedWire:\n\u001b[0;32m-> 8085\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mEdges are disconnected\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 8087\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m wire_builder\u001b[38;5;241m.\u001b[39mWire()\n",
"\u001b[0;31mValueError\u001b[0m: Edges are disconnected"
]
}
],
"source": [
"from math import sin, cos, pi\n",
"\n",
"width = 3\n",
"height = 6\n",
"ri = 10\n",
"ro = ri+0.3\n",
"\n",
"def build_signal(binstring, ri):\n",
" n = len(binstring)\n",
"\n",
" \n",
" ro = ri+1\n",
" dphi =2*pi/(n+0)\n",
" dp = dphi/10\n",
" dh = min(dp*ro, 18*pi/180)\n",
" \n",
" a = 1\n",
" tngu = lambda phi, d: (a*cos(phi), a*sin(phi), d)\n",
" tngd = lambda phi, d: (-a*cos(phi), -a*sin(phi), d)\n",
"\n",
" with BuildPart() as signal:\n",
" with BuildLine(Plane.XY) as path_builder:\n",
" segments = []\n",
" h = 0 if binstring[0] == \"0\" else height\n",
" same_bits_streak = 0\n",
" for i, b in enumerate(binstring):\n",
" pos_flank = b == \"0\" and binstring[(i+1)%n] == \"1\"\n",
" neg_flank = b == \"1\" and binstring[(i+1)%n] == \"0\"\n",
" same_bits_streak += 1\n",
" if neg_flank or pos_flank or (i == n-1):\n",
" phi0 = dphi*(i-same_bits_streak+1)\n",
" phi1 = dphi*(i-same_bits_streak+1+0.5*same_bits_streak)\n",
" phi2 = dphi*(i+1)\n",
" phi0_pad = phi0 + dp\n",
" phi2_pad = phi2 - dp\n",
" #if segments:\n",
" # segments.append(Spline(segments[-1]@1,p1, tangents=[segments[-1]%1, tngu(phi2, -1)]))\n",
" segments.append(ThreePointArc(\n",
" (ri * cos(phi0_pad), ri * sin(phi0_pad),h),\n",
" (ri * cos(phi1), ri * sin(phi1),h),\n",
" (ri * cos(phi2_pad), ri * sin(phi2_pad),h),\n",
" ))\n",
" same_bits_streak = 0\n",
" p1 = (ri * cos(phi2), ri * sin(phi2),height-dh)\n",
" p2 = (ri * cos(phi2), ri * sin(phi2),dh)\n",
" #l = segments[i]\n",
" if neg_flank:\n",
" h = 0\n",
" segments.append(Spline(segments[-1]@1,p1, tangents=[segments[-1]%1, tngu(phi2, -1)]))\n",
" segments.append(Spline(p1,p2,\n",
" tangents=[tngu(phi2, -1), tngd(phi2, -1)]))\n",
" if pos_flank:\n",
" h = height\n",
" segments.append(Spline(p2,p1,\n",
" tangents=[tngu(phi2, 1), tngd(phi2, 1)]))\n",
"\n",
" # l1 = segments[0]\n",
" with BuildSketch(Plane( segments[0] @ 0, z_dir=segments[0] % 0)) as x_section:\n",
" Circle(0.5)\n",
" #return path_builder\n",
" sweep(transition=Transition.ROUND)\n",
" return signal\n",
"\n",
"binstr = '0101100'#\n",
"binstr = '1101000'#\n",
"binstr = string_to_binary_string(\"munsel\")\n",
"binstr = string_to_binary_string(\"nonpostrans \")\n",
"signal = build_signal(binstr, ri+width+0.4)\n",
"show(signal,ring, transparent=True)\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "7646c441-da20-47e2-9047-fb4a02a0a85d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"100% ⋮————————————————————————————————————————————————————————————⋮ (2/2) 0.02s\n"
]
},
{
"data": {
"text/plain": [
"<cad_viewer_widget.widget.CadViewer at 0x7f28585a1390>"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"def build_signal(binstring, ri):\n",
" n = len(binstring)\n",
" ro = ri+1\n",
" dphi =2*pi/(n+0) # how much angle per bit\n",
" dp = 0.81/ri/pi#dphi/10 # how much of that used for curvature\n",
" dh = min(dp*ro, 10*pi/180)\n",
" \n",
" a = 1\n",
" tngu = lambda phi, d: (a*cos(phi), a*sin(phi), d)\n",
" tngd = lambda phi, d: (-a*cos(phi), -a*sin(phi), d)\n",
" \n",
" def build_segments(pre_segments=[]):\n",
" segments = []\n",
" h = 0 if binstring[0] == \"0\" else height\n",
" same_bits_streak = 0\n",
" i_hoz = 0\n",
" ns = len(pre_segments)\n",
" for i, b in enumerate(binstring):\n",
" pos_flank = b == \"0\" and binstring[(i+1)%n] == \"1\"\n",
" neg_flank = b == \"1\" and binstring[(i+1)%n] == \"0\"\n",
" same_bits_streak += 1\n",
" if neg_flank or pos_flank or (i == n-1):\n",
" phi0 = dphi*(i-same_bits_streak+1)\n",
" phi1 = dphi*(i-same_bits_streak+1+0.5*same_bits_streak)\n",
" phi2 = dphi*(i+1)\n",
" phi0_pad = phi0 + dp\n",
" phi2_pad = phi2 - dp\n",
" #if segments:\n",
" # segments.append(Spline(segments[-1]@1,p1, tangents=[segments[-1]%1, tngu(phi2, -1)]))\n",
" segments.append(ThreePointArc(\n",
" (ri * cos(phi0_pad), ri * sin(phi0_pad),h),\n",
" (ri * cos(phi1), ri * sin(phi1),h),\n",
" (ri * cos(phi2_pad), ri * sin(phi2_pad),h),\n",
" ))\n",
" i_hoz += 1\n",
" same_bits_streak = 0\n",
" p1 = (ri * cos(phi2), ri * sin(phi2),height-dh)\n",
" p2 = (ri * cos(phi2), ri * sin(phi2),dh)\n",
" #l = segments[i]\n",
" if neg_flank:\n",
" h = 0\n",
" if pre_segments:\n",
" segments.append(Spline(pre_segments[i_hoz-1]@1,p1, tangents=[pre_segments[i_hoz-1]%1, tngu(phi2, -1)]))\n",
" segments.append(Spline(p1,p2,\n",
" tangents=[tngu(phi2, -1), tngd(phi2, -1)]))\n",
" segments.append(Spline(p2, pre_segments[i_hoz%ns]@0, tangents=[tngd(phi2, -1), pre_segments[i_hoz%ns]%0]))\n",
" if pos_flank:\n",
" h = height\n",
" if pre_segments:\n",
" segments.append(Spline(pre_segments[i_hoz-1]@1,p2, tangents=[pre_segments[i_hoz-1]%1, tngu(phi2, 1)]))\n",
" segments.append(Spline(p2,p1,\n",
" tangents=[tngu(phi2, 1), tngd(phi2, 1)]))\n",
" segments.append(Spline(p1, pre_segments[i_hoz%ns]@0, tangents=[tngd(phi2, 1), pre_segments[i_hoz%ns]%0]))\n",
"\n",
" return segments\n",
" \n",
" pre_segments = build_segments()#???\n",
"\n",
"\n",
" with BuildPart() as signal:\n",
" with BuildLine(Plane.XY) as path_builder:\n",
" #path_builder.mode=Mode.PRIVATE\n",
" segments = build_segments(pre_segments)\n",
" #segments = build_segments()\n",
" # l1 = segments[0]\n",
" with BuildSketch(Plane(segments[0] @ 0, z_dir=segments[0] % 0)) as x_section:\n",
" Circle(0.4)\n",
" #Rectangle(0.8,0.8)\n",
" #return path_builder\n",
" sweep()\n",
" #sweep(transition=Transition.ROUND)\n",
" signal.label=\"decor\"\n",
" #return pre_segments\n",
" return path_builder\n",
" #return signal\n",
"\n",
"#binstr = '0101100'#\n",
"#binstr = '110101000'#\n",
"#binstr = string_to_binary_string(\"munsel\")\n",
"binstr = string_to_binary_string(\"salty\")\n",
"signal = build_signal(binstr, ri+width+0.3)\n",
"show(signal,ring, transparent=True)\n",
"#show(signal, transparent=True, reset_camera=False)\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "d2d71180-9e82-4907-9579-e1accdb756e7",
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "'BuildLine' has no attribute 'part'. Did you intend '<BuildLine>.line.part'?",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[14], line 10\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m (left, right)\n\u001b[1;32m 9\u001b[0m \u001b[38;5;66;03m#ld, lu = \u001b[39;00m\n\u001b[0;32m---> 10\u001b[0m a,b,c,d \u001b[38;5;241m=\u001b[39m split_part(\u001b[43msignal\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpart\u001b[49m)\n\u001b[1;32m 11\u001b[0m \u001b[38;5;66;03m#cv = show(ld,lu, axes=True, axes0=True, transparent=True)\u001b[39;00m\n",
"File \u001b[0;32m~/.local/lib/python3.10/site-packages/build123d/build_common.py:761\u001b[0m, in \u001b[0;36mBuilder.__getattr__\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m 759\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__getattr__\u001b[39m(\u001b[38;5;28mself\u001b[39m, name):\n\u001b[1;32m 760\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"The user is likely trying to reference the builder's object\"\"\"\u001b[39;00m\n\u001b[0;32m--> 761\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mAttributeError\u001b[39;00m(\n\u001b[1;32m 762\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__class__\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m has no attribute \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mname\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m. \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 763\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDid you intend \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m<\u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__class__\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m>.\u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_obj_name\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m.\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mname\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m?\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 764\u001b[0m )\n",
"\u001b[0;31mAttributeError\u001b[0m: 'BuildLine' has no attribute 'part'. Did you intend '<BuildLine>.line.part'?"
]
}
],
"source": [
"def split_part(part):\n",
" #left, right = \n",
" return split(part, bisect_by=Plane.XZ, keep=Keep.BOTH).solids()\n",
" #ld, lu = split(left,bisect_by=Plane.YZ, keep=Keep.BOTH).solids()\n",
" #rd, ru = split(right,bisect_by=Plane.YZ, keep=Keep.BOTH).solids()\n",
" #return ld, lu#, rd, ru\n",
" return (left, right)\n",
"\n",
"#ld, lu = \n",
"a,b,c,d = split_part(signal.part)\n",
"#cv = show(ld,lu, axes=True, axes0=True, transparent=True)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "71186b01-15d9-4cdc-b70c-f94f75106ef9",
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'd' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[13], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43md\u001b[49m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;66;03m#neg_ring = ring.part - signal.part\u001b[39;00m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;66;03m#show(neg_ring)\u001b[39;00m\n",
"\u001b[0;31mNameError\u001b[0m: name 'd' is not defined"
]
}
],
"source": [
"d\n",
"#neg_ring = ring.part - signal.part\n",
"#show(neg_ring)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "e6b70bbb-5ceb-4440-ab01-7caeb06c6f17",
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "'BuildLine' has no attribute 'part'. Did you intend '<BuildLine>.line.part'?",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[12], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m product \u001b[38;5;241m=\u001b[39m Compound(label\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mring\u001b[39m\u001b[38;5;124m\"\u001b[39m, children\u001b[38;5;241m=\u001b[39m[ring\u001b[38;5;241m.\u001b[39mpart, \u001b[43msignal\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpart\u001b[49m])\n\u001b[1;32m 2\u001b[0m show(product)\n",
"File \u001b[0;32m~/.local/lib/python3.10/site-packages/build123d/build_common.py:761\u001b[0m, in \u001b[0;36mBuilder.__getattr__\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m 759\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__getattr__\u001b[39m(\u001b[38;5;28mself\u001b[39m, name):\n\u001b[1;32m 760\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"The user is likely trying to reference the builder's object\"\"\"\u001b[39;00m\n\u001b[0;32m--> 761\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mAttributeError\u001b[39;00m(\n\u001b[1;32m 762\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__class__\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m has no attribute \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mname\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m. \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 763\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDid you intend \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m<\u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__class__\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m>.\u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_obj_name\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m.\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mname\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m?\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 764\u001b[0m )\n",
"\u001b[0;31mAttributeError\u001b[0m: 'BuildLine' has no attribute 'part'. Did you intend '<BuildLine>.line.part'?"
]
}
],
"source": [
"product = Compound(label=\"ring\", children=[ring.part, signal.part])\n",
"show(product)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4d278f9c-5e81-4341-89bd-6840d21028da",
"metadata": {},
"outputs": [],
"source": [
"#show(signal)\n",
"product.export_step(\"nonpostrans_ascii_ring.step\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a0f50802-29c0-4960-918b-245c9b71a3e9",
"metadata": {},
"outputs": [],
"source": [
"fullring = ring.part + signal.part"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3d306d91-b798-445a-b91c-e99887d539df",
"metadata": {},
"outputs": [],
"source": [
"#cq.exporters.export(signal, \"signal.stl\", cq.exporters.ExportTypes.STL)\n",
"\n",
"view_port_origin=(-100, -50, 30)\n",
"visible, hidden = ring.project_to_viewport(view_port_origin)\n",
"\n",
"max_dimension = max(*Compound(children=visible + hidden).bounding_box().size)\n",
"exporter = ExportSVG(scale=100 / max_dimension)\n",
"exporter.add_layer(\"Visible\")\n",
"exporter.add_layer(\"Hidden\", line_color=(99, 99, 99), line_type=LineType.ISO_DOT)\n",
"exporter.add_shape(visible, layer=\"Visible\")\n",
"exporter.add_shape(hidden, layer=\"Hidden\")\n",
"exporter.write(\"nonpostrans_ring.svg\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8a5cfcf5-9811-4004-8f29-d56fa444a399",
"metadata": {},
"outputs": [],
"source": [
"from build123d import *\n",
"import copy"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "c485de3b-7837-496a-9664-283ed97ea2d9",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"w_cut_inside = 71.0 w_cut_outside = 21.0\n",
"w_cut_inside = 71.0 w_cut_outside = 21.0\n"
]
}
],
"source": [
"def build_psorias_release(L = 216, W = 127, H = 135,PEAK2PEAK = 160, h_bottom = 15):\n",
"\n",
" R0 = 40\n",
" R1 = 8\n",
" R2 = 40\n",
" R3 = 30\n",
" w_cut_inside = (PEAK2PEAK / 2) - R1-1\n",
" w_cut_outside = (L / 2) - w_cut_inside - (2 * R1)\n",
" print(f\"{w_cut_inside = } {w_cut_outside = }\")\n",
" \n",
" h_bend = 70\n",
" w_bend = w_cut_outside - 8\n",
" h_rect = 10\n",
" w_slope = 10\n",
"\n",
"\n",
" with BuildPart() as p:\n",
" with BuildSketch(Plane.XZ) as s:\n",
" with Locations((0,H-R0)):\n",
" Circle(R0)\n",
" with Locations((0,0)):\n",
" Rectangle(W, h_rect)\n",
" make_hull()\n",
" extrude(amount=L/2)\n",
" with BuildSketch(Plane.YZ.offset(-W/2)) as s:\n",
" with Locations((-(L-w_cut_inside)/2, H+h_rect/2)):\n",
" Rectangle(w_cut_inside, h_rect)\n",
" with Locations(((-L+w_cut_inside-w_slope-R2-1)/2, h_bottom+h_rect/2)): \n",
" Rectangle(w_cut_inside-w_slope-R2, h_rect)\n",
" with Locations((-(L-w_cut_inside+R2-w_slope)/2, h_bottom+R2)): \n",
" Circle(R2)\n",
" make_hull()\n",
" extrude(amount=W, mode=Mode.SUBTRACT)\n",
" with BuildSketch(Plane.YZ.offset(-W/2)) as s:\n",
" with Locations((-w_cut_outside/2, H+h_rect/2)):\n",
" Rectangle(w_cut_outside, h_rect)\n",
" with Locations(((h_rect)/2, h_rect)): \n",
" Rectangle(h_rect, h_rect)\n",
" with Locations((-w_bend+R3, h_bend)): \n",
" Circle(R3)\n",
" make_hull()\n",
" extrude(amount=W, mode=Mode.SUBTRACT) \n",
" fillet(p.edges().sort_by(Axis.Z)[-1], radius=R1) \n",
" fillet(p.edges().sort_by(Axis.Z)[-3], radius=R1)\n",
" #scale(by=(1,1,0.8), mode=Mode.SUBTRACT)\n",
" mirror(p.part, about=Plane(p.faces().group_by(Axis.Y)[0][0]))\n",
" return p\n",
"\n",
"p = build_psorias_release()\n",
"p1 = build_psorias_release(L = 216, W = 110, H = 100,PEAK2PEAK = 160, h_bottom = 15)\n",
"p2 = p.part - p1.part.locate(Location((0.,0,-25.)))\n",
"\n",
"p2"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bfe10241-66e6-43c9-839e-16f1dfbe2925",
"metadata": {},
"outputs": [],
"source": [
"p1 = copy.copy(p.part)\n",
"p1 = scale(p1, by=(0.8,0.95,0.8)).locate(Location((0.,-(1-0.95)*W/2.-2.5,-25.)))\n",
"p2 = p.part-p1"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bc50e074-b223-4c10-9dc4-bbece6206876",
"metadata": {},
"outputs": [],
"source": [
"p2.export_step(\"psoas_releaser.step\")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "beae3c3c-7cea-40f3-9e30-10b87e8fcbdd",
"metadata": {},
"outputs": [],
"source": [
"import build123d as b1 \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "016ae351-fc44-456c-834a-15cb59e42327",
"metadata": {},
"outputs": [],
"source": [
"b1.topology."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

343
regal.ipynb Normal file
View File

@ -0,0 +1,343 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "a0dc6484-8b39-4f43-a765-11e567de1746",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting auto display for cadquery Workplane and Shape\n",
"import runtime: 2.6s\n"
]
}
],
"source": [
"import timeit\n",
"\n",
"tictime = 0\n",
"def tic():\n",
" global tictime\n",
" tictime = timeit.default_timer()\n",
"\n",
"def toclog(custom_msg=None):\n",
" toc = timeit.default_timer()\n",
" runtime = toc - tictime\n",
" msg = \"runtime\" if not custom_msg else custom_msg\n",
" print(f\"{msg}: {runtime:2.2}s\")\n",
" \n",
"tic()\n",
"\n",
"\n",
"\n",
"from build123d import *\n",
"from jupyter_cadquery import (\n",
" versions,\n",
" show, PartGroup, Part, \n",
" get_viewer, close_viewer, get_viewers, close_viewers, open_viewer, set_defaults, get_defaults, open_viewer,\n",
" get_pick,\n",
")\n",
"from jupyter_cadquery.ocp_utils import webcol_to_cq\n",
"\n",
"from jupyter_cadquery.replay import replay, enable_replay, disable_replay\n",
"\n",
"toclog(\"import runtime\")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "6b46efca-c212-4c0d-9e39-a6d82d51bbec",
"metadata": {},
"outputs": [],
"source": [
"cv = open_viewer(\"REGAL\",\n",
" anchor=\"right\", \n",
" glass=True, \n",
" tools=False) # sets default viewer\n",
"\n",
"\n",
"cv.grid = [not g for g in cv.widget.grid]\n",
"\n",
"cv.axes = not cv.axes\n",
"cv.axes0 = not cv.axes0\n",
"cv.transparent = not cv.transparent\n",
"cv.black_edges = not cv.black_edges\n",
"\n",
"set_defaults(\n",
" cad_width=640, \n",
" height=480, \n",
" viewer=\"REGAL\"\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "44dd6c5a-c307-4284-8074-ec9086df4239",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[32;1m\n",
"*******************************************************************\n",
"****** Statistics on Transfer (Write) ******\u001b[0m\n",
"\u001b[32;1m\n",
"*******************************************************************\n",
"****** Transfer Mode = 0 I.E. As Is ******\u001b[0m\n",
"\u001b[32;1m****** Transferring Shape, ShapeType = 0 ******\u001b[0m\n",
"\u001b[32;1m** WorkSession : Sending all data\u001b[0m\n",
"\u001b[32;1m Step File Name : regal_5x5.step(15716 ents) Write Done\u001b[0m\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/tmp/ipykernel_223/3924664858.py:37: DeprecationWarning: Use the `export_step` function instead\n",
" regal.export_step(f'regal_{n_hor_boards}x{n_vert_boards}.step')\n"
]
},
{
"data": {
"text/plain": [
"<IFSelect_ReturnStatus.IFSelect_RetDone: 1>"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from build123d import *\n",
"\n",
"h = 200\n",
"w = 200\n",
"d = 80\n",
"t = 3\n",
"n_vert_boards = 5\n",
"n_hor_boards = 5\n",
"dw = (w-t)/(n_vert_boards-1)\n",
"dh = (h-t)/(n_hor_boards-1)\n",
"tol = 1\n",
"\n",
"\n",
"with BuildPart() as cutouts:\n",
" with BuildSketch(Plane.XZ.offset(d/2)) as sk:\n",
" with Locations(*tuple((j*dw-tol,dh*i-tol) \\\n",
" for i in range(n_hor_boards) \\\n",
" for j in range(n_vert_boards))):\n",
" Rectangle(t+tol*2,t+tol*2, align=Align.MIN)\n",
" extrude(amount=d/2+tol)\n",
"\n",
"with BuildPart() as vboards:\n",
" with BuildSketch(Plane.XZ) as sk:\n",
" with Locations(*tuple((dw*i, 0.0) for i in range(n_vert_boards))):\n",
" Rectangle(t, h, align=Align.MIN)\n",
" extrude(amount=d)\n",
" add(cutouts.part, mode=Mode.SUBTRACT)\n",
" \n",
"with BuildPart() as hboards: \n",
" with BuildSketch(Plane.XZ.offset(d/2)) as sk:\n",
" with Locations(*tuple((0.0,dh*i) for i in range(n_hor_boards))):\n",
" Rectangle(w,t, align=Align.MIN)\n",
" extrude(amount=d)\n",
" add(cutouts.part, mode=Mode.SUBTRACT)\n",
"\n",
"\n",
"hboards = hboards.part.translate((0,d/2,0))\n",
"\n",
"regal = Compound(label=\"regal\", children=(vboards.part, hboards))\n",
"\n",
"regal.export_step(f'regal_{n_hor_boards}x{n_vert_boards}.step')"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "ee75ab94-20d0-421e-a30b-06c4ae888206",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"100% ⋮————————————————————————————————————————————————————————————⋮ (2/2) 0.09s\n"
]
}
],
"source": [
"packed = pack((vertboards.part, horboards),\\\n",
" padding=5, align_z=False)\n",
"Compound(packed)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "7e29334c-787c-474b-aab5-e92b72e93c66",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Versions:\n",
"- jupyter_cadquery 3.5.2\n",
"- cad_viewer_widget 1.4.1\n",
"- open cascade 7.6.3\n",
"\n",
"Plugins loaded:\n",
"- build123d\n",
"- cadquery-massembly\n"
]
}
],
"source": [
"versions()"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "e80b28dd-4739-4d79-a47e-d5c17e6fb3e9",
"metadata": {},
"outputs": [],
"source": [
"with BuildPart() as cupbuilder:\n",
" with BuildSketch() as sk:\n",
" Circle(30)\n",
" extrude(amount=60)\n",
" with Locations((30, 0, 10), (30, 0, 45)):\n",
" b = Box(15, 40, 10)\n",
" #b.edges().sort_by(b.edges(),Axis.is_parallel(Axis.Z))\n",
" with BuildSketch(cupbuilder.faces().sort_by(Axis.Z)[-1]) as sk1:\n",
" Circle(25)\n",
" extrude(amount=-55, mode=Mode.SUBTRACT)\n",
" #offset(amount=-6, openings=f)\n",
" fillet(cupbuilder.edges().sort_by(Axis.Z)[-2], radius=3)\n",
" with Locations((32,0,30)):\n",
" Box(4, 30, 60, mode=Mode.SUBTRACT)\n",
" with Locations((36,0,30)): \n",
" Box(8, 4, 60, mode=Mode.SUBTRACT)\n",
"cupbuilder"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "2551e7ff-dde4-40a6-9ad6-63cd513a5ea7",
"metadata": {},
"outputs": [],
"source": [
"b.edges().pa"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "d7bbd569-8c84-4d3a-8466-ac1fa95ff480",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'0.6.1.dev11+g31c2aaa'"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from build123d import __version__\n",
"__version__"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "e7ec04b2-3b3d-4f66-9374-b8dbe9445c72",
"metadata": {},
"outputs": [],
"source": [
"sheet_thickness = 4 * MM\n",
"\n",
"with BuildPart() as side:\n",
" d = Vector(1, 0, 0).rotate(Axis.Y, 60)\n",
" with BuildLine(Plane.XZ) as side_line:\n",
" l1 = Line((0, 65), (170 / 2, 65))\n",
" l2 = PolarLine(l1 @ 1, length=65, direction=d, length_mode=LengthMode.VERTICAL)\n",
" l3 = Line(l2 @ 1, (170 / 2, 0))\n",
" fillet(side_line.vertices(), 7)\n",
" make_brake_formed(\n",
" thickness=sheet_thickness,\n",
" station_widths=[40, 40, 40, 112.52 / 2, 112.52 / 2, 112.52 / 2],\n",
" side=Side.RIGHT,\n",
" )\n",
" fe = side.edges().filter_by(Axis.Z).group_by(Axis.Z)[0].sort_by(Axis.Y)[-1]\n",
" fillet(fe, radius=7)\n",
"side"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "bc9fe2d7-c65f-481d-93ae-46ad90172418",
"metadata": {},
"outputs": [
{
"ename": "ImportError",
"evalue": "cannot import name '__version__' from 'os' (/opt/conda/envs/cq/lib/python3.10/os.py)",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mImportError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[2], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mos\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m __version__\n",
"\u001b[0;31mImportError\u001b[0m: cannot import name '__version__' from 'os' (/opt/conda/envs/cq/lib/python3.10/os.py)"
]
}
],
"source": [
"import os"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6c9865a4-0062-4f8b-9f57-48170042bcee",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

149
smartphonestand.ipynb Normal file
View File

@ -0,0 +1,149 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "bad426fe-bce7-427b-938b-ccf52358420d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting auto display for cadquery Workplane and Shape\n"
]
}
],
"source": [
"import timeit\n",
"tic = timeit.default_timer()\n",
"\n",
"import cadquery as cq\n",
"from build123d import *\n",
"\n",
"from jupyter_cadquery import (\n",
" versions,\n",
" show, PartGroup, Part, \n",
" get_viewer, close_viewer, get_viewers, close_viewers, open_viewer, set_defaults, get_defaults, open_viewer,\n",
" get_pick,\n",
")\n",
"from jupyter_cadquery.ocp_utils import webcol_to_cq\n",
"\n",
"from jupyter_cadquery.replay import replay, enable_replay, disable_replay\n",
"close_viewers()\n",
"set_defaults(\n",
" cad_width=640, \n",
" height=480, \n",
" viewer=\"smartphonestand\"\n",
")\n",
"cv = open_viewer(\"smartphonestand\",\n",
" anchor=\"right\", \n",
" glass=True, \n",
" theme=\"dark\",\n",
" tools=True) # sets default viewer\n",
"\n",
"\n",
"#cv.grid = [not g for g in cv.widget.grid]\n",
"\n",
"#cv.axes = not cv.axes\n",
"#cv.axes0 = not cv.axes0\n",
"#cv.transparent = not cv.transparent\n",
"#cv.black_edges = not cv.black_edges\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "897c1e60-a09b-4143-99c6-52f5e42bf60e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<cad_viewer_widget.widget.CadViewer at 0x71b3d4c51fc0>"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"with BuildPart() as part_builder:\n",
" with BuildSketch() as profile_sketch:\n",
" with BuildLine() as line_builder:\n",
" line = Polyline((100, -30),(-30, -30),(0, -10),\\\n",
" (-30,10),(-20,20), (0,0), (70,70), close=False)\n",
" line1 = fillet(radius=6,objects=line.vertices())\n",
" w = offset(amount=3) \n",
" \n",
" make_face()\n",
" extrude(amount=70)\n",
" f = part_builder.faces().sort_by(Axis.Y)[-11]\n",
" with BuildSketch() as bump_sk:\n",
" with Locations((-15,18)):\n",
" Circle(3)\n",
" extrude(amount=70)\n",
" with BuildSketch(f) as cutout_sketch:\n",
" with Locations((-7,0)):\n",
" RectangleRounded(35, 15, 2)\n",
" #SlotCenterToCenter(10,9, rotation=90)\n",
" #Circle(6)\n",
" extrude(amount=35, both=True, mode=Mode.SUBTRACT)\n",
" \n",
"show(part_builder,reset_camera=False)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "ca8fe07f-818b-458d-989c-e93d248a8bec",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"export_step(part_builder.part, \"phonestand1.step\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1b70ab33-cade-49e7-afc6-579769e9aee7",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

1812
smue2.ipynb Normal file

File diff suppressed because it is too large Load Diff

220
v2_SyncGrips.ipynb Normal file
View File

@ -0,0 +1,220 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "667ffcc6-563f-442b-9726-e15a2a45c01f",
"metadata": {},
"source": [
"# SyncGrips v2"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "c8a0e581-2963-424c-a258-f1de92180674",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting auto display for cadquery Workplane and Shape\n"
]
}
],
"source": [
"import timeit\n",
"tic = timeit.default_timer()\n",
"\n",
"import cadquery as cq\n",
"from build123d import *\n",
"\n",
"from jupyter_cadquery import (\n",
" versions,\n",
" show, PartGroup, Part, \n",
" get_viewer, close_viewer, get_viewers, close_viewers, open_viewer, set_defaults, get_defaults, open_viewer,\n",
" get_pick,\n",
")\n",
"from jupyter_cadquery.ocp_utils import webcol_to_cq\n",
"\n",
"from jupyter_cadquery.replay import replay, enable_replay, disable_replay\n",
"close_viewers()\n",
"set_defaults(\n",
" cad_width=640, \n",
" height=480, \n",
" viewer=\"syncgrips_v2\"\n",
")\n",
"cv = open_viewer(\"syncgrips_v2\",\n",
" anchor=\"right\", \n",
" glass=True, \n",
" theme=\"dark\",\n",
" tools=True) # sets default viewer\n"
]
},
{
"cell_type": "code",
"execution_count": 89,
"id": "e694a533-04eb-4783-84ca-faf15d983361",
"metadata": {},
"outputs": [],
"source": [
"sensor_width = 35\n",
"r_sens = 6\n",
"wall_thickness = 3\n",
"t = 2.5 # sheet thickness\n",
"w1 = sensor_width + 2* wall_thickness #sensor casing\n",
"w2 = 150 #sensors center placed at corners of w2*w2 square\n",
"h = 85 # total height\n",
"h1 = 20 # sensor casing height\n",
"h2 = 12\n",
"h3 = 35# sensor casing + mpu height\n",
"r = 25 # grip radius\n",
"w3 = 20 # upper mount dx \n",
"r1 = 8 # bending radius\n",
"locs = ((0,h+10), (-10,h-10),(10,h-10)) #locations of screws\n",
"handle_len = w2+w1\n",
"l = w2/2+sensor_width+r1+5 # half of the length"
]
},
{
"cell_type": "code",
"execution_count": 108,
"id": "2461ad9b-3cf5-4517-9b66-cee2e0bc5b5b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"100% ⋮————————————————————————————————————————————————————————————⋮ (3/3) 0.23s\n"
]
},
{
"data": {
"text/plain": [
"<cad_viewer_widget.widget.CadViewer at 0x7b1cff93a5c0>"
]
},
"execution_count": 108,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"with BuildPart() as part_builder:\n",
" with BuildSketch() as profile_sketch:\n",
" with BuildLine() as line_builder:\n",
" line = Polyline((-w3, h+r/2),(-w3, h-r),(-l, 0),\\\n",
" (l,0),(w3,h-r), (w3,h+r/2), close=False)\n",
" line1 = fillet(radius=r1,objects=line.vertices())\n",
" w = offset(amount=t) \n",
" make_face()\n",
" extrude(amount=w1)\n",
" \n",
"with BuildPart() as holes:\n",
" with BuildSketch(part_builder.faces().filter_by(Plane.YZ)[0]) as hole_sk:\n",
" dh = 10\n",
" dl = 5\n",
" with Locations((-dl,-dh),(dl,dh),(-dl,dh),(dl,-dh)):\n",
" Circle(2.05)\n",
" #SlotCenterToCenter(4,4, rotation=90)\n",
" extrude(amount=-50, both=True)\n",
" \n",
"with BuildPart() as handle:\n",
" with BuildSketch(Plane.XY) as profile_sk:\n",
" with Locations((0,h)):\n",
" Circle(r)\n",
" extrude(amount=handle_len)\n",
" ch = r-w3+4\n",
" with Locations((w3+ch/2-t,h,w1/2), (-w3-ch/2+t,h,w1/2), (w3+ch/2-t,h,w2+w1/2), (-w3-ch/2+t,h,w2+w1/2)):\n",
" Box(ch, r*2, w1, mode=Mode.SUBTRACT)\n",
" add(holes, mode=Mode.SUBTRACT)\n",
" \n",
"with BuildPart() as sensors:\n",
" dz = -5\n",
" ds = 4\n",
" with Locations((w2/2+ds,dz,w1/2), (w2/2+ds,dz,w2+w1/2)):\n",
" #Box(w1, 5, w1, mode=Mode.ADD)\n",
" add(sensor_cutout)\n",
" with Locations(((-w2/2-ds,dz,w1/2),(-w2/2-ds,dz,w2+w1/2))):\n",
" add(sensor_cutout.part.mirror(Plane.YZ))\n",
" \n",
"upper_sheet = part_builder.part - holes.part - sensors.part\n",
"lower_sheet = Location((0,0,handle_len-w1))*upper_sheet\n",
"show(upper_sheet, lower_sheet,handle.part,reset_camera=False)"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "74b1b118-4c15-4e03-a029-670d8198db72",
"metadata": {},
"outputs": [],
"source": [
"part_builder.faces().filter_by(Plane.YZ)[0]"
]
},
{
"cell_type": "code",
"execution_count": 111,
"id": "6fe18aef-3215-43e4-8d00-1ffd45a44f1d",
"metadata": {},
"outputs": [],
"source": [
"with BuildPart() as sensor_cutout:\n",
" with BuildSketch(Plane.XZ) as sensor_sk1:\n",
" d = 0\n",
" #Rectangle(22,26)\n",
" \n",
" sensor_space = extrude(amount=-14)\n",
" faces = (sensor_space.edges().group_by(Axis.Y)[-1] | Axis.Z)\n",
" #chamfer(objects=faces, length=6)\n",
" \n",
"with BuildPart() as sensorhole:\n",
" with BuildSketch(Plane.XZ) as sensorhole_sk: \n",
" with Locations((-sensor_width/2,0)):\n",
" Circle(1.55)\n",
" extrude(amount=-14)"
]
},
{
"cell_type": "code",
"execution_count": 113,
"id": "ffef54a9-57a6-4477-9836-2c770b451182",
"metadata": {},
"outputs": [],
"source": [
"sensor_cutout.part + sensor_cutout.part.mirror(Plane.YZ)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "80097045-32aa-4744-a56a-9892e60d361a",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}