Skip to content

Commit 2e8e9db

Browse files
committed
Fixed examples except for extruder support
1 parent da69d51 commit 2e8e9db

File tree

10 files changed

+78
-73
lines changed

10 files changed

+78
-73
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ A place to share CadQuery scripts, modules, tutorials and projects
1616

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

19-
<img src="examples/images/parametric_enclosure.png" width="600"/>
19+
<img src="examples/images/Parametric_Enclosure.png" width="600"/>
2020

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

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

4646
* [Remote_Enclosure.py](examples/Remote_Enclosure.py) - An electronics enclosure created to be mounted on motorcycle handlebars
47+
48+
<img src="examples/images/Remote_Enclosure.png" width="600"/>
49+
4750
* [Classic_OCC_Bottle.py](examples/Classic_OCC_Bottle.py) - Standard OCCT bottle example, implemented using the CadQuery API
51+
52+
<img src="examples/images/Classic_OCC_Bottle.png" width="600"/>
53+
4854
* [Numpy.py](examples/Numpy.py) - Example of integrating Numpy with CadQuery
55+
56+
<img src="examples/images/Numpy.png" width="600"/>
57+
4958
* [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
5059

5160
### Tutorials

examples/Classic_OCC_Bottle.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import cadquery as cq
22

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

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

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

15-
# Make a shell
15+
# Make the bottle a shell
1616
result = p.faces(">Z").shell(0.3)
1717

1818
# Displays the result of this script

examples/Numpy.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# NOTE: This example may not run correctly in some revisions of FreeCAD 0.16
21
import numpy as np
32
import cadquery as cq
43

@@ -19,7 +18,7 @@
1918

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

2423
# Render the solid
2524
show_object(result)

examples/Parametric_Enclosure.py

Lines changed: 58 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,74 @@
1-
import cadquery as cq
2-
3-
# Parameter definitions
4-
p_outerWidth = 100.0 # Outer width of box enclosure
5-
p_outerLength = 150.0 # Outer length of box enclosure
6-
p_outerHeight = 50.0 # Outer height of box enclosure
7-
8-
p_thickness = 3.0 # Thickness of the box walls
9-
p_sideRadius = 10.0 # Radius for the curves around the sides of the bo
10-
p_topAndBottomRadius = 2.0 # Radius for the curves on the top and bottom edges
11-
12-
p_screwpostInset = 12.0 # How far in from the edges the screwposts should be
13-
p_screwpostID = 4.0 # Inner diameter of the screwpost holes, should be roughly screw diameter not including threads
14-
p_screwpostOD = 10.0 # Outer diameter of the screwposts. Determines overall thickness of the posts
15-
16-
p_boreDiameter = 8.0 # Diameter of the counterbore hole, if any
17-
p_boreDepth = 1.0 # Depth of the counterbore hole, if
18-
p_countersinkDiameter = 0.0 # Outer diameter of countersink. Should roughly match the outer diameter of the screw head
19-
p_countersinkAngle = 90.0 # Countersink angle (complete angle between opposite sides, not from center to one side)
20-
p_lipHeight = 1.0 # Height of lip on the underside of the lid. Sits inside the box body for a snug fit.
21-
22-
# Outer shell
23-
oshell = cq.Workplane("XY").rect(p_outerWidth, p_outerLength) \
24-
.extrude(p_outerHeight + p_lipHeight)
25-
26-
# Weird geometry happens if we make the fillets in the wrong order
1+
# parameter definitions
2+
p_outerWidth = 100.0 #Outer width of box enclosure
3+
p_outerLength = 150.0 #Outer length of box enclosure
4+
p_outerHeight = 50.0 #Outer height of box enclosure
5+
6+
p_thickness = 3.0 #Thickness of the box walls
7+
p_sideRadius = 10.0 #Radius for the curves around the sides of the box
8+
p_topAndBottomRadius = 2.0 #Radius for the curves on the top and bottom edges of the box
9+
10+
p_screwpostInset = 12.0 #How far in from the edges the screw posts should be place.
11+
p_screwpostID = 4.0 #Inner Diameter of the screw post holes, should be roughly screw diameter not including threads
12+
p_screwpostOD = 10.0 #Outer Diameter of the screw posts.\nDetermines overall thickness of the posts
13+
14+
p_boreDiameter = 8.0 #Diameter of the counterbore hole, if any
15+
p_boreDepth = 1.0 #Depth of the counterbore hole, if
16+
p_countersinkDiameter = 0.0 #Outer diameter of countersink. Should roughly match the outer diameter of the screw head
17+
p_countersinkAngle = 90.0 #Countersink angle (complete angle between opposite sides, not from center to one side)
18+
p_flipLid = True #Whether to place the lid with the top facing down or not.
19+
p_lipHeight = 1.0 #Height of lip on the underside of the lid.\nSits inside the box body for a snug fit.
20+
21+
# outer shell
22+
oshell = cq.Workplane("XY").rect(p_outerWidth,p_outerLength).extrude(p_outerHeight + p_lipHeight)
23+
24+
# weird geometry happens if we make the fillets in the wrong order
2725
if p_sideRadius > p_topAndBottomRadius:
28-
oshell.edges("|Z").fillet(p_sideRadius)
29-
oshell.edges("#Z").fillet(p_topAndBottomRadius)
26+
oshell = oshell.edges("|Z").fillet(p_sideRadius)
27+
oshell = oshell.edges("#Z").fillet(p_topAndBottomRadius)
3028
else:
31-
oshell.edges("#Z").fillet(p_topAndBottomRadius)
32-
oshell.edges("|Z").fillet(p_sideRadius)
29+
oshell = oshell.edges("#Z").fillet(p_topAndBottomRadius)
30+
oshell = oshell.edges("|Z").fillet(p_sideRadius)
3331

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

40-
# Make the box outer box
39+
# make the box outer box
4140
box = oshell.cut(ishell)
4241

43-
# Make the screwposts
44-
POSTWIDTH = (p_outerWidth - 2.0 * p_screwpostInset)
45-
POSTLENGTH = (p_outerLength - 2.0 * p_screwpostInset)
46-
47-
postCenters = box.faces(">Z").workplane(-p_thickness)\
48-
.rect(POSTWIDTH, POSTLENGTH, forConstruction=True)\
49-
.vertices()
42+
# make the screw posts
43+
POSTWIDTH = (p_outerWidth - 2.0*p_screwpostInset)
44+
POSTLENGTH = (p_outerLength -2.0*p_screwpostInset)
5045

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

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

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

62-
# Compute centers for counterbore/countersink or counterbore
63-
topOfLidCenters = cutlip.faces(">Z").workplane().rect(POSTWIDTH, POSTLENGTH, forConstruction=True).vertices()
58+
# compute centers for counterbore/countersink or counterbore
59+
topOfLidCenters = cutlip.faces(">Z").workplane().rect(POSTWIDTH,POSTLENGTH,forConstruction=True).vertices()
6460

65-
# Add holes of the desired type
61+
# add holes of the desired type
6662
if p_boreDiameter > 0 and p_boreDepth > 0:
67-
topOfLid = topOfLidCenters.cboreHole(p_screwpostID, p_boreDiameter, p_boreDepth, (2.0) * p_thickness)
63+
topOfLid = topOfLidCenters.cboreHole(p_screwpostID,p_boreDiameter,p_boreDepth,(2.0)*p_thickness)
6864
elif p_countersinkDiameter > 0 and p_countersinkAngle > 0:
69-
topOfLid = topOfLidCenters.cskHole(p_screwpostID, p_countersinkDiameter, p_countersinkAngle, (2.0) * p_thickness)
65+
topOfLid = topOfLidCenters.cskHole(p_screwpostID,p_countersinkDiameter,p_countersinkAngle,(2.0)*p_thickness)
7066
else:
71-
topOfLid= topOfLidCenters.hole(p_screwpostID, 2.0 * p_thickness)
67+
topOfLid= topOfLidCenters.hole(p_screwpostID,(2.0)*p_thickness)
7268

73-
# Return the combined result
74-
result = topOfLid.combineSolids(bottom)
69+
# flip lid upside down if desired
70+
if p_flipLid:
71+
topOfLid = topOfLid.rotateAboutCenter((1,0,0),180)
7572

76-
# Displays the result of this script
77-
show_object(result)
73+
# return the combined result
74+
result =topOfLid.union(bottom)

examples/Remote_Enclosure.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
width = 2.2 # Nominal x dimension of the part
88
height = 0.5 # Height from bottom top to the top of the top :P
99
length = 1.5 # Nominal y dimension of the part
10-
trapezoidFudge = 0.7 # ratio of trapezoid bases. set to 1.0 for cube
10+
trapezoidFudge = 1.5 # ratio of trapezoid bases. set to 1.0 for cube
1111
xHoleOffset = 0.500 # Holes are distributed symmetrically about each axis
1212
yHoleOffset = 0.500
1313
zFilletRadius = 0.50 # Fillet radius of corners perp. to Z axis.
@@ -54,7 +54,7 @@ def base(h):
5454
.shell(-wallThickness)
5555
# cut five button holes into the top face in a cross pattern.
5656
.faces(">Z")
57-
.workplane()
57+
.workplane(centerOption="CenterOfMass")
5858
.pushPoints([(0, 0),
5959
(-xHoleOffset, 0),
6060
(0, -yHoleOffset),
31.8 KB
Loading

examples/images/Numpy.png

20.7 KB
Loading
39.4 KB
Loading
115 KB
Loading
-23 KB
Binary file not shown.

0 commit comments

Comments
 (0)