diff --git a/cadquery/CQ.py b/cadquery/CQ.py index 3723f67..ec0b583 100644 --- a/cadquery/CQ.py +++ b/cadquery/CQ.py @@ -256,6 +256,15 @@ class CQ(object): """ return self.objects[0] + def toFreecad(self): + """ + Directly returns the wrapped FreeCAD object to cut down on the amount of boiler plate code needed when + rendering a model in FreeCAD's 3D view. + :return: The wrapped FreeCAD object + :rtype A FreeCAD object or a SolidReference + """ + + return self.objects[0].wrapped def workplane(self,offset=0.0,invert=False): diff --git a/examples/FreeCAD/Ex001_Simple_Block.py b/examples/FreeCAD/Ex001_Simple_Block.py index c177ce1..8e1609c 100644 --- a/examples/FreeCAD/Ex001_Simple_Block.py +++ b/examples/FreeCAD/Ex001_Simple_Block.py @@ -11,10 +11,11 @@ #If you need to reload the part after making a change, you can use the following lines within the FreeCAD console. #reload(Ex001_Simple_Block) -#You'll need to delete the original shape that was created, and the new shape should be named sequentially (Shape001, etc). +#You'll need to delete the original shape that was created, and the new shape should be named sequentially +# (Shape001, etc). #You can also tie these blocks of code to macros, buttons, and keybindings in FreeCAD for quicker access. -#You can get a more in-depth explantion of this example at http://parametricparts.com/docs/quickstart.html +#You can get a more in-depth explanation of this example at http://parametricparts.com/docs/quickstart.html import cadquery import Part @@ -27,10 +28,5 @@ thickness = 10.0 #Create a 3D box based on the dimension variables above result = cadquery.Workplane("XY").box(length, height, thickness) -#Get a cadquery solid object -solid = result.val() - -#Use the wrapped property of a cadquery primitive to get a FreeCAD solid -Part.show(solid.wrapped) - -#Would like to zoom to fit the part here, but FreeCAD doesn't seem to have that scripting functionality \ No newline at end of file +#Boiler plate code to render our solid in FreeCAD's GUI +Part.show(result.toFreecad()) \ No newline at end of file diff --git a/examples/FreeCAD/Ex002_Block_With_Bored_Center_Hole.py b/examples/FreeCAD/Ex002_Block_With_Bored_Center_Hole.py index 3f7bcec..ea405f5 100644 --- a/examples/FreeCAD/Ex002_Block_With_Bored_Center_Hole.py +++ b/examples/FreeCAD/Ex002_Block_With_Bored_Center_Hole.py @@ -27,12 +27,7 @@ center_hole_dia = 22.0 #Create a 3D box based on the dimension variables above and add a 22mm center hole result = cadquery.Workplane("XY").box(length, height, thickness) \ - .faces(">Z").workplane().hole(center_hole_dia) + .faces(">Z").workplane().hole(center_hole_dia) -#Get a cadquery solid object -solid = result.val() - -#Use the wrapped property of a cadquery primitive to get a FreeCAD solid -Part.show(solid.wrapped) - -#Would like to zoom to fit the part here, but FreeCAD doesn't seem to have that scripting functionality \ No newline at end of file +#Boiler plate code to render our solid in FreeCAD's GUI +Part.show(result.toFreecad()) \ No newline at end of file diff --git a/examples/FreeCAD/Ex003_Pillow_Block_With_Counterbored_Holes.py b/examples/FreeCAD/Ex003_Pillow_Block_With_Counterbored_Holes.py index b6407ab..382f03e 100644 --- a/examples/FreeCAD/Ex003_Pillow_Block_With_Counterbored_Holes.py +++ b/examples/FreeCAD/Ex003_Pillow_Block_With_Counterbored_Holes.py @@ -11,10 +11,11 @@ #If you need to reload the part after making a change, you can use the following lines within the FreeCAD console. #reload(Ex003_Pillow_Block_With_Counterbored_Holes) -#You'll need to delete the original shape that was created, and the new shape should be named sequentially (Shape001, etc). +#You'll need to delete the original shape that was created, and the new shape should be named sequentially +# (Shape001, etc). #You can also tie these blocks of code to macros, buttons, and keybindings in FreeCAD for quicker access. -#You can get a more in-depth explantion of this example at http://parametricparts.com/docs/quickstart.html +#You can get a more in-depth explanation of this example at http://parametricparts.com/docs/quickstart.html import cadquery import Part @@ -30,15 +31,10 @@ cbore_depth = 2.1 #Create a 3D box based on the dimension variables above and add 4 counterbored holes result = cadquery.Workplane("XY").box(length, height, thickness) \ - .faces(">Z").workplane().hole(center_hole_dia) \ - .faces(">Z").workplane() \ - .rect(length - 8.0, height - 8.0, forConstruction = True) \ - .vertices().cboreHole(cbore_hole_diameter, cbore_diameter, cbore_depth) + .faces(">Z").workplane().hole(center_hole_dia) \ + .faces(">Z").workplane() \ + .rect(length - 8.0, height - 8.0, forConstruction = True) \ + .vertices().cboreHole(cbore_hole_diameter, cbore_diameter, cbore_depth) -#Get a cadquery solid object -solid = result.val() - -#Use the wrapped property of a cadquery primitive to get a FreeCAD solid -Part.show(solid.wrapped) - -#Would like to zoom to fit the part here, but FreeCAD doesn't seem to have that scripting functionality \ No newline at end of file +#Boiler plate code to render our solid in FreeCAD's GUI +Part.show(result.toFreecad()) \ No newline at end of file diff --git a/examples/FreeCAD/Ex004_Extruded_Cylindrical_Plate.py b/examples/FreeCAD/Ex004_Extruded_Cylindrical_Plate.py index 3119a50..8b631ce 100644 --- a/examples/FreeCAD/Ex004_Extruded_Cylindrical_Plate.py +++ b/examples/FreeCAD/Ex004_Extruded_Cylindrical_Plate.py @@ -11,10 +11,12 @@ #If you need to reload the part after making a change, you can use the following lines within the FreeCAD console. #reload(Ex004_Extruded_Cylindrical_Plate) -#You'll need to delete the original shape that was created, and the new shape should be named sequentially (Shape001, etc). +#You'll need to delete the original shape that was created, and the new shape should be named sequentially +# (Shape001, etc). #You can also tie these blocks of code to macros, buttons, and keybindings in FreeCAD for quicker access. -#You can get a more information on this example at http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid +#You can get a more information on this example at +# http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid import cadquery import Part @@ -22,16 +24,11 @@ import Part #The dimensions of the model. These can be modified rather than changing the box's code directly. circle_radius = 50.0 rectangle_width = 13.0 -rectange_length = 19.0 +rectangle_length = 19.0 thickness = 13.0 #Extrude a cylindrical plate with a rectangular hole in the middle of it -result = cadquery.Workplane("front").circle(circle_radius).rect(rectangle_width, rectange_length).extrude(thickness) +result = cadquery.Workplane("front").circle(circle_radius).rect(rectangle_width, rectangle_length).extrude(thickness) -#Get a cadquery solid object -solid = result.val() - -#Use the wrapped property of a cadquery primitive to get a FreeCAD solid -Part.show(solid.wrapped) - -#Would like to zoom to fit the part here, but FreeCAD doesn't seem to have that scripting functionality \ No newline at end of file +#Boiler plate code to render our solid in FreeCAD's GUI +Part.show(result.toFreecad()) \ No newline at end of file diff --git a/examples/FreeCAD/Ex005_Extruded_Lines_and_Arcs.py b/examples/FreeCAD/Ex005_Extruded_Lines_and_Arcs.py index f8d5465..9994434 100644 --- a/examples/FreeCAD/Ex005_Extruded_Lines_and_Arcs.py +++ b/examples/FreeCAD/Ex005_Extruded_Lines_and_Arcs.py @@ -11,10 +11,12 @@ #If you need to reload the part after making a change, you can use the following lines within the FreeCAD console. #reload(Ex005_Extruded_Lines_and_Arcs) -#You'll need to delete the original shape that was created, and the new shape should be named sequentially (Shape001, etc). +#You'll need to delete the original shape that was created, and the new shape should be named sequentially +#(Shape001, etc). #You can also tie these blocks of code to macros, buttons, and keybindings in FreeCAD for quicker access. -#You can get a more information on this example at http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid +#You can get a more information on this example at +# http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid import cadquery import Part @@ -24,12 +26,8 @@ width = 2.0 thickness = 0.25 #Extrude a plate outline made of lines and an arc -result = cadquery.Workplane("front").lineTo(width, 0).lineTo(width, 1.0).threePointArc((1.0, 1.5),(0.0, 1.0)).close().extrude(thickness) +result = cadquery.Workplane("front").lineTo(width, 0).lineTo(width, 1.0).threePointArc((1.0, 1.5),(0.0, 1.0)) \ + .close().extrude(thickness) -#Get a cadquery solid object -solid = result.val() - -#Use the wrapped property of a cadquery primitive to get a FreeCAD solid -Part.show(solid.wrapped) - -#Would like to zoom to fit the part here, but FreeCAD doesn't seem to have that scripting functionality \ No newline at end of file +#Boiler plate code to render our solid in FreeCAD's GUI +Part.show(result.toFreecad()) \ No newline at end of file diff --git a/examples/FreeCAD/Ex006_Moving_the_Current_Working_Point.py b/examples/FreeCAD/Ex006_Moving_the_Current_Working_Point.py index e2045da..892396c 100644 --- a/examples/FreeCAD/Ex006_Moving_the_Current_Working_Point.py +++ b/examples/FreeCAD/Ex006_Moving_the_Current_Working_Point.py @@ -11,10 +11,12 @@ #If you need to reload the part after making a change, you can use the following lines within the FreeCAD console. #reload(Ex006_Moving_the_Current_Working_Point) -#You'll need to delete the original shape that was created, and the new shape should be named sequentially (Shape001, etc). +#You'll need to delete the original shape that was created, and the new shape should be named sequentially +# (Shape001, etc). #You can also tie these blocks of code to macros, buttons, and keybindings in FreeCAD for quicker access. -#You can get a more information on this example at http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid +#You can get a more information on this example at +# http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid import cadquery import Part @@ -24,18 +26,13 @@ circle_radius = 3.0 thickness = 0.25 #Make the plate with two cutouts in it -result = cadquery.Workplane("front").circle(circle_radius) #Current point is the center of the circle, at (0,0) -result = result.center(1.5,0.0).rect(0.5,0.5) #New work center is (1.5,0.0) +result = cadquery.Workplane("front").circle(circle_radius) # Current point is the center of the circle, at (0,0) +result = result.center(1.5,0.0).rect(0.5,0.5) # New work center is (1.5,0.0) -result = result.center(-1.5,1.5).circle(0.25) #New work center is ( 0.0,1.5). +result = result.center(-1.5,1.5).circle(0.25) # New work center is ( 0.0,1.5). #The new center is specified relative to the previous center, not global coordinates! result = result.extrude(thickness) -#Get a cadquery solid object -solid = result.val() - -#Use the wrapped property of a cadquery primitive to get a FreeCAD solid -Part.show(solid.wrapped) - -#Would like to zoom to fit the part here, but FreeCAD doesn't seem to have that scripting functionality \ No newline at end of file +#Boiler plate code to render our solid in FreeCAD's GUI +Part.show(result.toFreecad()) \ No newline at end of file diff --git a/examples/FreeCAD/Ex007_Using_Point_Lists.py b/examples/FreeCAD/Ex007_Using_Point_Lists.py index 1b24127..2609d84 100644 --- a/examples/FreeCAD/Ex007_Using_Point_Lists.py +++ b/examples/FreeCAD/Ex007_Using_Point_Lists.py @@ -11,10 +11,12 @@ #If you need to reload the part after making a change, you can use the following lines within the FreeCAD console. #reload(Ex007_Using_Point_Lists) -#You'll need to delete the original shape that was created, and the new shape should be named sequentially (Shape001, etc). +#You'll need to delete the original shape that was created, and the new shape should be named sequentially +# (Shape001, etc). #You can also tie these blocks of code to macros, buttons, and keybindings in FreeCAD for quicker access. -#You can get a more information on this example at http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid +#You can get a more information on this example at +# http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid import cadquery import Part @@ -25,15 +27,10 @@ hole_pattern_radius = 0.25 thickness = 0.125 #Make the plate with 4 holes in it at various points -r = cadquery.Workplane("front").circle(plate_radius) #Make the base -r = r.pushPoints( [ (1.5,0),(0,1.5),(-1.5,0),(0,-1.5) ] ) #Now four points are on the stack -r = r.circle(hole_pattern_radius) #Circle will operate on all four points +r = cadquery.Workplane("front").circle(plate_radius) # Make the base +r = r.pushPoints([(1.5, 0), (0, 1.5), (-1.5, 0), (0, -1.5)]) # Now four points are on the stack +r = r.circle(hole_pattern_radius) # Circle will operate on all four points result = r.extrude(thickness) -#Get a cadquery solid object -solid = result.val() - -#Use the wrapped property of a cadquery primitive to get a FreeCAD solid -Part.show(solid.wrapped) - -#Would like to zoom to fit the part here, but FreeCAD doesn't seem to have that scripting functionality \ No newline at end of file +#Boiler plate code to render our solid in FreeCAD's GUI +Part.show(result.toFreecad()) \ No newline at end of file diff --git a/examples/FreeCAD/Ex008_Polygon_Creation.py b/examples/FreeCAD/Ex008_Polygon_Creation.py index 1c01a8d..6eefe13 100644 --- a/examples/FreeCAD/Ex008_Polygon_Creation.py +++ b/examples/FreeCAD/Ex008_Polygon_Creation.py @@ -11,10 +11,12 @@ #If you need to reload the part after making a change, you can use the following lines within the FreeCAD console. #reload(Ex008_Polygon_Creation) -#You'll need to delete the original shape that was created, and the new shape should be named sequentially (Shape001, etc). +#You'll need to delete the original shape that was created, and the new shape should be named sequentially +# (Shape001, etc). #You can also tie these blocks of code to macros, buttons, and keybindings in FreeCAD for quicker access. -#You can get a more information on this example at http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid +#You can get a more information on this example at +# http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid import cadquery import Part @@ -27,13 +29,8 @@ polygon_sides = 6 polygon_dia = 1.0 #Create a plate with two polygons cut through it -result = cadquery.Workplane("front").box(width, height, thickness).pushPoints ( [ ( 0,0.75 ),(0,-0.75) ]) \ +result = cadquery.Workplane("front").box(width, height, thickness).pushPoints([(0, 0.75), (0, -0.75)]) \ .polygon(polygon_sides, polygon_dia).cutThruAll() -#Get a cadquery solid object -solid = result.val() - -#Use the wrapped property of a cadquery primitive to get a FreeCAD solid -Part.show(solid.wrapped) - -#Would like to zoom to fit the part here, but FreeCAD doesn't seem to have that scripting functionality \ No newline at end of file +#Boiler plate code to render our solid in FreeCAD's GUI +Part.show(result.toFreecad()) \ No newline at end of file diff --git a/examples/FreeCAD/Ex009_Polylines.py b/examples/FreeCAD/Ex009_Polylines.py index 6b0c212..73f9259 100644 --- a/examples/FreeCAD/Ex009_Polylines.py +++ b/examples/FreeCAD/Ex009_Polylines.py @@ -11,16 +11,19 @@ #If you need to reload the part after making a change, you can use the following lines within the FreeCAD console. #reload(Ex009_Polylines) -#You'll need to delete the original shape that was created, and the new shape should be named sequentially (Shape001, etc). +#You'll need to delete the original shape that was created, and the new shape should be named sequentially +# (Shape001, etc). #You can also tie these blocks of code to macros, buttons, and keybindings in FreeCAD for quicker access. -#You can get a more information on this example at http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid +#You can get a more information on this example at +# http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid import cadquery import Part -#Set up our Length, Height, Width, and thickness that will be used to define the locations that the polyline is drawn to/thru -(L,H,W,t) = ( 100.0, 20.0, 20.0, 1.0) +#Set up our Length, Height, Width, and thickness that will be used to define the locations that the polyline +#is drawn to/thru +(L, H, W, t) = (100.0, 20.0, 20.0, 1.0) #Define the locations that the polyline will be drawn to/thru pts = [ @@ -29,7 +32,7 @@ pts = [ (W/2.0, (H/2.0 - t)), (t/2.0, (H/2.0-t)), (t/2.0, (t - H/2.0)), - (W/2.0, (t -H/2.0)), + (W/2.0, (t - H/2.0)), (W/2.0, H/-2.0), (0, H/-2.0) ] @@ -37,10 +40,5 @@ pts = [ #We generate half of the I-beam outline and then mirror it to create the full I-beam result = cadquery.Workplane("front").polyline(pts).mirrorY().extrude(L) -#Get a cadquery solid object -solid = result.val() - -#Use the wrapped property of a cadquery primitive to get a FreeCAD solid -Part.show(solid.wrapped) - -#Would like to zoom to fit the part here, but FreeCAD doesn't seem to have that scripting functionality \ No newline at end of file +#Boiler plate code to render our solid in FreeCAD's GUI +Part.show(result.toFreecad()) \ No newline at end of file diff --git a/examples/FreeCAD/Ex010_Defining_an_Edge_with_a_Spline.py b/examples/FreeCAD/Ex010_Defining_an_Edge_with_a_Spline.py index 985e7b9..7a9534a 100644 --- a/examples/FreeCAD/Ex010_Defining_an_Edge_with_a_Spline.py +++ b/examples/FreeCAD/Ex010_Defining_an_Edge_with_a_Spline.py @@ -11,10 +11,12 @@ #If you need to reload the part after making a change, you can use the following lines within the FreeCAD console. #reload(Ex010_Defining_an_Edge_with_a_Spline) -#You'll need to delete the original shape that was created, and the new shape should be named sequentially (Shape001, etc). +#You'll need to delete the original shape that was created, and the new shape should be named sequentially +# (Shape001, etc). #You can also tie these blocks of code to macros, buttons, and keybindings in FreeCAD for quicker access. -#You can get a more information on this example at http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid +#You can get a more information on this example at +# http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid import cadquery import Part @@ -39,10 +41,5 @@ r = s.lineTo(3.0, 0).lineTo(3.0, 1.0).spline(sPnts).close() #Extrude to turn the wire into a plate result = r.extrude(0.5) -#Get a cadquery solid object -solid = result.val() - -#Use the wrapped property of a cadquery primitive to get a FreeCAD solid -Part.show(solid.wrapped) - -#Would like to zoom to fit the part here, but FreeCAD doesn't seem to have that scripting functionality \ No newline at end of file +#Boiler plate code to render our solid in FreeCAD's GUI +Part.show(result.toFreecad()) \ No newline at end of file diff --git a/examples/FreeCAD/Ex011_Mirroring_Symmetric_Geometry.py b/examples/FreeCAD/Ex011_Mirroring_Symmetric_Geometry.py index e666d00..54a02b6 100644 --- a/examples/FreeCAD/Ex011_Mirroring_Symmetric_Geometry.py +++ b/examples/FreeCAD/Ex011_Mirroring_Symmetric_Geometry.py @@ -11,10 +11,12 @@ #If you need to reload the part after making a change, you can use the following lines within the FreeCAD console. #reload(Ex011_Mirroring_Symmetric_Geometry) -#You'll need to delete the original shape that was created, and the new shape should be named sequentially (Shape001, etc). +#You'll need to delete the original shape that was created, and the new shape should be named sequentially +# (Shape001, etc). #You can also tie these blocks of code to macros, buttons, and keybindings in FreeCAD for quicker access. -#You can get a more information on this example at http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid +#You can get a more information on this example at +# http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid import cadquery import Part @@ -26,12 +28,7 @@ r = cadquery.Workplane("front").hLine(1.0) r = r.vLine(0.5).hLine(-0.25).vLine(-0.25).hLineTo(0.0) #Mirror the geometry and extrude -result =r.mirrorY().extrude(0.25) +result = r.mirrorY().extrude(0.25) -#Get a cadquery solid object -solid = result.val() - -#Use the wrapped property of a cadquery primitive to get a FreeCAD solid -Part.show(solid.wrapped) - -#Would like to zoom to fit the part here, but FreeCAD doesn't seem to have that scripting functionality +#Boiler plate code to render our solid in FreeCAD's GUI +Part.show(result.toFreecad()) diff --git a/examples/FreeCAD/Ex012_Creating_Workplanes_on_Faces.py b/examples/FreeCAD/Ex012_Creating_Workplanes_on_Faces.py index d46b795..50a8ba3 100644 --- a/examples/FreeCAD/Ex012_Creating_Workplanes_on_Faces.py +++ b/examples/FreeCAD/Ex012_Creating_Workplanes_on_Faces.py @@ -11,10 +11,12 @@ #If you need to reload the part after making a change, you can use the following lines within the FreeCAD console. #reload(Ex012_Creating_Workplanes_on_Faces) -#You'll need to delete the original shape that was created, and the new shape should be named sequentially (Shape001, etc). +#You'll need to delete the original shape that was created, and the new shape should be named sequentially +# (Shape001, etc). #You can also tie these blocks of code to macros, buttons, and keybindings in FreeCAD for quicker access. -#You can get a more information on this example at http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid +#You can get a more information on this example at +# http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid import cadquery import Part @@ -25,10 +27,5 @@ result = cadquery.Workplane("front").box(2,3,0.5) #Find the top-most face and make a hole result = result.faces(">Z").workplane().hole(0.5) -#Get a cadquery solid object -solid = result.val() - -#Use the wrapped property of a cadquery primitive to get a FreeCAD solid -Part.show(solid.wrapped) - -#Would like to zoom to fit the part here, but FreeCAD doesn't seem to have that scripting functionality +#Boiler plate code to render our solid in FreeCAD's GUI +Part.show(result.toFreecad()) diff --git a/examples/FreeCAD/Ex013_Locating_a_Workplane_on_a_Vertex.py b/examples/FreeCAD/Ex013_Locating_a_Workplane_on_a_Vertex.py index 2b2719a..a50f74f 100644 --- a/examples/FreeCAD/Ex013_Locating_a_Workplane_on_a_Vertex.py +++ b/examples/FreeCAD/Ex013_Locating_a_Workplane_on_a_Vertex.py @@ -11,16 +11,18 @@ #If you need to reload the part after making a change, you can use the following lines within the FreeCAD console. #reload(Ex013_Locating_a_Workplane_on_a_Vertex) -#You'll need to delete the original shape that was created, and the new shape should be named sequentially (Shape001, etc). +#You'll need to delete the original shape that was created, and the new shape should be named sequentially +# (Shape001, etc). #You can also tie these blocks of code to macros, buttons, and keybindings in FreeCAD for quicker access. -#You can get a more information on this example at http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid +#You can get a more information on this example at +# http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid import cadquery import Part #Make a basic prism -result = cadquery.Workplane("front").box(3,2,0.5) +result = cadquery.Workplane("front").box(3, 2, 0.5) #Select the lower left vertex and make a workplane result = result.faces(">Z").vertices("Z").vertices("Z").workplane() \ - .transformed(offset=Vector(0,-1.5,1.0),rotate=Vector(60,0,0)) \ - .rect(1.5,1.5,forConstruction=True).vertices().hole(0.25) +#Create a rotated workplane and put holes in each corner of a rectangle on that workplane, producing angled holes +#in the face +result = cadquery.Workplane("front").box(4.0, 4.0, 0.25).faces(">Z").workplane() \ + .transformed(offset=Vector(0, -1.5, 1.0), rotate=Vector(60, 0, 0)) \ + .rect(1.5, 1.5, forConstruction=True).vertices().hole(0.25) -#Get a cadquery solid object -solid = result.val() - -#Use the wrapped property of a cadquery primitive to get a FreeCAD solid -Part.show(solid.wrapped) - -#Would like to zoom to fit the part here, but FreeCAD doesn't seem to have that scripting functionality +#Boiler plate code to render our solid in FreeCAD's GUI +Part.show(result.toFreecad()) diff --git a/examples/FreeCAD/Ex016_Using_Construction_Geometry.py b/examples/FreeCAD/Ex016_Using_Construction_Geometry.py index c3b5d43..69ba013 100644 --- a/examples/FreeCAD/Ex016_Using_Construction_Geometry.py +++ b/examples/FreeCAD/Ex016_Using_Construction_Geometry.py @@ -11,10 +11,12 @@ #If you need to reload the part after making a change, you can use the following lines within the FreeCAD console. #reload(Ex016_Using_Construction_Geometry) -#You'll need to delete the original shape that was created, and the new shape should be named sequentially (Shape001, etc). +#You'll need to delete the original shape that was created, and the new shape should be named sequentially +# (Shape001, etc). #You can also tie these blocks of code to macros, buttons, and keybindings in FreeCAD for quicker access. -#You can get a more information on this example at http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid +#You can get a more information on this example at +# http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid import cadquery import Part @@ -23,10 +25,5 @@ import Part result = cadquery.Workplane("front").box(2, 2, 0.5).faces(">Z").workplane() \ .rect(1.5, 1.5, forConstruction=True).vertices().hole(0.125) -#Get a cadquery solid object -solid = result.val() - -#Use the wrapped property of a cadquery primitive to get a FreeCAD solid -Part.show(solid.wrapped) - -#Would like to zoom to fit the part here, but FreeCAD doesn't seem to have that scripting functionality +#Boiler plate code to render our solid in FreeCAD's GUI +Part.show(result.toFreecad()) diff --git a/examples/FreeCAD/Ex017_Shelling_to_Create_Thin_Features.py b/examples/FreeCAD/Ex017_Shelling_to_Create_Thin_Features.py index 826a8a4..7965c44 100644 --- a/examples/FreeCAD/Ex017_Shelling_to_Create_Thin_Features.py +++ b/examples/FreeCAD/Ex017_Shelling_to_Create_Thin_Features.py @@ -11,21 +11,18 @@ #If you need to reload the part after making a change, you can use the following lines within the FreeCAD console. #reload(Ex017_Shelling_to_Create_Thin_Features) -#You'll need to delete the original shape that was created, and the new shape should be named sequentially (Shape001, etc). +#You'll need to delete the original shape that was created, and the new shape should be named sequentially +# (Shape001, etc). #You can also tie these blocks of code to macros, buttons, and keybindings in FreeCAD for quicker access. -#You can get a more information on this example at http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid +#You can get a more information on this example at +# http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid import cadquery import Part #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) +result = cadquery.Workplane("front").box(2, 2, 2).faces("+Z").shell(0.05) -#Get a cadquery solid object -solid = result.val() - -#Use the wrapped property of a cadquery primitive to get a FreeCAD solid -Part.show(solid.wrapped) - -#Would like to zoom to fit the part here, but FreeCAD doesn't seem to have that scripting functionality +#Boiler plate code to render our solid in FreeCAD's GUI +Part.show(result.toFreecad()) diff --git a/examples/FreeCAD/Ex018_Making_Lofts.py b/examples/FreeCAD/Ex018_Making_Lofts.py index 1c96994..847285a 100644 --- a/examples/FreeCAD/Ex018_Making_Lofts.py +++ b/examples/FreeCAD/Ex018_Making_Lofts.py @@ -11,10 +11,12 @@ #If you need to reload the part after making a change, you can use the following lines within the FreeCAD console. #reload(Ex018_Making_Lofts) -#You'll need to delete the original shape that was created, and the new shape should be named sequentially (Shape001, etc). +#You'll need to delete the original shape that was created, and the new shape should be named sequentially +# (Shape001, etc). #You can also tie these blocks of code to macros, buttons, and keybindings in FreeCAD for quicker access. -#You can get a more information on this example at http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid +#You can get a more information on this example at +# http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid import cadquery import Part @@ -23,10 +25,5 @@ import Part 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) -#Get a cadquery solid object -solid = result.val() - -#Use the wrapped property of a cadquery primitive to get a FreeCAD solid -Part.show(solid.wrapped) - -#Would like to zoom to fit the part here, but FreeCAD doesn't seem to have that scripting functionality +#Boiler plate code to render our solid in FreeCAD's GUI +Part.show(result.toFreecad()) diff --git a/examples/FreeCAD/Ex019_Counter_Sunk_Holes.py b/examples/FreeCAD/Ex019_Counter_Sunk_Holes.py index affd21b..4a2590d 100644 --- a/examples/FreeCAD/Ex019_Counter_Sunk_Holes.py +++ b/examples/FreeCAD/Ex019_Counter_Sunk_Holes.py @@ -11,22 +11,20 @@ #If you need to reload the part after making a change, you can use the following lines within the FreeCAD console. #reload(Ex019_Counter_Sunk_Holes) -#You'll need to delete the original shape that was created, and the new shape should be named sequentially (Shape001, etc). +#You'll need to delete the original shape that was created, and the new shape should be named sequentially +# (Shape001, etc). #You can also tie these blocks of code to macros, buttons, and keybindings in FreeCAD for quicker access. -#You can get a more information on this example at http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid +#You can get a more information on this example at +# http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid import cadquery import Part #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)\ - .vertices().cskHole(0.125, 0.25, 82.0, depth=None) +result = cadquery.Workplane(cadquery.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) -#Get a cadquery solid object -solid = result.val() - -#Use the wrapped property of a cadquery primitive to get a FreeCAD solid -Part.show(solid.wrapped) - -#Would like to zoom to fit the part here, but FreeCAD doesn't seem to have that scripting functionality +#Boiler plate code to render our solid in FreeCAD's GUI +Part.show(result.toFreecad()) diff --git a/examples/FreeCAD/Ex020_Rounding_Corners_with_Fillets.py b/examples/FreeCAD/Ex020_Rounding_Corners_with_Fillets.py index aa70632..2d71322 100644 --- a/examples/FreeCAD/Ex020_Rounding_Corners_with_Fillets.py +++ b/examples/FreeCAD/Ex020_Rounding_Corners_with_Fillets.py @@ -11,21 +11,18 @@ #If you need to reload the part after making a change, you can use the following lines within the FreeCAD console. #reload(Ex020_Rounding_Corners_with_Fillets) -#You'll need to delete the original shape that was created, and the new shape should be named sequentially (Shape001, etc). +#You'll need to delete the original shape that was created, and the new shape should be named sequentially +# (Shape001, etc). #You can also tie these blocks of code to macros, buttons, and keybindings in FreeCAD for quicker access. -#You can get a more information on this example at http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid +#You can get a more information on this example at +# http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid import cadquery import Part #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) +result = cadquery.Workplane("XY").box(3, 3, 0.5).edges("|Z").fillet(0.125) -#Get a cadquery solid object -solid = result.val() - -#Use the wrapped property of a cadquery primitive to get a FreeCAD solid -Part.show(solid.wrapped) - -#Would like to zoom to fit the part here, but FreeCAD doesn't seem to have that scripting functionality +#Boiler plate code to render our solid in FreeCAD's GUI +Part.show(result.toFreecad()) diff --git a/examples/FreeCAD/Ex021_Splitting_an_Object.py b/examples/FreeCAD/Ex021_Splitting_an_Object.py index 25f0e6a..133104a 100644 --- a/examples/FreeCAD/Ex021_Splitting_an_Object.py +++ b/examples/FreeCAD/Ex021_Splitting_an_Object.py @@ -11,10 +11,12 @@ #If you need to reload the part after making a change, you can use the following lines within the FreeCAD console. #reload(Ex021_Splitting_an_Object) -#You'll need to delete the original shape that was created, and the new shape should be named sequentially (Shape001, etc). +#You'll need to delete the original shape that was created, and the new shape should be named sequentially +# (Shape001, etc). #You can also tie these blocks of code to macros, buttons, and keybindings in FreeCAD for quicker access. -#You can get a more information on this example at http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid +#You can get a more information on this example at +# http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid import cadquery import Part @@ -25,10 +27,5 @@ c = cadquery.Workplane("XY").box(1, 1, 1).faces(">Z").workplane().circle(0.25).c #Cut the block in half sideways result = c.faces(">Y").workplane(-0.5).split(keepTop=True) -#Get a cadquery solid object -solid = result.val() - -#Use the wrapped property of a cadquery primitive to get a FreeCAD solid -Part.show(solid.wrapped) - -#Would like to zoom to fit the part here, but FreeCAD doesn't seem to have that scripting functionality +#Boiler plate code to render our solid in FreeCAD's GUI +Part.show(result.toFreecad()) diff --git a/examples/FreeCAD/Ex022_Classic_OCC_Bottle.py b/examples/FreeCAD/Ex022_Classic_OCC_Bottle.py index cd30eb5..8ea52c5 100644 --- a/examples/FreeCAD/Ex022_Classic_OCC_Bottle.py +++ b/examples/FreeCAD/Ex022_Classic_OCC_Bottle.py @@ -11,10 +11,12 @@ #If you need to reload the part after making a change, you can use the following lines within the FreeCAD console. #reload(Ex022_Classic_OCC_Bottle) -#You'll need to delete the original shape that was created, and the new shape should be named sequentially (Shape001, etc). +#You'll need to delete the original shape that was created, and the new shape should be named sequentially +# (Shape001, etc). #You can also tie these blocks of code to macros, buttons, and keybindings in FreeCAD for quicker access. -#You can get a more information on this example at http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid +#You can get a more information on this example at +# http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid import cadquery import Part @@ -34,10 +36,5 @@ p.faces(">Z").workplane().circle(3.0).extrude(2.0, True) #Make a shell result = p.faces(">Z").shell(0.3) -#Get a cadquery solid object -solid = result.val() - -#Use the wrapped property of a cadquery primitive to get a FreeCAD solid -Part.show(solid.wrapped) - -#Would like to zoom to fit the part here, but FreeCAD doesn't seem to have that scripting functionality +#Boiler plate code to render our solid in FreeCAD's GUI +Part.show(result.toFreecad()) diff --git a/examples/FreeCAD/Ex023_Parametric_Enclosure.py b/examples/FreeCAD/Ex023_Parametric_Enclosure.py index d6a499f..ef3308f 100644 --- a/examples/FreeCAD/Ex023_Parametric_Enclosure.py +++ b/examples/FreeCAD/Ex023_Parametric_Enclosure.py @@ -11,33 +11,35 @@ #If you need to reload the part after making a change, you can use the following lines within the FreeCAD console. #reload(Ex023_Parametric_Enclosure) -#You'll need to delete the original shape that was created, and the new shape should be named sequentially (Shape001, etc). +#You'll need to delete the original shape that was created, and the new shape should be named sequentially +# (Shape001, etc). #You can also tie these blocks of code to macros, buttons, and keybindings in FreeCAD for quicker access. -#You can get a more information on this example at http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid +#You can get a more information on this example at +# http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid import cadquery import Part #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_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 of the box +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 of the box -p_screwpostInset = 12.0 #How far in from the edges the screwposts should be placed -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_screwpostInset = 12.0 # How far in from the edges the screwposts should be placed +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_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. Sits inside the box body for a snug fit. +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. Sits inside the box body for a snug fit. #Outer shell oshell = cadquery.Workplane("XY").rect(p_outerWidth, p_outerLength).extrude(p_outerHeight + p_lipHeight) @@ -53,7 +55,7 @@ else: #Inner shell ishell = oshell.faces("Z").workplane(-p_thickness)\ .rect(POSTWIDTH, POSTLENGTH, forConstruction=True)\ @@ -72,11 +74,11 @@ for v in postCenters.all(): .extrude((-1.0) * ((p_outerHeight + p_lipHeight) - (2.0 * 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() #splits into two solids +(lid, bottom) = box.faces(">Z").workplane(-p_thickness - p_lipHeight).split(keepTop=True, keepBottom=True).all() #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)) +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() @@ -87,7 +89,7 @@ if p_boreDiameter > 0 and p_boreDepth > 0: elif p_countersinkDiameter > 0 and p_countersinkAngle > 0: 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) #Flip lid upside down if desired if p_flipLid: @@ -96,10 +98,5 @@ if p_flipLid: #Return the combined result result = topOfLid.combineSolids(bottom) -#Get a cadquery solid object -solid = result.val() - -#Use the wrapped property of a cadquery primitive to get a FreeCAD solid -Part.show(solid.wrapped) - -#Would like to zoom to fit the part here, but FreeCAD doesn't seem to have that scripting functionality +#Boiler plate code to render our solid in FreeCAD's GUI +Part.show(result.toFreecad()) diff --git a/examples/FreeCAD/Ex024_Using_FreeCAD_Solids_as_CQ_Objects.py b/examples/FreeCAD/Ex024_Using_FreeCAD_Solids_as_CQ_Objects.py index 524e0a8..7a8088f 100644 --- a/examples/FreeCAD/Ex024_Using_FreeCAD_Solids_as_CQ_Objects.py +++ b/examples/FreeCAD/Ex024_Using_FreeCAD_Solids_as_CQ_Objects.py @@ -11,14 +11,16 @@ #If you need to reload the part after making a change, you can use the following lines within the FreeCAD console. #reload(Ex024_Using_FreeCAD_Solids_as_CQ_Objects) -#You'll need to delete the original shape that was created, and the new shape should be named sequentially (Shape001, etc). +#You'll need to delete the original shape that was created, and the new shape should be named sequentially +# (Shape001, etc). #You can also tie these blocks of code to macros, buttons, and keybindings in FreeCAD for quicker access. -#You can get a more information on this example at http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid +#You can get a more information on this example at +# http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid import cadquery, FreeCAD, Part -#Create a new document that we can draw our modle on +#Create a new document that we can draw our model on newDoc = FreeCAD.newDocument() #shows a 1x1x1 FreeCAD cube in the display @@ -32,10 +34,8 @@ cqBox = cadquery.CQ(cadquery.Solid(initialBox.Shape)) newThing = cqBox.faces(">Z").workplane().circle(0.5).extrude(0.25) #Add a FreeCAD object to the tree and then store a CQ object in it -nextShape = newDoc.addObject("Part::Feature","nextShape") +nextShape = newDoc.addObject("Part::Feature", "nextShape") nextShape.Shape = newThing.val().wrapped #Rerender the doc to see what the new solid looks like newDoc.recompute() - -#Would like to zoom to fit the part here, but FreeCAD doesn't seem to have that scripting functionality diff --git a/examples/FreeCAD/Ex025_Revolution.py b/examples/FreeCAD/Ex025_Revolution.py index 7b17422..e0f9364 100644 --- a/examples/FreeCAD/Ex025_Revolution.py +++ b/examples/FreeCAD/Ex025_Revolution.py @@ -11,10 +11,12 @@ #If you need to reload the part after making a change, you can use the following lines within the FreeCAD console. #reload(Ex025_Revolution) -#You'll need to delete the original shape that was created, and the new shape should be named sequentially (Shape001, etc). +#You'll need to delete the original shape that was created, and the new shape should be named sequentially +# (Shape001, etc). #You can also tie these blocks of code to macros, buttons, and keybindings in FreeCAD for quicker access. -#You can get a more information on this example at http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid +#You can get a more information on this example at +# http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid import cadquery import Part @@ -35,10 +37,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)) -#Get a cadquery solid object -solid = result.val() - -#Use the wrapped property of a cadquery primitive to get a FreeCAD solid -Part.show(solid.wrapped) - -#Would like to zoom to fit the part here, but FreeCAD doesn't seem to have that scripting functionality +#Boiler plate code to render our solid in FreeCAD's GUI +Part.show(result.toFreecad())