Continued working through the examples on ParametricParts.com, adding 3 more and fixing some variables that weren't updated in some of the older examples.

This commit is contained in:
Jeremy Wright 2014-06-26 21:54:55 -04:00
parent 0fcd01b3b0
commit d8ba4b23e9
9 changed files with 159 additions and 26 deletions

View File

@ -23,10 +23,11 @@ import Part
length = 80.0 length = 80.0
height = 60.0 height = 60.0
thickness = 10.0 thickness = 10.0
center_hole_dia = 22.0
#Create a 3D box based on the dimension variables above and add a 22mm center hole #Create a 3D box based on the dimension variables above and add a 22mm center hole
result = cadquery.Workplane("XY").box(length, height, thickness) \ result = cadquery.Workplane("XY").box(length, height, thickness) \
.faces(">Z").workplane().hole(22.0) .faces(">Z").workplane().hole(center_hole_dia)
#Get a cadquery solid object #Get a cadquery solid object
solid = result.val() solid = result.val()

View File

@ -23,13 +23,17 @@ import Part
length = 80.0 length = 80.0
height = 60.0 height = 60.0
thickness = 10.0 thickness = 10.0
center_hole_dia = 22.0
cbore_hole_diameter = 2.4
cbore_diameter = 4.4
cbore_depth = 2.1
#Create a 3D box based on the dimension variables above and add 3 counterbored holes #Create a 3D box based on the dimension variables above and add 4 counterbored holes
result = cadquery.Workplane("XY").box(length, height, thickness) \ result = cadquery.Workplane("XY").box(length, height, thickness) \
.faces(">Z").workplane().hole(22.0) \ .faces(">Z").workplane().hole(center_hole_dia) \
.faces(">Z").workplane() \ .faces(">Z").workplane() \
.rect(length - 8.0, height - 8.0, forConstruction = True) \ .rect(length - 8.0, height - 8.0, forConstruction = True) \
.vertices().cboreHole(2.4, 4.4, 2.1) .vertices().cboreHole(cbore_hole_diameter, cbore_diameter, cbore_depth)
#Get a cadquery solid object #Get a cadquery solid object
solid = result.val() solid = result.val()

View File

@ -19,7 +19,7 @@
import cadquery import cadquery
import Part import Part
#The dimensions of the box. These can be modified rather than changing the box's code directly. #The dimensions of the model. These can be modified rather than changing the box's code directly.
circle_radius = 50.0 circle_radius = 50.0
rectangle_width = 13.0 rectangle_width = 13.0
rectange_length = 19.0 rectange_length = 19.0

View File

@ -19,14 +19,12 @@
import cadquery import cadquery
import Part import Part
#The dimensions of the box. These can be modified rather than changing the box's code directly. #The dimensions of the model. These can be modified rather than changing the box's code directly.
circle_radius = 50.0 width = 2.0
rectangle_width = 13.0 thickness = 0.25
rectange_length = 19.0
thickness = 13.0
#Extrude a plate outline made of lines and an arc #Extrude a plate outline made of lines and an arc
result = cadquery.Workplane("front").lineTo(2.0,0).lineTo(2.0,1.0).threePointArc((1.0,1.5),(0.0,1.0)).close().extrude(0.25) 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 #Get a cadquery solid object
solid = result.val() solid = result.val()

View File

@ -19,20 +19,18 @@
import cadquery import cadquery
import Part import Part
#The dimensions of the box. These can be modified rather than changing the box's code directly. #The dimensions of the model. These can be modified rather than changing the box's code directly.
circle_radius = 50.0 circle_radius = 3.0
rectangle_width = 13.0 thickness = 0.25
rectange_length = 19.0
thickness = 13.0
#Make the plate with two cutouts in it #Make the plate with two cutouts in it
result = cadquery.Workplane("front").circle(3.0) #Current point is the center of the circle, at (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,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! #The new center is specified relative to the previous center, not global coordinates!
result = result.extrude(0.25) result = result.extrude(thickness)
#Get a cadquery solid object #Get a cadquery solid object
solid = result.val() solid = result.val()

View File

@ -19,17 +19,16 @@
import cadquery import cadquery
import Part import Part
#The dimensions of the box. These can be modified rather than changing the box's code directly. #The dimensions of the model. These can be modified rather than changing the box's code directly.
circle_radius = 50.0 plate_radius = 2.0
rectangle_width = 13.0 hole_pattern_radius = 0.25
rectange_length = 19.0 thickness = 0.125
thickness = 13.0
#Make the plate with 4 holes in it at various points #Make the plate with 4 holes in it at various points
r = cadquery.Workplane("front").circle(2.0) #Make the base 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.pushPoints( [ (1.5,0),(0,1.5),(-1.5,0),(0,-1.5) ] ) #Now four points are on the stack
r = r.circle( 0.25 ) #Circle will operate on all four points r = r.circle(hole_pattern_radius) #Circle will operate on all four points
result = r.extrude(0.125 ) result = r.extrude(thickness)
#Get a cadquery solid object #Get a cadquery solid object
solid = result.val() solid = result.val()

View File

@ -0,0 +1,39 @@
#File: Ex008_Polygon_Creation.py
#To use this example file, you need to first follow the "Using CadQuery From Inside FreeCAD"
#instructions here: https://github.com/dcowden/cadquery#installing----using-cadquery-from-inside-freecad
#You run this example by typing the following in the FreeCAD python console, making sure to change
#the path to this example, and the name of the example appropriately.
#import sys
#sys.path.append('/home/user/Downloads/cadquery/examples/FreeCAD')
#import Ex008_Polygon_Creation
#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 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
import cadquery
import Part
#The dimensions of the model. These can be modified rather than changing the box's code directly.
width = 3.0
height = 4.0
thickness = 0.25
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) ]) \
.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

View File

@ -0,0 +1,46 @@
#File: Ex009_Polylines.py
#To use this example file, you need to first follow the "Using CadQuery From Inside FreeCAD"
#instructions here: https://github.com/dcowden/cadquery#installing----using-cadquery-from-inside-freecad
#You run this example by typing the following in the FreeCAD python console, making sure to change
#the path to this example, and the name of the example appropriately.
#import sys
#sys.path.append('/home/user/Downloads/cadquery/examples/FreeCAD')
#import Ex009_Polylines
#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 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
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)
#Define the locations that the polyline will be drawn to/thru
pts = [
(0, H/2.0),
(W/2.0, H/2.0),
(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, H/-2.0),
(0, H/-2.0)
]
#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

View File

@ -0,0 +1,48 @@
#File: Ex010_Defining_an_Edge_with_a_Spline.py
#To use this example file, you need to first follow the "Using CadQuery From Inside FreeCAD"
#instructions here: https://github.com/dcowden/cadquery#installing----using-cadquery-from-inside-freecad
#You run this example by typing the following in the FreeCAD python console, making sure to change
#the path to this example, and the name of the example appropriately.
#import sys
#sys.path.append('/home/user/Downloads/cadquery/examples/FreeCAD')
#import Ex010_Defining_an_Edge_with_a_Spline
#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 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
import cadquery
import Part
#The workplane we want to create the spline on to extrude
s = cadquery.Workplane("XY")
#The points that the spline will pass through
sPnts = [
(2.75, 1.5),
(2.5, 1.75),
(2.0, 1.5),
(1.5, 1.0),
(1.0, 1.25),
(0.5, 1.0),
(0, 1.0)
]
#Generate our plate with the spline feature and make sure it's a closed entity
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