def cylinder(diameter: float, height: float, segments: int = 48): n = node( linear_extrude(height=height)(circle(diameter / 2.0, segments=segments))) n.set_origin(x=-diameter / 2, y=-diameter / 2) n.set_center(z=height / 2) return n
def test_scad_render_to_file(self): a = circle(10) # No header, no included original code with TemporaryFileBuffer() as tmp: scad_render_to_file(a, filepath=tmp.name, include_orig_code=False) actual = tmp.contents expected = '\n\ncircle(r = 10);' # scad_render_to_file also adds a date & version stamp before scad code; # That won't match here, so just make sure the correct code is at the end self.assertTrue(actual.endswith(expected)) # Header with TemporaryFileBuffer() as tmp: scad_render_to_file(a, filepath=tmp.name, include_orig_code=False, file_header='$fn = 24;') actual = tmp.contents expected = '$fn = 24;\n\n\ncircle(r = 10);' self.assertTrue(actual.endswith(expected)) # Test out_dir specification, both using an existing dir & creating one # Using existing directory with TemporaryFileBuffer() as tmp: out_dir = Path(tmp.name).parent expected = (out_dir / 'test_solidpython.scad').as_posix() actual = scad_render_to_file(a, out_dir=out_dir) self.assertEqual(expected, actual) # Creating a directory on demand with TemporaryFileBuffer() as tmp: out_dir = Path(tmp.name).parent / 'SCAD' expected = (out_dir / 'test_solidpython.scad').as_posix() actual = scad_render_to_file(a, out_dir=out_dir) self.assertEqual(expected, actual)
def solid_nut(screw_type="m3"): dims = screw_dimensions[screw_type.lower()] outer_rad = dims["nut_outer_diam"] ret = linear_extrude(height=dims["nut_thickness"])(circle(outer_rad, segments=6)) return ret
def roller(): radius = 31.75/2 ring = so.rotate_extrude(360)(so.translate((radius + 3.175/2,0))(so.circle(d=3.175))) return so.mirror((0,0,1))(so.cylinder(r=radius+3.175/2-0.8, h=13) - big_hex_nut - so.translate((0,0,6.5))(ring) - so.cylinder(r=15.2/2 + 0.1, h=13))
def main(params: Params): # face face_profile = roundrect( [LGX_FACE_WIDTH, LGX_FACE_HEIGHT + params.lgx_face_extra_height], params.face_radius, ) cutout_profile = roundrect([params.poe_face_width, params.poe_face_height], params.poe_face_radius) cutout_x = LGX_FACE_WIDTH / 2 - params.poe_face_width / 2 cutout_y = params.poe_face_lift + params.platform_thickness cutout = translate([cutout_x, cutout_y, 0])(cutout_profile) cutout_extrude = debug( down(params.lgx_rack_thickness)( linear_extrude(params.face_thickness + params.lgx_rack_thickness)(cutout))) post = circle(d=params.face_post_d) posts = post + right(params.face_post_separation)(post) posts = translate([ LGX_FACE_WIDTH / 2 - params.face_post_separation / 2, LGX_FACE_HEIGHT / 2, 0 ])(posts) face = difference()(face_profile, posts) face_extrusion = linear_extrude(height=params.face_thickness)(face) tray_depth = (params.platform_thickness + params.poe_depth + params.lgx_rack_thickness) # tray tray = linear_extrude(height=params.platform_thickness)( square(size=[LGX_PLATFORM_WIDTH, tray_depth])) poe_holder_outer_params = [ params.poe_width + params.platform_thickness * 2, tray_depth, ] poe_holder_profile = difference()( square(poe_holder_outer_params), right(params.platform_thickness)(forward(params.lgx_rack_thickness)( square([ params.poe_width, params.poe_depth, ]))), ) poe_holder_extrude = linear_extrude( height=params.poe_retainer_height)(poe_holder_profile) poe_holder = translate([ LGX_PLATFORM_WIDTH / 2 - poe_holder_outer_params[0] / 2, 0, params.platform_thickness, ])(poe_holder_extrude) tray = union()(poe_holder, tray) tray = rotate([270, 0, 0])(translate( [LGX_FACE_WIDTH / 2 - LGX_PLATFORM_WIDTH / 2, 0, 0])(tray)) # support support_start_inset = (params.platform_thickness + LGX_FACE_WIDTH / 2 - LGX_PLATFORM_WIDTH / 2) point_extent = LGX_FACE_HEIGHT - params.platform_thickness support_profile = polygon([[0, 0], [0, point_extent], [point_extent, 0]]) support = linear_extrude(height=params.platform_thickness)(support_profile) support = rotate([270, 0, 90])(support) support_left = translate([support_start_inset, 0, 0])(support) support_right = translate([ support_start_inset + LGX_PLATFORM_WIDTH - params.platform_thickness, 0, 0 ])(support) return difference()(union()(face_extrusion, tray, support_left, support_right), cutout_extrude)