Skip to content

Commit

Permalink
Added smarter automatic object naming. Updated console scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelgale committed Jan 10, 2024
1 parent aa786d7 commit fbb7142
Show file tree
Hide file tree
Showing 13 changed files with 257 additions and 88 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ clean-pyc: ## remove Python file artifacts
clean-test: ## remove test and coverage artifacts
@find . -name '*.step' -exec rm -f {} +
@find . -name '*.stl' -exec rm -f {} +
@find . -name '*.svg' -exec rm -f {} +
@rm -f .coverage
@rm -fr htmlcov/

Expand Down
2 changes: 2 additions & 0 deletions cqgridfinity/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
(GR_BOX_CHAMF_H * SQRT2, 45),
)

# Rugged Box constant parameters
GR_RBOX_WALL = 2.5
GR_RBOX_FLOOR = 1.2
GR_RBOX_CWALL = 10.0
Expand Down Expand Up @@ -137,6 +138,7 @@
GR_LID_HANDLE_W = 70
GR_SIDE_HANDLE_W = 60

GR_HINGE_SZ = 32
GR_HINGE_D = 3
GR_HINGE_W1 = 5.5
GR_HINGE_H1 = 2.7
Expand Down
52 changes: 32 additions & 20 deletions cqgridfinity/gf_baseplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,37 @@ class GridfinityBaseplate(GridfinityObject):
width_y - width in U (42 mm / U)
ext_depth - extrude bottom face by an extra amount in mm
straight_bottom - remove bottom chamfer and replace with straight side
corner_screws - add countersink mounting screws to the inside corners
corner_tab_size - size of mounting screw corner tabs
csk_hole - mounting screw hole diameter
csk_diam - mounting screw countersink diameter
csk_angle - mounting screw countersink angle
"""

def __init__(self, length_u, width_u, **kwargs):
super().__init__()
self.length_u = length_u
self.width_u = width_u
self.ext_depth = 0 # extra extrusion depth below bottom face
self.straight_bottom = False # remove chamfered bottom lip
self.ext_depth = 0
self.straight_bottom = False
self.corner_screws = False
self.corner_tab_size = 21
self.csk_hole = 5.0
self.csk_diam = 10.0
self.csk_angle = 82
for k, v in kwargs.items():
if k in self.__dict__:
if k in self.__dict__ and v is not None:
self.__dict__[k] = v
if self.corner_screws:
self.ext_depth = max(self.ext_depth, 5.0)

def _corner_pts(self, offset=0):
oxy = (self.corner_tab_size - offset) / 2
return [
(i * (self.length / 2 - oxy), j * (self.width / 2 - oxy), 0)
for i in (-1, 1)
for j in (-1, 1)
]

def render(self):
profile = GR_BASE_PROFILE if not self.straight_bottom else GR_STR_BASE_PROFILE
Expand All @@ -78,24 +97,17 @@ def render(self):
.cut(rc)
)
if self.corner_screws:
rs = cq.Sketch().rect(21, 21)
rs = cq.Workplane("XY").placeSketch(rs).extrude(self.ext_depth)
rs = rs.faces(">Z").cskHole(5, cskDiameter=10, cskAngle=82)
pts = [
(i * (self.length / 2 - 10.5), j * (self.width / 2 - 10.5), 0)
for i in (-1, 1)
for j in (-1, 1)
]
rp = composite_from_pts(rs, pts)
depth = self.ext_depth
rs = cq.Sketch().rect(self.corner_tab_size, self.corner_tab_size)
rs = cq.Workplane("XY").placeSketch(rs).extrude(depth)
rs = rs.faces(">Z").cskHole(
self.csk_hole, cskDiameter=self.csk_diam, cskAngle=self.csk_angle
)
rp = composite_from_pts(rs, self._corner_pts())
rp = recentre(rp, "XY")
r = r.union(rp)
r = r.edges(
VerticalEdgeSelector(self.ext_depth) & HasZCoordinateSelector(0)
).fillet(GR_RAD)
pts = [
(i * (self.length / 2 - 10), j * (self.width / 2 - 10), 0)
for i in (-1, 1)
for j in (-1, 1)
]
r = r.edges(VerticalEdgeSelector(depth) & HasZCoordinateSelector(0)).fillet(
GR_RAD
)

return r
16 changes: 14 additions & 2 deletions cqgridfinity/gf_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import cadquery as cq
from cqkit import HasZCoordinateSelector, VerticalEdgeSelector, FlatEdgeSelector
from cqkit.cq_helpers import multi_extrude, rounded_rect_sketch, composite_from_pts
from cqkit.cq_helpers import rounded_rect_sketch, composite_from_pts
from cqgridfinity import *


Expand All @@ -54,6 +54,12 @@ class GridfinityBox(GridfinityObject):
- no_lip : removes the contoured lip on the top module used for stacking
- length_div, width_div : subdivides the box into sub-compartments in
length and/or width.
- lite_style : render box as an economical shell without elevated floor
- unsupported_holes : render bottom holes as 3D printer friendly versions
which can be printed without supports
- label_width : width of top label ledge face overhang
- label_height : height of label ledge overhang
- scoop_rad : radius of the bottom scoop feature
"""

