Added toFreecad function and modified the examples to use it. Also cleaned up minor PEP non-conformances.

This commit is contained in:
Jeremy Wright 2014-11-04 17:13:21 -05:00
parent 83e61efbe4
commit 528e4e3a46
26 changed files with 207 additions and 270 deletions

View File

@ -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):

View File

@ -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
#Boiler plate code to render our solid in FreeCAD's GUI
Part.show(result.toFreecad())

View File

@ -29,10 +29,5 @@ center_hole_dia = 22.0
result = cadquery.Workplane("XY").box(length, height, thickness) \
.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
#Boiler plate code to render our solid in FreeCAD's GUI
Part.show(result.toFreecad())

View File

@ -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
@ -35,10 +36,5 @@ result = cadquery.Workplane("XY").box(length, height, thickness) \
.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
#Boiler plate code to render our solid in FreeCAD's GUI
Part.show(result.toFreecad())

View File

@ -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
#Boiler plate code to render our solid in FreeCAD's GUI
Part.show(result.toFreecad())

View File

@ -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
#Boiler plate code to render our solid in FreeCAD's GUI
Part.show(result.toFreecad())

View File

@ -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
@ -32,10 +34,5 @@ result = result.center(-1.5,1.5).circle(0.25) #New work center is ( 0.0,1.5).
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
#Boiler plate code to render our solid in FreeCAD's GUI
Part.show(result.toFreecad())

View File

@ -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
@ -30,10 +32,5 @@ r = r.pushPoints( [ (1.5,0),(0,1.5),(-1.5,0),(0,-1.5) ] ) #Now four points are
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
#Boiler plate code to render our solid in FreeCAD's GUI
Part.show(result.toFreecad())

View File

@ -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
@ -30,10 +32,5 @@ polygon_dia = 1.0
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
#Boiler plate code to render our solid in FreeCAD's GUI
Part.show(result.toFreecad())

View File

@ -11,15 +11,18 @@
#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
#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
@ -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
#Boiler plate code to render our solid in FreeCAD's GUI
Part.show(result.toFreecad())

View File

@ -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
#Boiler plate code to render our solid in FreeCAD's GUI
Part.show(result.toFreecad())

View File

@ -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
@ -28,10 +30,5 @@ 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)
#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())

View File

@ -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())

View File

@ -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(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
@ -28,10 +30,5 @@ result = result.faces(">Z").vertices("<XY").workplane()
#Cut the corner out
result = result.circle(1.0).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
#Boiler plate code to render our solid in FreeCAD's GUI
Part.show(result.toFreecad())

View File

@ -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(Ex014_Offset_Workplanes)
#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
@ -28,10 +30,5 @@ result = result.faces("<X").workplane(offset=0.75)
#Create a disc
result = result.circle(1.0).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
#Boiler plate code to render our solid in FreeCAD's GUI
Part.show(result.toFreecad())

View File

@ -11,24 +11,22 @@
#If you need to reload the part after making a change, you can use the following lines within the FreeCAD console.
#reload(Ex015_Rotated_Workplanes)
#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
from cadquery import Vector
import Part
#Create a rotated workplane and put holes in each corner of a rectangle on that workplane, producing angled holes in the face
#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())

View File

@ -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())

View File

@ -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(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
@ -22,10 +24,5 @@ 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)
#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())

View File

@ -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())

View File

@ -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)\
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())

View File

@ -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(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
@ -22,10 +24,5 @@ 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)
#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())

View File

@ -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())

View File

@ -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())

View File

@ -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(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
@ -72,7 +74,7 @@ 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))
@ -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())

View File

@ -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
@ -37,5 +39,3 @@ 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

View File

@ -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())