Skip to content

Commit

Permalink
Fixed examples except for extruder support
Browse files Browse the repository at this point in the history
  • Loading branch information
jmwright committed Mar 16, 2021
1 parent da69d51 commit 2e8e9db
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 73 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ A place to share CadQuery scripts, modules, tutorials and projects

* [Parametric_Enclosure.py](examples/Parametric_Enclosure.py) - Standard CadQuery example of an electronics enclosure with a base, fastener bosses, and a lid

<img src="examples/images/parametric_enclosure.png" width="600"/>
<img src="examples/images/Parametric_Enclosure.png" width="600"/>

* [Reinforce_Junction_UsingFillet.py](examples/Reinforce_Junction_UsingFillet.py) - Example of using fillets to reinforce a joint, reducing stress concentrators at the joint

Expand Down Expand Up @@ -44,8 +44,17 @@ A place to share CadQuery scripts, modules, tutorials and projects
<img src="examples/images/cylindrical_gear.png" width="600"/>

* [Remote_Enclosure.py](examples/Remote_Enclosure.py) - An electronics enclosure created to be mounted on motorcycle handlebars

<img src="examples/images/Remote_Enclosure.png" width="600"/>

* [Classic_OCC_Bottle.py](examples/Classic_OCC_Bottle.py) - Standard OCCT bottle example, implemented using the CadQuery API

<img src="examples/images/Classic_OCC_Bottle.png" width="600"/>

* [Numpy.py](examples/Numpy.py) - Example of integrating Numpy with CadQuery

<img src="examples/images/Numpy.png" width="600"/>

* [3D_Printer_Extruder_Support.py](examples/3D_Printer_Extruder_Support.py) - Designed for mounting hotend to an i3 X-carriage inspired by the P3steel Toolson

### Tutorials
Expand Down
14 changes: 7 additions & 7 deletions examples/Classic_OCC_Bottle.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import cadquery as cq

# Set up the length, width, and thickness
(L, w, t) = (20.0, 6.0, 3.0)
(L,w,t) = (20.0, 6.0, 3.0)
s = cq.Workplane("XY")

# Draw half the profile of the bottle and extrude it
p = s.center(-L / 2.0, 0).vLine(w / 2.0) \
.threePointArc((L / 2.0, w / 2.0 + t), (L, w / 2.0)).vLine(-w / 2.0) \
.mirrorX().extrude(30.0, True)
# Draw half the profile of the bottle, mirror it, and extrude it
p = (s.center(-L/2.0, 0).vLine(w/2.0)
.threePointArc((L/2.0, w/2.0 + t),(L, w/2.0)).vLine(-w/2.0)
.mirrorX().extrude(30.0,True))

# Make the neck
p.faces(">Z").workplane().circle(3.0).extrude(2.0, True)
p = p.faces(">Z").workplane(centerOption="CenterOfMass").circle(3.0).extrude(2.0,True)

# Make a shell
# Make the bottle a shell
result = p.faces(">Z").shell(0.3)

# Displays the result of this script
Expand Down
3 changes: 1 addition & 2 deletions examples/Numpy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# NOTE: This example may not run correctly in some revisions of FreeCAD 0.16
import numpy as np
import cadquery as cq

Expand All @@ -19,7 +18,7 @@

result = cq.Workplane('XY') \
.polyline(pts).close().extrude(2) \
.faces('+Z').workplane().circle(side / 2).extrude(1)
.faces('+Z').workplane(centerOption="CenterOfMass").circle(side / 2).extrude(1)

# Render the solid
show_object(result)
119 changes: 58 additions & 61 deletions examples/Parametric_Enclosure.py
Original file line number Diff line number Diff line change
@@ -1,77 +1,74 @@
import cadquery as cq

# Parameter definitions
p_outerWidth = 100.0 # Outer width of box enclosure
p_outerLength = 150.0 # Outer length of box enclosure
p_outerHeight = 50.0 # Outer height of box enclosure

p_thickness = 3.0 # Thickness of the box walls
p_sideRadius = 10.0 # Radius for the curves around the sides of the bo
p_topAndBottomRadius = 2.0 # Radius for the curves on the top and bottom edges

p_screwpostInset = 12.0 # How far in from the edges the screwposts should be
p_screwpostID = 4.0 # Inner diameter of the screwpost holes, should be roughly screw diameter not including threads
p_screwpostOD = 10.0 # Outer diameter of the screwposts. Determines overall thickness of the posts

