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:
parent
0fcd01b3b0
commit
d8ba4b23e9
|
@ -23,10 +23,11 @@ import Part
|
|||
length = 80.0
|
||||
height = 60.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
|
||||
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
|
||||
solid = result.val()
|
||||
|
|
|
@ -23,13 +23,17 @@ import Part
|
|||
length = 80.0
|
||||
height = 60.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) \
|
||||
.faces(">Z").workplane().hole(22.0) \
|
||||
.faces(">Z").workplane().hole(center_hole_dia) \
|
||||
.faces(">Z").workplane() \
|
||||
.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
|
||||
solid = result.val()
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
import cadquery
|
||||
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
|
||||
rectangle_width = 13.0
|
||||
rectange_length = 19.0
|
||||
|
|
|
@ -19,14 +19,12 @@
|
|||
import cadquery
|
||||
import Part
|
||||
|
||||
#The dimensions of the box. These can be modified rather than changing the box's code directly.
|
||||
circle_radius = 50.0
|
||||
rectangle_width = 13.0
|
||||
rectange_length = 19.0
|
||||
thickness = 13.0
|
||||
#The dimensions of the model. These can be modified rather than changing the box's code directly.
|
||||
width = 2.0
|
||||
thickness = 0.25
|
||||
|
||||
#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
|
||||
solid = result.val()
|
||||
|
|
|
@ -19,20 +19,18 @@
|
|||
import cadquery
|
||||
import Part
|
||||
|
||||
#The dimensions of the box. These can be modified rather than changing the box's code directly.
|
||||
circle_radius = 50.0
|
||||
rectangle_width = 13.0
|
||||
rectange_length = 19.0
|
||||
thickness = 13.0
|
||||
#The dimensions of the model. These can be modified rather than changing the box's code directly.
|
||||
circle_radius = 3.0
|
||||
thickness = 0.25
|
||||
|
||||
#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,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(0.25)
|
||||
result = result.extrude(thickness)
|
||||
|
||||
#Get a cadquery solid object
|
||||
solid = result.val()
|
||||
|
|
|
@ -19,17 +19,16 @@
|
|||
import cadquery
|
||||
import Part
|
||||
|
||||
#The dimensions of the box. These can be modified rather than changing the box's code directly.
|
||||
circle_radius = 50.0
|
||||
rectangle_width = 13.0
|
||||
rectange_length = 19.0
|
||||
thickness = 13.0
|
||||
#The dimensions of the model. These can be modified rather than changing the box's code directly.
|
||||
plate_radius = 2.0
|
||||
hole_pattern_radius = 0.25
|
||||
thickness = 0.125
|
||||
|
||||
#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.circle( 0.25 ) #Circle will operate on all four points
|
||||
result = r.extrude(0.125 )
|
||||
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()
|
||||
|
|
39
examples/FreeCAD/Ex008_Polygon_Creation.py
Normal file
39
examples/FreeCAD/Ex008_Polygon_Creation.py
Normal 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
|
46
examples/FreeCAD/Ex009_Polylines.py
Normal file
46
examples/FreeCAD/Ex009_Polylines.py
Normal 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
|
48
examples/FreeCAD/Ex010_Defining_an_Edge_with_a_Spline.py
Normal file
48
examples/FreeCAD/Ex010_Defining_an_Edge_with_a_Spline.py
Normal 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
|
Loading…
Reference in New Issue
Block a user