Expand Down Expand Up @@ -103,7 +109,13 @@ def render(self):
"Cannot select both holes and lite box styles together"
)
if self.wall_th > 1.5:
raise ValueError("Wall thickness cannot exceed 1.5 for lite box style")
raise ValueError(
"Wall thickness cannot exceed 1.5 mm for lite box style"
)
if self.wall_th > 2.5:
raise ValueError("Wall thickness cannot exceed 2.5 mm")
if self.wall_th < 0.5:
raise ValueError("Wall thickness must be at least 0.5 mm")
r = self.render_shell()
rd = self.render_dividers()
rs = self.render_scoops()
Expand Down
5 changes: 5 additions & 0 deletions cqgridfinity/gf_drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def render(self, arrows_top=True, arrows_bottom=True):
rc = self.alignment_feature(as_cutter=False, horz=False)
r = r.union(rc.translate((self.width_th / 2, sp_width, 0)))
self._cq_obj = r
self._obj_label = "corner_spacer"
return r

def alignment_feature(self, as_cutter=False, horz=True):
Expand Down Expand Up @@ -268,6 +269,7 @@ def render_length_filler(self, alignment_type="peg"):
r = r.union(ra.translate((self.length_fill / 2, 0, 0)))
r = r.union(ra.translate((-self.length_fill / 2, 0, 0)))
self._cq_obj = r
self._obj_label = "length_spacer"
return r

def render_width_filler(self, arrows_top=True, arrows_bottom=True):
Expand All @@ -288,6 +290,7 @@ def render_width_filler(self, arrows_top=True, arrows_bottom=True):
r = r.cut(ra.translate((0, self.width_fill / 2, 0)))
r = r.cut(ra.translate((0, -self.width_fill / 2, 0)))
self._cq_obj = r
self._obj_label = "width_spacer"
return r

def render_full_set(self, include_baseplate=False):
Expand Down Expand Up @@ -321,6 +324,7 @@ def render_full_set(self, include_baseplate=False):
rb = bp.render().translate((self.size[0] / 2, self.size[1] / 2, 0))
r = r.union(rb)
self._cq_obj = r
self._obj_label = "full_set"
return r

def render_half_set(self):
Expand Down Expand Up @@ -362,4 +366,5 @@ def render_half_set(self):
)
)
self._cq_obj = r
self._obj_label = "half_set"
return r
20 changes: 18 additions & 2 deletions cqgridfinity/gf_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(self, **kwargs):
self.width_u = 1
self.height_u = 1
self._cq_obj = None
self._obj_label = None
for k, v in kwargs.items():
if k in self.__dict__:
self.__dict__[k] = v
Expand Down Expand Up @@ -192,7 +193,7 @@ def filename(self, prefix=None, path=None):
if self.lite_style:
prefix = prefix + "lite_"
elif isinstance(self, GridfinityDrawerSpacer):
prefix = "gf_spacer_"
prefix = "gf_drawer_"
elif isinstance(self, GridfinityRuggedBox):
prefix = "gf_ruggedbox_"
else:
Expand All @@ -212,6 +213,8 @@ def filename(self, prefix=None, path=None):
fn = fn + "x%d" % (self.width_div)
else:
fn = fn + "_div_x%d" % (self.width_div)
if abs(self.wall_th - GR_WALL) > 1e-3:
fn = fn + "_%.2f" % (self.wall_th)
if self.no_lip:
fn = fn + "_basic"
if self.holes:
Expand All @@ -225,6 +228,8 @@ def filename(self, prefix=None, path=None):
fn = fn + "_labels"
elif isinstance(self, GridfinityRuggedBox):
fn = fn + "x%d" % (self.height_u)
if self._obj_label is not None:
fn = fn + "_%s" % (self._obj_label)
if self.front_handle or self.front_label:
fn = fn + "_fr-"
if self.front_handle:
Expand All @@ -241,6 +246,14 @@ def filename(self, prefix=None, path=None):
fn = fn + "_stack"
if self.lid_baseplate:
fn = fn + "_lidbp"
elif isinstance(self, GridfinityDrawerSpacer):
if self._obj_label is not None:
fn = fn + "_%s" % (self._obj_label)
elif isinstance(self, GridfinityBaseplate):
if self.ext_depth > 0:
fn = fn + "x%.1f" % (self.ext_depth)
if self.corner_screws:
fn = fn + "_screwtabs"
return fn

def save_step_file(self, filename=None, path=None, prefix=None):
Expand All @@ -251,7 +264,10 @@ def save_step_file(self, filename=None, path=None, prefix=None):
)
if not fn.lower().endswith(".step"):
fn = fn + ".step"
export_step_file(self.cq_obj, fn)
if isinstance(self.cq_obj, cq.Assembly):
self.cq_obj.save(fn)
else:
export_step_file(self.cq_obj, fn)

def save_stl_file(
self, filename=None, path=None, prefix=None, tol=1e-2, ang_tol=0.1
Expand Down
Loading

0 comments on commit fbb7142

Please sign in to comment.