From a9b94452abe720131c1fa54f36510887e44e5f6d Mon Sep 17 00:00:00 2001 From: Dave Cowden Date: Sat, 6 Dec 2014 10:19:38 -0500 Subject: [PATCH] Added Lego Brick Example: --- CadQuery/Examples/Ex026_Lego_Brick.py | 53 +++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 CadQuery/Examples/Ex026_Lego_Brick.py diff --git a/CadQuery/Examples/Ex026_Lego_Brick.py b/CadQuery/Examples/Ex026_Lego_Brick.py new file mode 100644 index 0000000..3f44293 --- /dev/null +++ b/CadQuery/Examples/Ex026_Lego_Brick.py @@ -0,0 +1,53 @@ +# This example is meant to be used from within the CadQuery module of FreeCAD. +# This script can create any regular rectangular Lego(TM) Brick +import cadquery +import Part + +##### +# Inputs +###### +lbumps = 4 # number of bumps long +wbumps = 4 # number of bumps wide +thickness = 3.2 # this is a thin lego +# thickness = 9.6 # a thick lego + +# +# Lego Brick Constants-- these make a lego brick a lego :) +# +pitch = 8.0 +clearance = 0.1 +height = 3.2 +bumpDiam = 4.8 +bumpHeight = 1.8 + +t = (pitch - (2 * clearance) - bumpDiam) / 2.0 +postDiam = pitch - t # works out to 6.5 +total_length = lbumps*pitch - 2.0*clearance +total_width = wbumps*pitch - 2.0*clearance + +# make the base +s = cadquery.Workplane("XY").box(total_length, total_width, height) + +# shell inwards not outwards +s = s.faces("Z").workplane(). \ + rarray(pitch, pitch, lbumps, wbumps, True).circle(bumpDiam / 2.0) \ + .extrude(bumpHeight) + +# add posts on the bottom. posts are different diameter depending on geometry +# solid studs for 1 bump, tubes for multiple, none for 1x1 +tmp = s.faces(" 1 and wbumps > 1: + tmp = tmp.rarray(pitch, pitch, lbumps - 1, wbumps - 1, center=True). \ + circle(postDiam / 2.0).circle(bumpDiam / 2.0).extrude(height - t) +elif lbumps > 1: + tmp = tmp.rarray(pitch, pitch, lbumps - 1, 1, center=True). \ + circle(t).extrude(height - t) +elif wbumps > 1: + tmp = tmp.rarray(pitch, pitch, 1, wbumps - 1, center=True). \ + circle(t).extrude(height - t) + +Part.show(tmp.toFreecad())