mirror of
https://github.com/gumyr/build123d.git
synced 2025-12-06 02:30:55 -08:00
fixed examples to work with build1223d
This commit is contained in:
parent
70c14fdd0d
commit
f65bc75976
13 changed files with 32 additions and 135 deletions
|
|
@ -1,7 +1,5 @@
|
|||
from build123d import *
|
||||
|
||||
# from build123d.part_operations import *
|
||||
|
||||
b = Box(3, 3, 3)
|
||||
b2 = Rot(0, 0, 45) * extrude(Rectangle(1, 2), 0.2)
|
||||
for plane in [Plane(f) for f in b.faces()]:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
from build123d import *
|
||||
import build123d.alg_compat as COMPAT
|
||||
|
||||
logo_text = Text("123d", font_size=10, align=(Align.MIN, Align.MIN))
|
||||
font_height = logo_text.vertices().sort_by(Axis.Y)[-1].Y
|
||||
|
|
@ -27,7 +26,7 @@ three_d = Pos(font_height * 1.1, 0) * extrude(three_d, amount=font_height * 0.3)
|
|||
logo_width = three_d.vertices().sort_by(Axis.X)[-1].X
|
||||
|
||||
t1 = TangentArc((0, 0), (1, 0.75), tangent=(1, 0))
|
||||
arrow_left = t1 + COMPAT.mirror(t1, about=Plane.XZ)
|
||||
arrow_left = t1 + mirror(t1, about=Plane.XZ)
|
||||
|
||||
ext_line_length = font_height * 0.5
|
||||
dim_line_length = (logo_width - build_width - 2 * font_height * 0.05) / 2
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
from build123d import *
|
||||
import build123d.alg_compat as COMPAT
|
||||
|
||||
clock_radius = 10
|
||||
|
||||
|
|
@ -7,9 +6,9 @@ l1 = CenterArc((0, 0), clock_radius * 0.975, 0.75, 4.5)
|
|||
l2 = CenterArc((0, 0), clock_radius * 0.925, 0.75, 4.5)
|
||||
l3 = Line(l1 @ 0, l2 @ 0)
|
||||
l4 = Line(l1 @ 1, l2 @ 1)
|
||||
minute_indicator = COMPAT.make_face([l1, l3, l2, l4])
|
||||
minute_indicator = COMPAT.fillet(
|
||||
minute_indicator, minute_indicator.vertices(), radius=clock_radius * 0.01
|
||||
minute_indicator = make_face(l1, l3, l2, l4)
|
||||
minute_indicator = fillet(
|
||||
*minute_indicator.vertices(), radius=clock_radius * 0.01, target=minute_indicator
|
||||
)
|
||||
|
||||
clock_face = Circle(clock_radius)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
from build123d import *
|
||||
import build123d.alg_compat as COMPAT
|
||||
|
||||
# 35x7.5mm DIN Rail Dimensions
|
||||
overall_width, top_width, height, thickness, fillet_radius = 35, 27, 7.5, 1, 0.8
|
||||
|
|
@ -25,14 +24,14 @@ inside_vertices = (
|
|||
)
|
||||
)
|
||||
|
||||
din = COMPAT.fillet(din, inside_vertices, radius=fillet_radius)
|
||||
din = fillet(*inside_vertices, radius=fillet_radius, target=din)
|
||||
|
||||
outside_vertices = filter(
|
||||
lambda v: (v.Y == 0.0 or v.Y == height)
|
||||
and -overall_width / 2 < v.X < overall_width / 2,
|
||||
din.vertices(),
|
||||
)
|
||||
din = COMPAT.fillet(din, outside_vertices, radius=fillet_radius + thickness)
|
||||
din = fillet(*outside_vertices, radius=fillet_radius + thickness, target=din)
|
||||
|
||||
rail = extrude(din, rail_length)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
from build123d import *
|
||||
import build123d.alg_compat as COMPAT
|
||||
|
||||
segment_count = 6
|
||||
|
||||
|
|
@ -27,7 +26,7 @@ for i in range(segment_count + 1):
|
|||
section = plane * Circle(1)
|
||||
else:
|
||||
section = plane * Rectangle(1.25, 3)
|
||||
section = COMPAT.fillet(section, section.vertices(), radius=0.2)
|
||||
section = fillet(*section.vertices(), radius=0.2, target=section)
|
||||
sections += section
|
||||
|
||||
# Create the handle by sweeping along the path
|
||||
|
|
|
|||
|
|
@ -1,26 +1,23 @@
|
|||
from build123d import *
|
||||
import build123d.alg_compat as COMPAT
|
||||
|
||||
thru_hole = Cylinder(radius=3, height=2)
|
||||
thru_hole -= COMPAT.Bore(thru_hole, radius=1)
|
||||
thru_hole -= Hole(radius=1, depth=2)
|
||||
|
||||
# Recessed counter bore hole (hole location = (0,0,0))
|
||||
recessed_counter_bore = Cylinder(radius=3, height=2)
|
||||
recessed_counter_bore -= COMPAT.CounterBore(
|
||||
recessed_counter_bore, radius=1, counter_bore_radius=1.5, counter_bore_depth=0.5
|
||||
recessed_counter_bore -= CounterBoreHole(
|
||||
radius=1, depth=2, counter_bore_radius=1.5, counter_bore_depth=0.5
|
||||
)
|
||||
|
||||
# Recessed counter sink hole (hole location = (0,0,0))
|
||||
recessed_counter_sink = Cylinder(radius=3, height=2)
|
||||
recessed_counter_sink -= COMPAT.CounterSink(
|
||||
recessed_counter_sink, radius=1, counter_sink_radius=1.5
|
||||
)
|
||||
recessed_counter_sink -= CounterSinkHole(radius=1, depth=2, counter_sink_radius=1.5)
|
||||
|
||||
# Flush counter sink hole (hole location = (0,0,2))
|
||||
flush_counter_sink = Cylinder(radius=3, height=2)
|
||||
plane = Plane(flush_counter_sink.faces().sort_by().last)
|
||||
flush_counter_sink -= plane * COMPAT.CounterSink(
|
||||
flush_counter_sink, radius=1, counter_sink_radius=1.5
|
||||
flush_counter_sink -= plane * CounterSinkHole(
|
||||
radius=1, depth=2, counter_sink_radius=1.5
|
||||
)
|
||||
|
||||
if "show_object" in locals():
|
||||
|
|
|
|||
|
|
@ -1,15 +1,14 @@
|
|||
from build123d import *
|
||||
import build123d.alg_compat as COMPAT
|
||||
|
||||
blocks = Pos(-1, -1, 0) * Box(1, 2, 1, align=(Align.CENTER, Align.MIN, Align.MIN))
|
||||
blocks += Box(1, 1, 2, align=(Align.CENTER, Align.MIN, Align.MIN))
|
||||
blocks += Pos(1, -1, 0) * Box(1, 2, 1, align=(Align.CENTER, Align.MIN, Align.MIN))
|
||||
|
||||
bottom_edges = blocks.edges().filter_by_position(Axis.Z, 0, 1, inclusive=(True, False))
|
||||
blocks2 = COMPAT.chamfer(blocks, bottom_edges, length=0.1)
|
||||
blocks2 = chamfer(*bottom_edges, length=0.1, target=blocks)
|
||||
|
||||
top_edges = blocks2.edges().filter_by_position(Axis.Z, 1, 2, inclusive=(False, True))
|
||||
blocks2 = COMPAT.chamfer(blocks2, top_edges, length=0.1)
|
||||
blocks2 = chamfer(*top_edges, length=0.1, target=blocks2)
|
||||
|
||||
|
||||
if "show_object" in locals():
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ for plane in [Plane(f) for f in pipes.faces()]:
|
|||
|
||||
last = pipes.edges()
|
||||
pipes += extrude(pipe, amount=10)
|
||||
pipes = fillet(pipes, pipes.edges() - last, radius=0.2)
|
||||
pipes = fillet(*pipes.edges() - last, radius=0.2, target=pipes)
|
||||
|
||||
if "show_object" in locals():
|
||||
show_object(pipes, name="intersecting pipes")
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
from build123d import *
|
||||
import build123d.alg_compat as COMPAT
|
||||
|
||||
pip_count = 6
|
||||
|
||||
|
|
@ -23,7 +22,7 @@ wall_thickness = 1.2
|
|||
plan = Rectangle(width=block_length, height=block_width)
|
||||
|
||||
# Subtract an offset to create the block walls
|
||||
plan -= COMPAT.offset(
|
||||
plan -= offset(
|
||||
plan,
|
||||
amount=-wall_thickness,
|
||||
kind=Kind.INTERSECTION,
|
||||
|
|
@ -51,7 +50,7 @@ for loc in GridLocations(
|
|||
lego = extrude(plan, amount=base_height - wall_thickness)
|
||||
|
||||
# Create a box on the top of the walls
|
||||
for loc in Locations((0, 0, lego.vertices().max().Z)):
|
||||
for loc in Locations((0, 0, lego.vertices().sort_by().last.Z)):
|
||||
# Create the top of the block
|
||||
lego += loc * Box(
|
||||
length=block_length,
|
||||
|
|
@ -61,7 +60,7 @@ for loc in Locations((0, 0, lego.vertices().max().Z)):
|
|||
)
|
||||
|
||||
# Create a workplane on the top of the block
|
||||
plane = Plane(lego.faces().max())
|
||||
plane = Plane(lego.faces().sort_by().last)
|
||||
|
||||
# Create a grid of pips
|
||||
for loc in GridLocations(lego_unit_size, lego_unit_size, pip_count, 2):
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
from math import pi, sin
|
||||
from build123d import *
|
||||
import build123d.alg_compat as COMPAT
|
||||
|
||||
slice_count = 10
|
||||
|
||||
|
|
@ -10,8 +9,8 @@ for i in range(slice_count + 1):
|
|||
art += plane * Circle(10 * sin(i * pi / slice_count) + 5)
|
||||
|
||||
art = loft(art)
|
||||
top_bottom = art.faces(GeomType.PLANE)
|
||||
art = COMPAT.shell(art, openings=top_bottom, amount=0.5)
|
||||
top_bottom = art.faces().filter_by(GeomType.PLANE)
|
||||
art = offset(art, openings=top_bottom, amount=0.5)
|
||||
|
||||
if "show_object" in locals():
|
||||
show_object(art, name="art")
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
from build123d import *
|
||||
import build123d.alg_compat as COMPAT
|
||||
|
||||
height, width, thickness, padding = 60, 80, 10, 12
|
||||
screw_shaft_radius, screw_head_radius, screw_head_height = 1.5, 3, 3
|
||||
|
|
@ -7,20 +6,20 @@ bearing_axle_radius, bearing_radius, bearing_thickness = 4, 11, 7
|
|||
|
||||
# Build pillow block as an extruded sketch with counter bore holes
|
||||
plan = Rectangle(width, height)
|
||||
plan = COMPAT.fillet(plan, plan.vertices(), 5)
|
||||
plan = fillet(*plan.vertices(), radius=5, target=plan)
|
||||
pillow_block = extrude(plan, thickness)
|
||||
|
||||
plane = Plane(pillow_block.faces().max())
|
||||
plane = Plane(pillow_block.faces().sort_by().last)
|
||||
|
||||
pillow_block -= plane * COMPAT.CounterBore(
|
||||
pillow_block, bearing_axle_radius, bearing_radius, bearing_thickness
|
||||
pillow_block -= plane * CounterBoreHole(
|
||||
bearing_axle_radius, bearing_radius, bearing_thickness, height
|
||||
)
|
||||
for loc in GridLocations(width - 2 * padding, height - 2 * padding, 2, 2):
|
||||
pillow_block -= (
|
||||
plane
|
||||
* loc
|
||||
* COMPAT.CounterBore(
|
||||
pillow_block, screw_shaft_radius, screw_head_radius, screw_head_height
|
||||
* CounterBoreHole(
|
||||
screw_shaft_radius, screw_head_radius, screw_head_height, height
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
from build123d import *
|
||||
import build123d.alg_compat as COMPAT
|
||||
|
||||
l1 = Line((0, 0), (12, 0))
|
||||
l2 = RadiusArc(l1 @ 1, (15, 20), 50)
|
||||
|
|
@ -18,14 +17,14 @@ outline += Polyline(
|
|||
(0, (l5 @ 1).Y + 1),
|
||||
l1 @ 0,
|
||||
)
|
||||
profile = COMPAT.make_face(outline)
|
||||
profile = make_face(*outline.edges())
|
||||
vase = revolve(profile, axis=Axis.Y)
|
||||
vase = COMPAT.shell(vase, openings=vase.faces().max(Axis.Y), amount=-1)
|
||||
vase = offset(vase, openings=vase.faces().sort_by(Axis.Y).last, amount=-1)
|
||||
|
||||
top_edges = vase.edges(GeomType.CIRCLE).filter_by_position(Axis.Y, 60, 62)
|
||||
vase = fillet(vase, top_edges, radius=0.25)
|
||||
top_edges = vase.edges().filter_by(GeomType.CIRCLE).filter_by_position(Axis.Y, 60, 62)
|
||||
vase = fillet(*top_edges, radius=0.25, target=vase)
|
||||
|
||||
vase = fillet(vase, vase.edges().sort_by(Axis.Y)[0], radius=0.5)
|
||||
vase = fillet(vase.edges().sort_by(Axis.Y).first, radius=0.5, target=vase)
|
||||
|
||||
if "show_object" in locals():
|
||||
show_object(vase, name="vase")
|
||||
|
|
|
|||
|
|
@ -1,89 +0,0 @@
|
|||
#
|
||||
# TEMPORARY FOR MIGRATION ONLY
|
||||
#
|
||||
import copy
|
||||
from build123d import *
|
||||
from build123d.topology import class_LUT
|
||||
|
||||
from typing import Union, List
|
||||
|
||||
|
||||
class Hole:
|
||||
def __init__(self):
|
||||
raise NotImplemented
|
||||
|
||||
|
||||
class CounterSinkHole:
|
||||
def __init__(self):
|
||||
raise NotImplemented
|
||||
|
||||
|
||||
class CounterBoreHole:
|
||||
def __init__(self):
|
||||
raise NotImplemented
|
||||
|
||||
|
||||
def chamfer(
|
||||
obj: Union[Part, Sketch],
|
||||
objects: Union[List[Union[Edge, Vertex]], Edge, Vertex],
|
||||
length: float,
|
||||
length2: float = None,
|
||||
):
|
||||
if isinstance(obj, Part):
|
||||
compound = Compound.make_compound(
|
||||
[obj.solids()[0].chamfer(length, length2, list(objects))]
|
||||
)
|
||||
else:
|
||||
new_faces = []
|
||||
for face in obj.faces():
|
||||
vertices_in_face = [v for v in face.vertices() if v in objects]
|
||||
if vertices_in_face:
|
||||
new_faces.append(face.chamfer_2d(length, vertices_in_face))
|
||||
else:
|
||||
new_faces.append(face)
|
||||
compound = Compound.make_compound(new_faces)
|
||||
compound._dim = obj._dim
|
||||
return compound
|
||||
|
||||
|
||||
def fillet(
|
||||
obj: Union[Part, Sketch],
|
||||
objects: Union[List[Union[Edge, Vertex]], Edge, Vertex],
|
||||
radius: float,
|
||||
):
|
||||
if isinstance(obj, Part):
|
||||
compound = Compound.make_compound(
|
||||
[obj.solids()[0].fillet(radius, list(objects))]
|
||||
)
|
||||
else:
|
||||
new_faces = []
|
||||
for face in obj.faces():
|
||||
vertices_in_face = [v for v in face.vertices() if v in objects]
|
||||
if vertices_in_face:
|
||||
new_faces.append(face.fillet_2d(radius, vertices_in_face))
|
||||
else:
|
||||
new_faces.append(face)
|
||||
compound = Compound.make_compound(new_faces)
|
||||
compound._dim = obj._dim
|
||||
return compound
|
||||
|
||||
|
||||
def mirror(
|
||||
*objects: Union[Part, Sketch, Curve],
|
||||
about: Plane = Plane.XZ,
|
||||
):
|
||||
mirrored = [copy.deepcopy(o).mirror(about) for o in objects]
|
||||
compound = Compound.make_compound(mirrored)
|
||||
dim = objects[0]._dim if isinstance(objects, (list, tuple)) else objects._dim
|
||||
return class_LUT[dim](compound.wrapped)
|
||||
|
||||
|
||||
def make_face(objs: Union[Sketch, List[Edge]]):
|
||||
if isinstance(objs, Sketch) and objs._dim == 1:
|
||||
edges = objs.edges()
|
||||
elif isinstance(objs, (tuple, list)):
|
||||
edges = objs
|
||||
else:
|
||||
edges = [objs]
|
||||
|
||||
return Sketch.make_compound([Face.make_from_wires(*Wire.combine(edges))])
|
||||
Loading…
Add table
Add a link
Reference in a new issue