Skip to content

Commit 56dbddf

Browse files
authored
Merge pull request #147 from cristobaltapia/fix-issue-125
Change code to generate Bin objects
2 parents 3cb65f7 + 6bb6513 commit 56dbddf

15 files changed

Lines changed: 413 additions & 110 deletions

.vscode/launch.json

Lines changed: 0 additions & 14 deletions
This file was deleted.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ dev = [
2020
"Sphinx",
2121
"sphinx-rtd-theme",
2222
"sphinx_design",
23+
"debugpy>=1.8.20",
2324
]
2425

2526
[build-system]

src/gridfinity_build123d/base.py

Lines changed: 63 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@
1111
BasePartObject,
1212
BuildPart,
1313
BuildSketch,
14-
Location,
14+
Locations,
1515
Mode,
1616
Rectangle,
1717
RotationLike,
1818
add,
1919
extrude,
20-
fillet,
21-
offset,
2220
)
2321

2422
from .constants import gridfinity_standard
@@ -62,31 +60,27 @@ def __init__(
6260

6361
with BuildPart() as base:
6462
base_block = BaseBlock(features=features, mode=Mode.PRIVATE)
65-
Utils.place_by_grid(base_block, grid)
66-
67-
top_face = base.faces().sort_by(Axis.Z)[-1]
68-
edges = (
69-
base.edges()
70-
.filter_by(Axis.Z)
71-
.filter_by(
72-
lambda edge: any(
73-
True for vertex in edge.vertices() if vertex in top_face.vertices()
74-
),
75-
)
63+
Utils.place_by_grid(
64+
base_block,
65+
grid,
66+
width=gridfinity_standard.grid.size,
67+
length=gridfinity_standard.grid.size,
7668
)
77-
fillet(objects=edges, radius=gridfinity_standard.grid.radius)
7869

79-
with BuildPart() as cutter:
80-
with BuildSketch(Location((0, 0, base.part.bounding_box().max.Z))):
81-
add(base.faces().sort_by(Axis.Z)[-1])
82-
offset(amount=-gridfinity_standard.grid.tollerance / 2)
83-
extrude(amount=base.part.bounding_box().size.Z, dir=(0, 0, -1))
70+
top_face_1 = base.faces().sort_by(Axis.Z)[-1]
71+
z_top = top_face_1.bounding_box().min.Z
8472

85-
with BuildPart() as part:
86-
add(base)
87-
add(cutter, mode=Mode.INTERSECT)
73+
with Locations((0, 0, z_top)):
74+
Utils.create_bin_platform(
75+
grid,
76+
align=(
77+
Align.CENTER,
78+
Align.CENTER,
79+
Align.MIN,
80+
),
81+
)
8882

89-
super().__init__(part.part, rotation, align, mode)
83+
super().__init__(base.part, rotation, align, mode)
9084

9185

9286
class BaseEqual(Base):
@@ -122,9 +116,7 @@ def __init__(
122116
class BaseBlock(BasePartObject):
123117
"""BaseBlock.
124118
125-
Create a single baseblock with rectangular platform. The rectangular platform makes it
126-
posible to stack the blocks in x and y direction. After creating an array it is meant to
127-
cut the platform to size.
119+
Create a single baseblock.
128120
"""
129121

130122
def __init__(
@@ -155,14 +147,55 @@ def __init__(
155147
gridfinity_standard.stacking_lip.offset,
156148
)
157149

158-
with BuildSketch(baseblock.faces().sort_by(Axis.Z)[-1]) as rect2:
150+
for feature in features:
151+
feature.apply(baseblock)
152+
153+
super().__init__(baseblock.part, rotation, align, mode)
154+
155+
156+
class BaseBlockPlatform(BasePartObject):
157+
"""BaseBlockPlatform.
158+
159+
Create a single baseblock with a rectangular platform on top. The rectangular platform makes it
160+
posible to stack the blocks in x and y direction. After creating an array it is meant to cut or
161+
offset the platform to size.
162+
"""
163+
164+
def __init__(
165+
self,
166+
features: ObjectFeature | list[ObjectFeature] | None = None,
167+
rotation: RotationLike = (0, 0, 0),
168+
align: Align | tuple[Align, Align, Align] | None = None,
169+
mode: Mode = Mode.ADD,
170+
):
171+
"""Construct BaseBlockPlatform.
172+
173+
Args:
174+
features (ObjectFeature | list[ObjectFeature] | None, optional): ObjectFeature
175+
or list of ObjectFeatures. Defaults to None.
176+
rotation (RotationLike, optional): Angels to rotate around axes. Defaults to (0, 0, 0).
177+
align (Union[Align, tuple[Align, Align, Align]], optional): Align min center of max of
178+
object. Defaults to None.
179+
mode (Mode, optional): Combination mode. Defaults to Mode.ADD.
180+
"""
181+
if not features:
182+
features = []
183+
184+
features = features if isinstance(features, Iterable) else [features]
185+
186+
base_block = BaseBlock(features=[], rotation=rotation, mode=Mode.ADD)
187+
188+
with BuildPart() as baseblock_platform:
189+
add(base_block)
190+
191+
with BuildSketch(baseblock_platform.faces().sort_by(Axis.Z)[-1]) as rect2:
159192
Rectangle(gridfinity_standard.grid.size, gridfinity_standard.grid.size)
160193
extrude(
161194
to_extrude=rect2.sketch,
162195
amount=gridfinity_standard.bottom.platform_height,
163196
)
164197

165198
for feature in features:
166-
feature.apply(baseblock)
199+
feature.apply(baseblock_platform)
167200

168-
super().__init__(baseblock.part, rotation, align, mode)
201+
super().__init__(baseblock_platform.part, rotation, align, mode)

src/gridfinity_build123d/compartments.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,28 @@ def create(
7474
for feature in self.features:
7575
feature.apply(part)
7676

77-
fillet_edges = [
78-
i for i in part.edges() if i not in part.faces().sort_by(Axis.Z)[-1].edges()
79-
]
77+
bbox = part.part.bounding_box()
78+
79+
# Select only vertical edges
80+
fillet_edges = (
81+
part.edges()
82+
.filter_by(Axis.Z)
83+
.filter_by_position(
84+
Axis.Z,
85+
minimum=bbox.min.Z,
86+
maximum=bbox.max.Z - 1.1,
87+
)
88+
)
89+
90+
# Select the rest of the edges (excluding the top face and lower
91+
# edge of the label)
92+
fillet(fillet_edges, gf_bin.inner_radius_v)
93+
94+
fillet_edges = part.edges().filter_by_position(
95+
Axis.Z,
96+
minimum=bbox.min.Z,
97+
maximum=bbox.max.Z - 1.1,
98+
)
8099

81100
fillet(fillet_edges, gf_bin.inner_radius)
82101

src/gridfinity_build123d/constants.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,13 @@ class screw:
5252
class gf_bin:
5353
"""Bin constants."""
5454

55-
inner_radius = 1.8
56-
inner_wall = 1.2
55+
inner_wall = 0.95
56+
# Radius used for vertical inner fillets
57+
inner_radius_v = (
58+
gridfinity_standard.grid.radius - inner_wall - gridfinity_standard.grid.tollerance / 2
59+
)
60+
# Radius used for the rest of the inner fillets
61+
inner_radius = 1.2
5762

5863
@dataclass
5964
class label:

src/gridfinity_build123d/features.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,8 @@ def create_obj( # noqa: D102
488488
Polyline(
489489
ln3 @ 1,
490490
((ln3 @ 1).X, -3.5),
491-
((ln3 @ 1).X + 1.47, -5.6),
492-
((ln1 @ 0).X, -5.6),
491+
((ln3 @ 1).X + 1.47, -5.9),
492+
((ln1 @ 0).X, -5.9),
493493
ln1 @ 0,
494494
)
495495
make_face()

0 commit comments

Comments
 (0)