p_boreDiameter = 8.0 # Diameter of the counterbore hole, if any
p_boreDepth = 1.0 # Depth of the counterbore hole, if
p_countersinkDiameter = 0.0 # Outer diameter of countersink. Should roughly match the outer diameter of the screw head
p_countersinkAngle = 90.0 # Countersink angle (complete angle between opposite sides, not from center to one side)
p_lipHeight = 1.0 # Height of lip on the underside of the lid. Sits inside the box body for a snug fit.

# Outer shell
oshell = cq.Workplane("XY").rect(p_outerWidth, p_outerLength) \
.extrude(p_outerHeight + p_lipHeight)

# Weird geometry happens if we make the fillets in the wrong order
# parameter definitions
p_outerWidth = 100.0 #Outer width of box enclosure
p_outerLength = 150.0 #Outer length of box enclosure
p_outerHeight = 50.0 #Outer height of box enclosure

p_thickness = 3.0 #Thickness of the box walls
p_sideRadius = 10.0 #Radius for the curves around the sides of the box
p_topAndBottomRadius = 2.0 #Radius for the curves on the top and bottom edges of the box

p_screwpostInset = 12.0 #How far in from the edges the screw posts should be place.
p_screwpostID = 4.0 #Inner Diameter of the screw post holes, should be roughly screw diameter not including threads
p_screwpostOD = 10.0 #Outer Diameter of the screw posts.\nDetermines overall thickness of the posts

p_boreDiameter = 8.0 #Diameter of the counterbore hole, if any
p_boreDepth = 1.0 #Depth of the counterbore hole, if
p_countersinkDiameter = 0.0 #Outer diameter of countersink. Should roughly match the outer diameter of the screw head
p_countersinkAngle = 90.0 #Countersink angle (complete angle between opposite sides, not from center to one side)
p_flipLid = True #Whether to place the lid with the top facing down or not.
p_lipHeight = 1.0 #Height of lip on the underside of the lid.\nSits inside the box body for a snug fit.

# outer shell
oshell = cq.Workplane("XY").rect(p_outerWidth,p_outerLength).extrude(p_outerHeight + p_lipHeight)

# weird geometry happens if we make the fillets in the wrong order
if p_sideRadius > p_topAndBottomRadius:
oshell.edges("|Z").fillet(p_sideRadius)
oshell.edges("#Z").fillet(p_topAndBottomRadius)
oshell = oshell.edges("|Z").fillet(p_sideRadius)
oshell = oshell.edges("#Z").fillet(p_topAndBottomRadius)
else:
oshell.edges("#Z").fillet(p_topAndBottomRadius)
oshell.edges("|Z").fillet(p_sideRadius)
oshell = oshell.edges("#Z").fillet(p_topAndBottomRadius)
oshell = oshell.edges("|Z").fillet(p_sideRadius)

# Inner shell
ishell = oshell.faces("<Z").workplane(p_thickness, True)\
.rect((p_outerWidth - 2.0 * p_thickness), (p_outerLength - 2.0 * p_thickness))\
.extrude((p_outerHeight - 2.0 * p_thickness), False) # Set combine false to produce just the new boss
ishell.edges("|Z").fillet(p_sideRadius - p_thickness)
# inner shell
ishell = (oshell.faces("<Z").workplane(p_thickness,True)
.rect((p_outerWidth - 2.0* p_thickness),(p_outerLength - 2.0*p_thickness))
.extrude((p_outerHeight - 2.0*p_thickness),False) #set combine false to produce just the new boss
)
ishell = ishell.edges("|Z").fillet(p_sideRadius - p_thickness)

# Make the box outer box
# make the box outer box
box = oshell.cut(ishell)

# Make the screwposts
POSTWIDTH = (p_outerWidth - 2.0 * p_screwpostInset)
POSTLENGTH = (p_outerLength - 2.0 * p_screwpostInset)

postCenters = box.faces(">Z").workplane(-p_thickness)\
.rect(POSTWIDTH, POSTLENGTH, forConstruction=True)\
.vertices()
# make the screw posts
POSTWIDTH = (p_outerWidth - 2.0*p_screwpostInset)
POSTLENGTH = (p_outerLength -2.0*p_screwpostInset)

