@@ -262,7 +262,7 @@ needs a complex profile
262
262
(0.5, 1.0),
263
263
(0, 1.0)
264
264
]
265
- r = s.lineTo(3.0, 0).lineTo(3.0, 1.0).spline(sPnts,includeCurrent=True).close()
265
+ r = s.lineTo(3.0, 0).lineTo(3.0, 1.0).spline(sPnts, includeCurrent=True).close()
266
266
result = r.extrude(0.5)
267
267
268
268
.. topic :: Api References
@@ -285,9 +285,9 @@ introduce horizontal and vertical lines, which make for slightly easier coding.
285
285
286
286
.. cadquery ::
287
287
288
- r = cq.Workplane("front").hLine(1.0) # 1.0 is the distance, not coordinate
289
- r = r.vLine(0.5).hLine(-0.25).vLine(-0.25).hLineTo(0.0) # hLineTo allows using xCoordinate not distance
290
- result =r.mirrorY().extrude(0.25 ) # mirror the geometry and extrude
288
+ r = cq.Workplane("front").hLine(1.0) # 1.0 is the distance, not coordinate
289
+ r = r.vLine(0.5).hLine(-0.25).vLine(-0.25).hLineTo(0.0) # hLineTo allows using xCoordinate not distance
290
+ result = r.mirrorY().extrude(0.25) # mirror the geometry and extrude
291
291
292
292
.. topic :: Api References
293
293
@@ -308,34 +308,34 @@ Mirroring 3D Objects
308
308
.. cadquery ::
309
309
310
310
result0 = (cadquery.Workplane("XY")
311
- .moveTo(10,0)
312
- .lineTo(5,0)
313
- .threePointArc((3.9393,0.4393),(3.5,1.5))
314
- .threePointArc((3.0607,2.5607),(2,3))
315
- .lineTo(1.5,3)
316
- .threePointArc((0.4393,3.4393),(0,4.5))
317
- .lineTo(0,13.5)
318
- .threePointArc((0.4393,14.5607),(1.5,15))
319
- .lineTo(28,15)
320
- .lineTo(28,13.5)
321
- .lineTo(24,13.5)
322
- .lineTo(24,11.5)
323
- .lineTo(27,11.5)
324
- .lineTo(27,10)
325
- .lineTo(22,10)
326
- .lineTo(22,13.2)
327
- .lineTo(14.5,13.2)
328
- .lineTo(14.5,10)
329
- .lineTo(12.5,10 )
330
- .lineTo(12.5,13.2)
331
- .lineTo(5.5,13.2)
332
- .lineTo(5.5,2)
333
- .threePointArc((5.793,1.293),(6.5,1))
334
- .lineTo(10,1)
311
+ .moveTo(10, 0)
312
+ .lineTo(5, 0)
313
+ .threePointArc((3.9393, 0.4393), (3.5, 1.5))
314
+ .threePointArc((3.0607, 2.5607), (2, 3))
315
+ .lineTo(1.5, 3)
316
+ .threePointArc((0.4393, 3.4393), (0, 4.5))
317
+ .lineTo(0, 13.5)
318
+ .threePointArc((0.4393, 14.5607), (1.5, 15))
319
+ .lineTo(28, 15)
320
+ .lineTo(28, 13.5)
321
+ .lineTo(24, 13.5)
322
+ .lineTo(24, 11.5)
323
+ .lineTo(27, 11.5)
324
+ .lineTo(27, 10)
325
+ .lineTo(22, 10)
326
+ .lineTo(22, 13.2)
327
+ .lineTo(14.5, 13.2)
328
+ .lineTo(14.5, 10)
329
+ .lineTo(12.5, 10 )
330
+ .lineTo(12.5, 13.2)
331
+ .lineTo(5.5, 13.2)
332
+ .lineTo(5.5, 2)
333
+ .threePointArc((5.793, 1.293), (6.5, 1))
334
+ .lineTo(10, 1)
335
335
.close())
336
336
result = result0.extrude(100)
337
337
338
- result = result.rotate((0, 0, 0),(1, 0, 0), 90)
338
+ result = result.rotate((0, 0, 0), (1, 0, 0), 90)
339
339
340
340
result = result.translate(result.val().BoundingBox().center.multiply(-1))
341
341
@@ -465,9 +465,9 @@ This example uses an offset workplane to make a compound object, which is perfec
465
465
466
466
.. cadquery ::
467
467
468
- result = cq.Workplane("front").box(3, 2, 0.5) # make a basic prism
469
- result = result.faces("<X").workplane(offset=0.75) # workplane is offset from the object surface
470
- result = result.circle(1.0).extrude(0.5) # disc
468
+ result = cq.Workplane("front").box(3, 2, 0.5) # make a basic prism
469
+ result = result.faces("<X").workplane(offset=0.75) # workplane is offset from the object surface
470
+ result = result.circle(1.0).extrude(0.5) # disc
471
471
472
472
.. topic :: Api References
473
473
@@ -513,7 +513,7 @@ You can create a rotated work plane by specifying angles of rotation relative to
513
513
514
514
result = (cq.Workplane("front").box(4.0, 4.0, 0.25).faces(">Z").workplane()
515
515
.transformed(offset=cq.Vector(0, -1.5, 1.0),rotate=cq.Vector(60, 0, 0))
516
- .rect(1.5,1.5,forConstruction=True).vertices().hole(0.25))
516
+ .rect(1.5, 1.5, forConstruction=True).vertices().hole(0.25))
517
517
518
518
.. topic :: Api References
519
519
@@ -536,7 +536,7 @@ In the example below, a rectangle is drawn, and its vertices are used to locate
536
536
.. cadquery ::
537
537
538
538
result = (cq.Workplane("front").box(2, 2, 0.5).faces(">Z").workplane()
539
- .rect(1.5, 1.5, forConstruction=True).vertices().hole(0.125 ))
539
+ .rect(1.5, 1.5, forConstruction=True).vertices().hole(0.125))
540
540
541
541
.. topic :: Api References
542
542
@@ -724,7 +724,7 @@ Here we fillet all of the edges of a simple plate.
724
724
725
725
.. cadquery ::
726
726
727
- result = cq.Workplane("XY" ).box(3, 3, 0.5).edges("|Z").fillet(0.125)
727
+ result = cq.Workplane("XY").box(3, 3, 0.5).edges("|Z").fillet(0.125)
728
728
729
729
.. topic :: Api References
730
730
@@ -791,11 +791,11 @@ with just a few lines of code.
791
791
792
792
.. cadquery ::
793
793
794
- (length,height,bearing_diam, thickness,padding) = ( 30.0, 40.0, 22.0, 10.0, 8.0)
794
+ (length, height, bearing_diam, thickness, padding) = (30.0, 40.0, 22.0, 10.0, 8.0)
795
795
796
- result = (cq.Workplane("XY").box(length,height,thickness).faces(">Z").workplane().hole(bearing_diam)
796
+ result = (cq.Workplane("XY").box(length, height, thickness).faces(">Z").workplane().hole(bearing_diam)
797
797
.faces(">Z").workplane()
798
- .rect(length-padding,height-padding,forConstruction=True)
798
+ .rect(length-padding, height-padding, forConstruction=True)
799
799
.vertices().cboreHole(2.4, 4.4, 2.1))
800
800
801
801
@@ -806,9 +806,9 @@ You can split an object using a workplane, and retain either or both halves
806
806
807
807
.. cadquery ::
808
808
809
- c = cq.Workplane("XY").box(1,1, 1).faces(">Z").workplane().circle(0.25).cutThruAll()
809
+ c = cq.Workplane("XY").box(1, 1, 1).faces(">Z").workplane().circle(0.25).cutThruAll()
810
810
811
- #now cut it in half sideways
811
+ # now cut it in half sideways
812
812
result = c.faces(">Y").workplane(-0.5).split(keepTop=True)
813
813
814
814
.. topic :: Api References
@@ -837,18 +837,18 @@ ones at 13 lines, but that's very short compared to the pythonOCC version, which
837
837
838
838
.. cadquery ::
839
839
840
- (L,w, t) = (20.0, 6.0, 3.0)
840
+ (L, w, t) = (20.0, 6.0, 3.0)
841
841
s = cq.Workplane("XY")
842
842
843
843
# Draw half the profile of the bottle and extrude it
844
844
p = (s.center(-L/2.0, 0).vLine(w/2.0)
845
- .threePointArc((L/2.0, w/2.0 + t),(L, w/2.0)).vLine(-w/2.0)
846
- .mirrorX().extrude(30.0,True))
845
+ .threePointArc((L/2.0, w/2.0 + t), (L, w/2.0)).vLine(-w/2.0)
846
+ .mirrorX().extrude(30.0, True))
847
847
848
- #make the neck
849
- p = p.faces(">Z").workplane(centerOption="CenterOfMass").circle(3.0).extrude(2.0,True)
848
+ # Make the neck
849
+ p = p.faces(">Z").workplane(centerOption="CenterOfMass").circle(3.0).extrude(2.0, True)
850
850
851
- #make a shell
851
+ # Make a shell
852
852
result = p.faces(">Z").shell(0.3)
853
853
854
854
.. topic :: Api References
@@ -871,80 +871,80 @@ A Parametric Enclosure
871
871
.. cadquery ::
872
872
:height: 400px
873
873
874
- #parameter definitions
875
- p_outerWidth = 100.0 #Outer width of box enclosure
876
- p_outerLength = 150.0 #Outer length of box enclosure
877
- p_outerHeight = 50.0 #Outer height of box enclosure
874
+ # parameter definitions
875
+ p_outerWidth = 100.0 # Outer width of box enclosure
876
+ p_outerLength = 150.0 # Outer length of box enclosure
877
+ p_outerHeight = 50.0 # Outer height of box enclosure
878
878
879
- p_thickness = 3.0 #Thickness of the box walls
880
- p_sideRadius = 10.0 #Radius for the curves around the sides of the box
881
- p_topAndBottomRadius = 2.0 #Radius for the curves on the top and bottom edges of the box
879
+ p_thickness = 3.0 # Thickness of the box walls
880
+ p_sideRadius = 10.0 # Radius for the curves around the sides of the box
881
+ p_topAndBottomRadius = 2.0 # Radius for the curves on the top and bottom edges of the box
882
882
883
- p_screwpostInset = 12.0 #How far in from the edges the screw posts should be place.
884
- p_screwpostID = 4.0 #Inner Diameter of the screw post holes, should be roughly screw diameter not including threads
885
- p_screwpostOD = 10.0 #Outer Diameter of the screw posts.\n Determines overall thickness of the posts
883
+ p_screwpostInset = 12.0 # How far in from the edges the screw posts should be place.
884
+ p_screwpostID = 4.0 # Inner Diameter of the screw post holes, should be roughly screw diameter not including threads
885
+ p_screwpostOD = 10.0 # Outer Diameter of the screw posts.\n Determines overall thickness of the posts
886
886
887
- p_boreDiameter = 8.0 #Diameter of the counterbore hole, if any
888
- p_boreDepth = 1.0 #Depth of the counterbore hole, if
889
- p_countersinkDiameter = 0.0 #Outer diameter of countersink. Should roughly match the outer diameter of the screw head
890
- p_countersinkAngle = 90.0 #Countersink angle (complete angle between opposite sides, not from center to one side)
891
- p_flipLid = True #Whether to place the lid with the top facing down or not.
892
- p_lipHeight = 1.0 #Height of lip on the underside of the lid.\n Sits inside the box body for a snug fit.
887
+ p_boreDiameter = 8.0 # Diameter of the counterbore hole, if any
888
+ p_boreDepth = 1.0 # Depth of the counterbore hole, if
889
+ p_countersinkDiameter = 0.0 # Outer diameter of countersink. Should roughly match the outer diameter of the screw head
890
+ p_countersinkAngle = 90.0 # Countersink angle (complete angle between opposite sides, not from center to one side)
891
+ p_flipLid = True # Whether to place the lid with the top facing down or not.
892
+ p_lipHeight = 1.0 # Height of lip on the underside of the lid.\n Sits inside the box body for a snug fit.
893
893
894
- #outer shell
895
- oshell = cq.Workplane("XY").rect(p_outerWidth,p_outerLength).extrude(p_outerHeight + p_lipHeight)
894
+ # outer shell
895
+ oshell = cq.Workplane("XY").rect(p_outerWidth, p_outerLength).extrude(p_outerHeight + p_lipHeight)
896
896
897
- #weird geometry happens if we make the fillets in the wrong order
897
+ # weird geometry happens if we make the fillets in the wrong order
898
898
if p_sideRadius > p_topAndBottomRadius:
899
899
oshell = oshell.edges("|Z").fillet(p_sideRadius)
900
900
oshell = oshell.edges("#Z").fillet(p_topAndBottomRadius)
901
901
else:
902
902
oshell = oshell.edges("#Z").fillet(p_topAndBottomRadius)
903
903
oshell = oshell.edges("|Z").fillet(p_sideRadius)
904
904
905
- #inner shell
906
- ishell = (oshell.faces("<Z").workplane(p_thickness,True)
907
- .rect((p_outerWidth - 2.0* p_thickness),(p_outerLength - 2.0*p_thickness))
908
- .extrude((p_outerHeight - 2.0*p_thickness),False) #set combine false to produce just the new boss
905
+ # inner shell
906
+ ishell = (oshell.faces("<Z").workplane(p_thickness, True)
907
+ .rect((p_outerWidth - 2.0*p_thickness), (p_outerLength - 2.0*p_thickness))
908
+ .extrude((p_outerHeight - 2.0*p_thickness), False) # set combine false to produce just the new boss
909
909
)
910
910
ishell = ishell.edges("|Z").fillet(p_sideRadius - p_thickness)
911
911
912
- #make the box outer box
912
+ # make the box outer box
913
913
box = oshell.cut(ishell)
914
914
915
- #make the screw posts
915
+ # make the screw posts
916
916
POSTWIDTH = (p_outerWidth - 2.0*p_screwpostInset)
917
- POSTLENGTH = (p_outerLength - 2.0*p_screwpostInset)
917
+ POSTLENGTH = (p_outerLength - 2.0*p_screwpostInset)
918
918
919
919
box = (box.faces(">Z").workplane(-p_thickness)
920
- .rect(POSTWIDTH,POSTLENGTH,forConstruction=True)
920
+ .rect(POSTWIDTH, POSTLENGTH, forConstruction=True)
921
921
.vertices().circle(p_screwpostOD/2.0).circle(p_screwpostID/2.0)
922
- .extrude((-1.0)*(p_outerHeight + p_lipHeight -p_thickness ),True))
922
+ .extrude((-1.0)*(p_outerHeight + p_lipHeight - p_thickness ),True))
923
923
924
- #split lid into top and bottom parts
925
- (lid,bottom) = box.faces(">Z").workplane(-p_thickness -p_lipHeight ).split(keepTop=True,keepBottom=True).all() #splits into two solids
924
+ # split lid into top and bottom parts
925
+ (lid, bottom) = box.faces(">Z").workplane(-p_thickness - p_lipHeight ).split(keepTop=True, keepBottom=True).all() # splits into two solids
926
926
927
- #translate the lid, and subtract the bottom from it to produce the lid inset
928
- lowerLid = lid.translate((0,0, -p_lipHeight))
929
- cutlip = lowerLid.cut(bottom).translate((p_outerWidth + p_thickness ,0, p_thickness - p_outerHeight + p_lipHeight))
927
+ # translate the lid, and subtract the bottom from it to produce the lid inset
928
+ lowerLid = lid.translate((0, 0, -p_lipHeight))
929
+ cutlip = lowerLid.cut(bottom).translate((p_outerWidth + p_thickness, 0, p_thickness - p_outerHeight + p_lipHeight))
930
930
931
- #compute centers for counterbore/countersink or counterbore
932
- topOfLidCenters = cutlip.faces(">Z").workplane().rect(POSTWIDTH,POSTLENGTH,forConstruction=True).vertices()
931
+ # compute centers for counterbore/countersink or counterbore
932
+ topOfLidCenters = cutlip.faces(">Z").workplane().rect(POSTWIDTH, POSTLENGTH, forConstruction=True).vertices()
933
933
934
- #add holes of the desired type
934
+ # add holes of the desired type
935
935
if p_boreDiameter > 0 and p_boreDepth > 0:
936
- topOfLid = topOfLidCenters.cboreHole(p_screwpostID,p_boreDiameter,p_boreDepth,( 2.0) *p_thickness)
936
+ topOfLid = topOfLidCenters.cboreHole(p_screwpostID, p_boreDiameter, p_boreDepth, 2.0*p_thickness)
937
937
elif p_countersinkDiameter > 0 and p_countersinkAngle > 0:
938
- topOfLid = topOfLidCenters.cskHole(p_screwpostID,p_countersinkDiameter,p_countersinkAngle,( 2.0) *p_thickness)
938
+ topOfLid = topOfLidCenters.cskHole(p_screwpostID, p_countersinkDiameter, p_countersinkAngle, 2.0*p_thickness)
939
939
else:
940
- topOfLid= topOfLidCenters.hole(p_screwpostID,( 2.0) *p_thickness)
940
+ topOfLid = topOfLidCenters.hole(p_screwpostID, 2.0*p_thickness)
941
941
942
- #flip lid upside down if desired
942
+ # flip lid upside down if desired
943
943
if p_flipLid:
944
- topOfLid = topOfLid.rotateAboutCenter((1,0, 0),180)
944
+ topOfLid = topOfLid.rotateAboutCenter((1, 0, 0), 180)
945
945
946
- #return the combined result
947
- result =topOfLid.union(bottom)
946
+ # return the combined result
947
+ result = topOfLid.union(bottom)
948
948
949
949
950
950
.. topic :: Api References
0 commit comments