From a661b0ec4b724aa453675ef7710adff16a460be7 Mon Sep 17 00:00:00 2001 From: Jeremy Mack Wright Date: Wed, 20 Sep 2017 17:12:30 -0400 Subject: [PATCH] Finished converting the rest of the examples and then started fixing the ones that are broken. --- Examples/Ex015_Rotated_Workplanes.py | 2 +- Examples/Ex016_Using_Construction_Geometry.py | 26 +++++++++++----- .../Ex017_Shelling_to_Create_Thin_Features.py | 19 +++++++----- Examples/Ex018_Making_Lofts.py | 27 +++++++++++------ Examples/Ex019_Counter_Sunk_Holes.py | 24 ++++++++++----- .../Ex020_Rounding_Corners_with_Fillets.py | 18 ++++++----- Examples/Ex021_Splitting_an_Object.py | 30 +++++++++++++------ Examples/Ex022_Classic_OCC_Bottle.py | 10 +++---- Examples/Ex023_Parametric_Enclosure.py | 10 +++---- Examples/Ex025_Revolution.py | 10 +++---- Examples/Ex026_Lego_Brick.py | 8 ++--- Examples/Ex027_Remote_Enclosure.py | 18 +++++------ Examples/Ex028_Numpy.py | 11 +++---- Examples/Ex029_Braille.py | 3 +- ...arious_Holes_for_Connector_Installation.py | 8 ++--- Examples/Ex031_Sweep.py | 30 +++++++++---------- Examples/Ex032_3D_Printer_Extruder_Support.py | 3 +- ...Chamfer_With_Logical_Selector_Operators.py | 7 ++--- 18 files changed, 145 insertions(+), 119 deletions(-) diff --git a/Examples/Ex015_Rotated_Workplanes.py b/Examples/Ex015_Rotated_Workplanes.py index 598712b..a964e01 100644 --- a/Examples/Ex015_Rotated_Workplanes.py +++ b/Examples/Ex015_Rotated_Workplanes.py @@ -8,7 +8,7 @@ import cadquery as cq # 3. Selects the top-most Z face of the box. # 4. Creates a new workplane and then moves and rotates it with the # transformed function. -# 5. Creates a for-construction rectangle that only exists to use for plancing +# 5. Creates a for-construction rectangle that only exists to use for placing # other geometry. # 6. Selects the vertices of the for-construction rectangle. # 7. Places holes at the center of each selected vertex. diff --git a/Examples/Ex016_Using_Construction_Geometry.py b/Examples/Ex016_Using_Construction_Geometry.py index aee8058..48a4f87 100644 --- a/Examples/Ex016_Using_Construction_Geometry.py +++ b/Examples/Ex016_Using_Construction_Geometry.py @@ -1,11 +1,21 @@ -# This example is meant to be used from within the CadQuery module of FreeCAD. -import cadquery -from Helpers import show +import cadquery as cq -# Create a block with holes in each corner of a rectangle on that workplane -result = cadquery.Workplane("front").box(2, 2, 0.5)\ +# Create a block with holes in each corner of a rectangle on that workplane. +# 1. Establishes a workplane that an object can be built on. +# 1a. Uses the named plane orientation "front" to define the workplane, meaning +# that the positive Z direction is "up", and the negative Z direction +# is "down". +# 2. Creates a plain box to base future geometry on with the box() function. +# 3. Selects the top-most Z face of the box. +# 4. Creates a new workplane to build new geometry on. +# 5. Creates a for-construction rectangle that only exists to use for placing +# other geometry. +# 6. Selects the vertices of the for-construction rectangle. +# 7. Places holes at the center of each selected vertex. +result = cq.Workplane("front").box(2, 2, 0.5)\ .faces(">Z").workplane() \ - .rect(1.5, 1.5, forConstruction=True).vertices().hole(0.125) + .rect(1.5, 1.5, forConstruction=True).vertices() \ + .hole(0.125) -# Render the solid -show(result) +# Displays the result of this script +show_object(result) diff --git a/Examples/Ex017_Shelling_to_Create_Thin_Features.py b/Examples/Ex017_Shelling_to_Create_Thin_Features.py index b984306..91c6823 100644 --- a/Examples/Ex017_Shelling_to_Create_Thin_Features.py +++ b/Examples/Ex017_Shelling_to_Create_Thin_Features.py @@ -1,9 +1,14 @@ -# This example is meant to be used from within the CadQuery module of FreeCAD. -import cadquery -from Helpers import show +import cadquery as cq -# Create a hollow box that's open on both ends with a thin wall -result = cadquery.Workplane("front").box(2, 2, 2).faces("+Z").shell(0.05) +# Create a hollow box that's open on both ends with a thin wall. +# 1. Establishes a workplane that an object can be built on. +# 1a. Uses the named plane orientation "front" to define the workplane, meaning +# that the positive Z direction is "up", and the negative Z direction +# is "down". +# 2. Creates a plain box to base future geometry on with the box() function. +# 3. Selects faces with normal in +z direction. +# 4. Create a shell by cutting out the top-most Z face. +result = cq.Workplane("front").box(2, 2, 2).faces("+Z").shell(0.05) -# Render the solid -show(result) +# Displays the result of this script +show_object(result) diff --git a/Examples/Ex018_Making_Lofts.py b/Examples/Ex018_Making_Lofts.py index 6478f4a..6e9ad1e 100644 --- a/Examples/Ex018_Making_Lofts.py +++ b/Examples/Ex018_Making_Lofts.py @@ -1,11 +1,20 @@ -# This example is meant to be used from within the CadQuery module of FreeCAD. -import cadquery -from Helpers import show +import cadquery as cq -# Create a lofted section between a rectangle and a circular section -result = cadquery.Workplane("front").box(4.0, 4.0, 0.25).faces(">Z") \ - .circle(1.5).workplane(offset=3.0) \ - .rect(0.75, 0.5).loft(combine=True) +# Create a lofted section between a rectangle and a circular section. +# 1. Establishes a workplane that an object can be built on. +# 1a. Uses the named plane orientation "front" to define the workplane, meaning +# that the positive Z direction is "up", and the negative Z direction +# is "down". +# 2. Creates a plain box to base future geometry on with the box() function. +# 3. Selects the top-most Z face of the box. +# 4. Draws a 2D circle at the center of the the top-most face of the box. +# 5. Creates a workplane 3 mm above the face the circle was drawn on. +# 6. Draws a 2D circle on the new, offset workplane. +# 7. Creates a loft between the circle and the rectangle. +result = cq.Workplane("front").box(4.0, 4.0, 0.25).faces(">Z") \ + .circle(1.5).workplane(offset=3.0) \ + .rect(0.75, 0.5) \ + .loft(combine=True) -# Render the solid -show(result) +# Displays the result of this script +show_object(result) diff --git a/Examples/Ex019_Counter_Sunk_Holes.py b/Examples/Ex019_Counter_Sunk_Holes.py index be70587..e75039a 100644 --- a/Examples/Ex019_Counter_Sunk_Holes.py +++ b/Examples/Ex019_Counter_Sunk_Holes.py @@ -1,11 +1,19 @@ -# This example is meant to be used from within the CadQuery module of FreeCAD. -import cadquery -from Helpers import show +import cadquery as cq -# Create a plate with 4 counter-sunk holes in it -result = cadquery.Workplane(cadquery.Plane.XY()).box(4, 2, 0.5).faces(">Z") \ - .workplane().rect(3.5, 1.5, forConstruction=True)\ +# Create a plate with 4 counter-sunk holes in it. +# 1. Establishes a workplane using an XY object instead of a named plane. +# 2. Creates a plain box to base future geometry on with the box() function. +# 3. Selects the top-most face of the box and established a workplane on that. +# 4. Draws a for-construction rectangle on the workplane which only exists for +# placing other geometry. +# 5. Selects the corner vertices of the rectangle and places a counter-sink +# hole, using each vertex as the center of a hole using the cskHole() +# function. +# 5a. When the depth of the counter-sink hole is set to None, the hole will be +# cut through. +result = cq.Workplane(cq.Plane.XY()).box(4, 2, 0.5).faces(">Z") \ + .workplane().rect(3.5, 1.5, forConstruction=True) \ .vertices().cskHole(0.125, 0.25, 82.0, depth=None) -# Render the solid -show(result) +# Displays the result of this script +show_object(result) diff --git a/Examples/Ex020_Rounding_Corners_with_Fillets.py b/Examples/Ex020_Rounding_Corners_with_Fillets.py index a2f7876..a736970 100644 --- a/Examples/Ex020_Rounding_Corners_with_Fillets.py +++ b/Examples/Ex020_Rounding_Corners_with_Fillets.py @@ -1,9 +1,13 @@ -# This example is meant to be used from within the CadQuery module of FreeCAD. -import cadquery -from Helpers import show +import cadquery as cq -# Create a plate with 4 rounded corners in the Z-axis -result = cadquery.Workplane("XY").box(3, 3, 0.5).edges("|Z").fillet(0.125) +# Create a plate with 4 rounded corners in the Z-axis. +# 1. Establishes a workplane that an object can be built on. +# 1a. Uses the X and Y origins to define the workplane, meaning that the +# positive Z direction is "up", and the negative Z direction is "down". +# 2. Creates a plain box to base future geometry on with the box() function. +# 3. Selects all edges that are parallel to the Z axis. +# 4. Creates fillets on each of the selected edges with the specified radius. +result = cq.Workplane("XY").box(3, 3, 0.5).edges("|Z").fillet(0.125) -# Render the solid -show(result) +# Displays the result of this script +show_object(result) diff --git a/Examples/Ex021_Splitting_an_Object.py b/Examples/Ex021_Splitting_an_Object.py index 6cda407..e903a13 100644 --- a/Examples/Ex021_Splitting_an_Object.py +++ b/Examples/Ex021_Splitting_an_Object.py @@ -1,13 +1,25 @@ -# This example is meant to be used from within the CadQuery module of FreeCAD. -import cadquery -from Helpers import show +import cadquery as cq -# Create a simple block with a hole through it that we can split -c = cadquery.Workplane("XY").box(1, 1, 1).faces(">Z").workplane() \ - .circle(0.25).cutThruAll() +# Create a simple block with a hole through it that we can split. +# 1. Establishes a workplane that an object can be built on. +# 1a. Uses the X and Y origins to define the workplane, meaning that the +# positive Z direction is "up", and the negative Z direction is "down". +# 2. Creates a plain box to base future geometry on with the box() function. +# 3. Selects the top-most face of the box and establishes a workplane on it +# that new geometry can be built on. +# 4. Draws a 2D circle on the new workplane and then uses it to cut a hole +# all the way through the box. +c = cq.Workplane("XY").box(1, 1, 1).faces(">Z").workplane() \ + .circle(0.25).cutThruAll() -# Cut the block in half sideways +# 5. Selects the face furthest away from the origin in the +Y axis direction. +# 6. Creates an offset workplane that is set in the center of the object. +# 6a. One possible improvement to this script would be to make the dimensions +# of the box variables, and then divide the Y-axis dimension by 2.0 and +# use that to create the offset workplane. +# 7. Uses the embedded workplane to split the object, keeping only the "top" +# portion. result = c.faces(">Y").workplane(-0.5).split(keepTop=True) -# Render the solid -show(result) +# Displays the result of this script +show_object(result) diff --git a/Examples/Ex022_Classic_OCC_Bottle.py b/Examples/Ex022_Classic_OCC_Bottle.py index 0721335..5e01873 100644 --- a/Examples/Ex022_Classic_OCC_Bottle.py +++ b/Examples/Ex022_Classic_OCC_Bottle.py @@ -1,10 +1,8 @@ -# This example is meant to be used from within the CadQuery module of FreeCAD. -import cadquery -from Helpers import show +import cadquery as cq # Set up the length, width, and thickness (L, w, t) = (20.0, 6.0, 3.0) -s = cadquery.Workplane("XY") +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) \ @@ -17,5 +15,5 @@ p.faces(">Z").workplane().circle(3.0).extrude(2.0, True) # Make a shell result = p.faces(">Z").shell(0.3) -# Render the solid -show(result) +# Displays the result of this script +show_object(result) diff --git a/Examples/Ex023_Parametric_Enclosure.py b/Examples/Ex023_Parametric_Enclosure.py index 82ebee4..3d12863 100644 --- a/Examples/Ex023_Parametric_Enclosure.py +++ b/Examples/Ex023_Parametric_Enclosure.py @@ -1,6 +1,4 @@ -# This example is meant to be used from within the CadQuery module of FreeCAD. -import cadquery -from Helpers import show +import cadquery as cq # Parameter definitions p_outerWidth = 100.0 # Outer width of box enclosure @@ -22,7 +20,7 @@ p_countersinkAngle = 90.0 # Countersink angle (complete angle between opposite 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 = cadquery.Workplane("XY").rect(p_outerWidth, p_outerLength) \ +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 @@ -75,5 +73,5 @@ else: # Return the combined result result = topOfLid.combineSolids(bottom) -# Render the solid -show(result) +# Displays the result of this script +show_object(result) diff --git a/Examples/Ex025_Revolution.py b/Examples/Ex025_Revolution.py index da0bb39..c5f3107 100644 --- a/Examples/Ex025_Revolution.py +++ b/Examples/Ex025_Revolution.py @@ -1,6 +1,4 @@ -# This example is meant to be used from within the CadQuery module of FreeCAD. -import cadquery -from Helpers import show +import cadquery as cq # The dimensions of the model. These can be modified rather than changing the # shape's code directly. @@ -10,7 +8,7 @@ angle_degrees = 360.0 # Revolve a cylinder from a rectangle # Switch comments around in this section to try the revolve operation with different parameters -result = cadquery.Workplane("XY").rect(rectangle_width, rectangle_length, False).revolve() +result = cq.Workplane("XY").rect(rectangle_width, rectangle_length, False).revolve() #result = cadquery.Workplane("XY").rect(rectangle_width, rectangle_length, False).revolve(angle_degrees) #result = cadquery.Workplane("XY").rect(rectangle_width, rectangle_length).revolve(angle_degrees,(-5,-5)) #result = cadquery.Workplane("XY").rect(rectangle_width, rectangle_length).revolve(angle_degrees,(-5, -5),(-5, 5)) @@ -19,5 +17,5 @@ result = cadquery.Workplane("XY").rect(rectangle_width, rectangle_length, False) # Revolve a donut with square walls #result = cadquery.Workplane("XY").rect(rectangle_width, rectangle_length, True).revolve(angle_degrees, (20, 0), (20, 10)) -# Render the solid -show(result) +# Displays the result of this script +show_object(result) diff --git a/Examples/Ex026_Lego_Brick.py b/Examples/Ex026_Lego_Brick.py index e52dde2..6a6381f 100644 --- a/Examples/Ex026_Lego_Brick.py +++ b/Examples/Ex026_Lego_Brick.py @@ -1,7 +1,5 @@ -# 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 -from Helpers import show +import cadquery as cq ##### # Inputs @@ -28,7 +26,7 @@ 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) +s = cq.Workplane("XY").box(total_length, total_width, height) # shell inwards not outwards s = s.faces("Z") .fillet(yFilletRadius) # shell the solid from the bottom face, with a .060" wall thickness - .faces("-Z") + .faces("Z") .workplane() .pushPoints([(0, 0), (-xHoleOffset, 0), @@ -84,6 +80,6 @@ cover = (base(coverThickness) # Conditionally render the parts if showTop: - show(top) + show_object(top) if showCover: - show(cover) + show_object(cover) diff --git a/Examples/Ex028_Numpy.py b/Examples/Ex028_Numpy.py index 0aa12a0..df7c8b9 100644 --- a/Examples/Ex028_Numpy.py +++ b/Examples/Ex028_Numpy.py @@ -1,7 +1,5 @@ -# This example is meant to be used from within the CadQuery module of FreeCAD. import numpy as np -import cadquery -from Helpers import show +import cadquery as cq # Square side and offset in x and y. side = 10 @@ -11,16 +9,15 @@ offset = 5 # The polyline is defined as numpy.array so that operations like translation # of all points are simplified. pts = np.array([ - (0, 0), (side, 0), (side, side), (0, side), (0, 0), ]) + [offset, offset] -result = cadquery.Workplane('XY') \ - .polyline(pts).extrude(2) \ +result = cq.Workplane('XY') \ + .polyline(pts).close().extrude(2) \ .faces('+Z').workplane().circle(side / 2).extrude(1) # Render the solid -show(result) +show_object(result) diff --git a/Examples/Ex029_Braille.py b/Examples/Ex029_Braille.py index c366f4a..85918cf 100644 --- a/Examples/Ex029_Braille.py +++ b/Examples/Ex029_Braille.py @@ -5,7 +5,6 @@ from __future__ import unicode_literals, division from collections import namedtuple import cadquery as cq -from Helpers import show # text_lines is a list of text lines. # FreeCAD in braille (converted with braille-converter: @@ -180,4 +179,4 @@ _cell_geometry = BrailleCellGeometry( if base_thickness < get_cylinder_radius(_cell_geometry): raise ValueError('Base thickness should be at least {}'.format(dot_height)) -show(make_embossed_plate(text_lines, _cell_geometry)) +show_object(make_embossed_plate(text_lines, _cell_geometry)) diff --git a/Examples/Ex030_Panel_with_Various_Holes_for_Connector_Installation.py b/Examples/Ex030_Panel_with_Various_Holes_for_Connector_Installation.py index f3f08b4..f428e6b 100644 --- a/Examples/Ex030_Panel_with_Various_Holes_for_Connector_Installation.py +++ b/Examples/Ex030_Panel_with_Various_Holes_for_Connector_Installation.py @@ -1,6 +1,4 @@ -# This example is meant to be used from within the CadQuery module of FreeCAD. -import cadquery -from Helpers import show +import cadquery as cq # The dimensions of the model. These can be modified rather than changing the # object's code directly. @@ -9,7 +7,7 @@ height = 500 thickness = 2 # Create a plate with two polygons cut through it -result = cadquery.Workplane("front").box(width, height, thickness) +result = cq.Workplane("front").box(width, height, thickness) h_sep = 60 for idx in range(4): @@ -44,4 +42,4 @@ for idx in range(4): result = result.workplane(offset=1, centerOption='CenterOfBoundBox').center(-173,-30-idx*h_sep).moveTo(-2.9176,-5.3).threePointArc((-6.05,0),(-2.9176,5.3)).lineTo(2.9176,5.3).threePointArc((6.05,0),(2.9176,-5.3)).close().cutThruAll() # Render the solid -show(result) +show_object(result) diff --git a/Examples/Ex031_Sweep.py b/Examples/Ex031_Sweep.py index 16201b9..7c5ebdd 100644 --- a/Examples/Ex031_Sweep.py +++ b/Examples/Ex031_Sweep.py @@ -1,6 +1,4 @@ -# This example is meant to be used from within the CadQuery module for FreeCAD -import cadquery -from Helpers import show +import cadquery as cq # Points we will use to create spline and polyline paths to sweep over pts = [ @@ -10,33 +8,33 @@ pts = [ ] # Spline path generated from our list of points (tuples) -path = cadquery.Workplane("XZ").spline(pts) +path = cq.Workplane("XZ").spline(pts) # Sweep a circle with a diameter of 1.0 units along the spline path we just created -defaultSweep = cadquery.Workplane("XY").circle(1.0).sweep(path) +defaultSweep = cq.Workplane("XY").circle(1.0).sweep(path) # Sweep defaults to making a solid and not generating a Frenet solid. Setting Frenet to True helps prevent creep in # the orientation of the profile as it is being swept -frenetShell = cadquery.Workplane("XY").circle(1.0).sweep(path, makeSolid=False, isFrenet=True) +frenetShell = cq.Workplane("XY").circle(1.0).sweep(path, makeSolid=False, isFrenet=True) # We can sweep shapes other than circles -defaultRect = cadquery.Workplane("XY").rect(1.0, 1.0).sweep(path) +defaultRect = cq.Workplane("XY").rect(1.0, 1.0).sweep(path) # Switch to a polyline path, but have it use the same points as the spline -path = cadquery.Workplane("XZ").polyline(pts) +path = cq.Workplane("XZ").polyline(pts) # Using a polyline path leads to the resulting solid having segments rather than a single swept outer face -plineSweep = cadquery.Workplane("XY").circle(1.0).sweep(path) +plineSweep = cq.Workplane("XY").circle(1.0).sweep(path) # Switch to an arc for the path -path = cadquery.Workplane("XZ").threePointArc((1.0, 1.5), (0.0, 1.0)) +path = cq.Workplane("XZ").threePointArc((1.0, 1.5), (0.0, 1.0)) # Use a smaller circle section so that the resulting solid looks a little nicer -arcSweep = cadquery.Workplane("XY").circle(0.5).sweep(path) +arcSweep = cq.Workplane("XY").circle(0.5).sweep(path) # Translate the resulting solids so that they do not overlap and display them left to right -show(defaultSweep) -show(frenetShell.translate((5, 0, 0))) -show(defaultRect.translate((10, 0, 0))) -show(plineSweep.translate((15, 0, 0))) -show(arcSweep.translate((20, 0, 0))) \ No newline at end of file +show_object(defaultSweep) +show_object(frenetShell.translate((5, 0, 0))) +show_object(defaultRect.translate((10, 0, 0))) +show_object(plineSweep.translate((15, 0, 0))) +show_object(arcSweep.translate((20, 0, 0))) \ No newline at end of file diff --git a/Examples/Ex032_3D_Printer_Extruder_Support.py b/Examples/Ex032_3D_Printer_Extruder_Support.py index 556a4d1..0b34f50 100644 --- a/Examples/Ex032_3D_Printer_Extruder_Support.py +++ b/Examples/Ex032_3D_Printer_Extruder_Support.py @@ -1,7 +1,6 @@ # 3d printer for mounting hotend to X-carriage inspired by the P3steel Toolson # edition - http://www.thingiverse.com/thing:1054909 import cadquery as cq -from Helpers import show def move_to_center(cqObject, shape): @@ -213,4 +212,4 @@ hole_sep = 0.5*face_right.Area()/main_plate_thickness res = make_aux_holes(res, hole_sep, 2) # show the result -show(res) \ No newline at end of file +show_object(res) \ No newline at end of file diff --git a/Examples/Ex033_Shelled_Cube_Inside_Chamfer_With_Logical_Selector_Operators.py b/Examples/Ex033_Shelled_Cube_Inside_Chamfer_With_Logical_Selector_Operators.py index 3137055..241615b 100644 --- a/Examples/Ex033_Shelled_Cube_Inside_Chamfer_With_Logical_Selector_Operators.py +++ b/Examples/Ex033_Shelled_Cube_Inside_Chamfer_With_Logical_Selector_Operators.py @@ -1,11 +1,10 @@ -# Example using advanced logical operators in string selectors -# to select only the inside edges on a shelled cube to chamfer. +# Example using advanced logical operators in string selectors to select only +# the inside edges on a shelled cube to chamfer. import cadquery as cq -from Helpers import show result = cq.Workplane("XY").box(2, 2, 2).\ faces(">Z").shell(-0.2).\ faces(">Z").edges("not(X or Y)").\ chamfer(0.125) -show(result) +show_object(result)