for v in postCenters.all():
v.circle(p_screwpostOD / 2.0).circle(p_screwpostID / 2.0)\
.extrude((-1.0) * ((p_outerHeight + p_lipHeight) - (2.0 * p_thickness)), True)
box = (box.faces(">Z").workplane(-p_thickness)
.rect(POSTWIDTH,POSTLENGTH,forConstruction=True)
.vertices().circle(p_screwpostOD/2.0).circle(p_screwpostID/2.0)
.extrude((-1.0)*(p_outerHeight + p_lipHeight -p_thickness ),True))

# Split lid into top and bottom parts
(lid, bottom) = box.faces(">Z").workplane(-p_thickness - p_lipHeight).split(keepTop=True, keepBottom=True).all()
# split lid into top and bottom parts
(lid,bottom) = box.faces(">Z").workplane(-p_thickness -p_lipHeight ).split(keepTop=True,keepBottom=True).all() #splits into two solids

# Translate the lid, and subtract the bottom from it to produce the lid inset
lowerLid = lid.translate((0, 0, -p_lipHeight))
cutlip = lowerLid.cut(bottom).translate((p_outerWidth + p_thickness, 0, p_thickness - p_outerHeight + p_lipHeight))
# translate the lid, and subtract the bottom from it to produce the lid inset
lowerLid = lid.translate((0,0,-p_lipHeight))
cutlip = lowerLid.cut(bottom).translate((p_outerWidth + p_thickness ,0,p_thickness - p_outerHeight + p_lipHeight))

# Compute centers for counterbore/countersink or counterbore
topOfLidCenters = cutlip.faces(">Z").workplane().rect(POSTWIDTH, POSTLENGTH, forConstruction=True).vertices()
# compute centers for counterbore/countersink or counterbore
topOfLidCenters = cutlip.faces(">Z").workplane().rect(POSTWIDTH,POSTLENGTH,forConstruction=True).vertices()

# Add holes of the desired type
# add holes of the desired type
if p_boreDiameter > 0 and p_boreDepth > 0:
topOfLid = topOfLidCenters.cboreHole(p_screwpostID, p_boreDiameter, p_boreDepth, (2.0) * p_thickness)
topOfLid = topOfLidCenters.cboreHole(p_screwpostID,p_boreDiameter,p_boreDepth,(2.0)*p_thickness)
elif p_countersinkDiameter > 0 and p_countersinkAngle > 0:
topOfLid = topOfLidCenters.cskHole(p_screwpostID, p_countersinkDiameter, p_countersinkAngle, (2.0) * p_thickness)
topOfLid = topOfLidCenters.cskHole(p_screwpostID,p_countersinkDiameter,p_countersinkAngle,(2.0)*p_thickness)
else:
topOfLid= topOfLidCenters.hole(p_screwpostID, 2.0 * p_thickness)
topOfLid= topOfLidCenters.hole(p_screwpostID,(2.0)*p_thickness)

# Return the combined result
result = topOfLid.combineSolids(bottom)
# flip lid upside down if desired
if p_flipLid:
topOfLid = topOfLid.rotateAboutCenter((1,0,0),180)

# Displays the result of this script
show_object(result)
# return the combined result
result =topOfLid.union(bottom)
4 changes: 2 additions & 2 deletions examples/Remote_Enclosure.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
width = 2.2 # Nominal x dimension of the part
height = 0.5 # Height from bottom top to the top of the top :P
length = 1.5 # Nominal y dimension of the part
trapezoidFudge = 0.7 # ratio of trapezoid bases. set to 1.0 for cube
trapezoidFudge = 1.5 # ratio of trapezoid bases. set to 1.0 for cube
xHoleOffset = 0.500 # Holes are distributed symmetrically about each axis
yHoleOffset = 0.500
zFilletRadius = 0.50 # Fillet radius of corners perp. to Z axis.
Expand Down Expand Up @@ -54,7 +54,7 @@ def base(h):
.shell(-wallThickness)
# cut five button holes into the top face in a cross pattern.
.faces(">Z")
.workplane()
.workplane(centerOption="CenterOfMass")
.pushPoints([(0, 0),
(-xHoleOffset, 0),
(0, -yHoleOffset),
Expand Down
Binary file added examples/images/Classic_OCC_Bottle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/images/Numpy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/images/Parametric_Enclosure.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/images/Remote_Enclosure.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed examples/images/parametric_enclosure.png
Binary file not shown.

0 comments on commit 2e8e9db

Please sign in to comment.