Reworked the core examples to exclude contributed examples.
This commit is contained in:
19
examples/Ex001_Simple_Block.py
Normal file
19
examples/Ex001_Simple_Block.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import cadquery as cq
|
||||||
|
|
||||||
|
# These can be modified rather than hardcoding values for each dimension.
|
||||||
|
length = 80.0 # Length of the block
|
||||||
|
height = 60.0 # Height of the block
|
||||||
|
thickness = 10.0 # Thickness of the block
|
||||||
|
|
||||||
|
# Create a 3D block based on the dimension variables above.
|
||||||
|
# 1. Establishes a workplane that an object can be built on.
|
||||||
|
# 1a. Uses the X and Y origins to define the workplane, meaning that the
|
||||||
|
# positive Z direction is "up", and the negative Z direction is "down".
|
||||||
|
result = cq.Workplane("XY").box(length, height, thickness)
|
||||||
|
|
||||||
|
# The following method is now outdated, but can still be used to display the
|
||||||
|
# results of the script if you want
|
||||||
|
# from Helpers import show
|
||||||
|
# show(result) # Render the result of this script
|
||||||
|
|
||||||
|
show_object(result)
|
20
examples/Ex002_Block_With_Bored_Center_Hole.py
Normal file
20
examples/Ex002_Block_With_Bored_Center_Hole.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import cadquery as cq
|
||||||
|
|
||||||
|
# These can be modified rather than hardcoding values for each dimension.
|
||||||
|
length = 80.0 # Length of the block
|
||||||
|
height = 60.0 # Height of the block
|
||||||
|
thickness = 10.0 # Thickness of the block
|
||||||
|
center_hole_dia = 22.0 # Diameter of center hole in block
|
||||||
|
|
||||||
|
# Create a block based on the dimensions above and add a 22mm center hole.
|
||||||
|
# 1. Establishes a workplane that an object can be built on.
|
||||||
|
# 1a. Uses the X and Y origins to define the workplane, meaning that the
|
||||||
|
# positive Z direction is "up", and the negative Z direction is "down".
|
||||||
|
# 2. The highest (max) Z face is selected and a new workplane is created on it.
|
||||||
|
# 3. The new workplane is used to drill a hole through the block.
|
||||||
|
# 3a. The hole is automatically centered in the workplane.
|
||||||
|
result = cq.Workplane("XY").box(length, height, thickness) \
|
||||||
|
.faces(">Z").workplane().hole(center_hole_dia)
|
||||||
|
|
||||||
|
# Displays the result of this script
|
||||||
|
show_object(result)
|
34
examples/Ex003_Pillow_Block_With_Counterbored_Holes.py
Normal file
34
examples/Ex003_Pillow_Block_With_Counterbored_Holes.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import cadquery as cq
|
||||||
|
|
||||||
|
# These can be modified rather than hardcoding values for each dimension.
|
||||||
|
length = 80.0 # Length of the block
|
||||||
|
height = 60.0 # Height of the block
|
||||||
|
thickness = 10.0 # Thickness of the block
|
||||||
|
center_hole_dia = 22.0 # Diameter of center hole in block
|
||||||
|
cbore_hole_diameter = 2.4 # Bolt shank/threads clearance hole diameter
|
||||||
|
cbore_diameter = 4.4 # Bolt head pocket hole diameter
|
||||||
|
cbore_depth = 2.1 # Bolt head pocket hole depth
|
||||||
|
|
||||||
|
# Create a 3D block based on the dimensions above and add a 22mm center hold
|
||||||
|
# and 4 counterbored holes for bolts
|
||||||
|
# 1. Establishes a workplane that an object can be built on.
|
||||||
|
# 1a. Uses the X and Y origins to define the workplane, meaning that the
|
||||||
|
# positive Z direction is "up", and the negative Z direction is "down".
|
||||||
|
# 2. The highest(max) Z face is selected and a new workplane is created on it.
|
||||||
|
# 3. The new workplane is used to drill a hole through the block.
|
||||||
|
# 3a. The hole is automatically centered in the workplane.
|
||||||
|
# 4. The highest(max) Z face is selected and a new workplane is created on it.
|
||||||
|
# 5. A for-construction rectangle is created on the workplane based on the
|
||||||
|
# block's overall dimensions.
|
||||||
|
# 5a. For-construction objects are used only to place other geometry, they
|
||||||
|
# do not show up in the final displayed geometry.
|
||||||
|
# 6. The vertices of the rectangle (corners) are selected, and a counter-bored
|
||||||
|
# hole is placed at each of the vertices (all 4 of them at once).
|
||||||
|
result = cq.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)
|
||||||
|
|
||||||
|
# Displays the result of this script
|
||||||
|
show_object(result)
|
29
examples/Ex004_Extruded_Cylindrical_Plate.py
Normal file
29
examples/Ex004_Extruded_Cylindrical_Plate.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import cadquery as cq
|
||||||
|
|
||||||
|
# These can be modified rather than hardcoding values for each dimension.
|
||||||
|
circle_radius = 50.0 # Radius of the plate
|
||||||
|
thickness = 13.0 # Thickness of the plate
|
||||||
|
rectangle_width = 13.0 # Width of rectangular hole in cylindrical plate
|
||||||
|
rectangle_length = 19.0 # Length of rectangular hole in cylindrical plate
|
||||||
|
|
||||||
|
# Extrude a cylindrical plate with a rectangular hole in the middle of it.
|
||||||
|
# 1. Establishes a workplane that an object can be built on.
|
||||||
|
# 1a. Uses the named plane orientation "front" to define the workplane, meaning
|
||||||
|
# that the positive Z direction is "up", and the negative Z direction
|
||||||
|
# is "down".
|
||||||
|
# 2. The 2D geometry for the outer circle is created at the same time as the
|
||||||
|
# rectangle that will create the hole in the center.
|
||||||
|
# 2a. The circle and the rectangle will be automatically centered on the
|
||||||
|
# workplane.
|
||||||
|
# 2b. Unlike some other functions like the hole(), circle() takes
|
||||||
|
# a radius and not a diameter.
|
||||||
|
# 3. The circle and rectangle are extruded together, creating a cylindrical
|
||||||
|
# plate with a rectangular hole in the center.
|
||||||
|
# 3a. circle() and rect() could be changed to any other shape to completely
|
||||||
|
# change the resulting plate and/or the hole in it.
|
||||||
|
result = cq.Workplane("front").circle(circle_radius) \
|
||||||
|
.rect(rectangle_width, rectangle_length) \
|
||||||
|
.extrude(thickness)
|
||||||
|
|
||||||
|
# Displays the result of this script
|
||||||
|
show_object(result)
|
45
examples/Ex005_Extruded_Lines_and_Arcs.py
Normal file
45
examples/Ex005_Extruded_Lines_and_Arcs.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import cadquery as cq
|
||||||
|
|
||||||
|
# These can be modified rather than hardcoding values for each dimension.
|
||||||
|
width = 2.0 # Overall width of the plate
|
||||||
|
thickness = 0.25 # Thickness of the plate
|
||||||
|
|
||||||
|
# Extrude a plate outline made of lines and an arc
|
||||||
|
# 1. Establishes a workplane that an object can be built on.
|
||||||
|
# 1a. Uses the named plane orientation "front" to define the workplane, meaning
|
||||||
|
# that the positive Z direction is "up", and the negative Z direction
|
||||||
|
# is "down".
|
||||||
|
# 2. Draws a line from the origin to an X position of the plate's width.
|
||||||
|
# 2a. The starting point of a 2D drawing like this will be at the center of the
|
||||||
|
# workplane (0, 0) unless the moveTo() function moves the starting point.
|
||||||
|
# 3. A line is drawn from the last position straight up in the Y direction
|
||||||
|
# 1.0 millimeters.
|
||||||
|
# 4. An arc is drawn from the last point, through point (1.0, 1.5) which is
|
||||||
|
# half-way back to the origin in the X direction and 0.5 mm above where
|
||||||
|
# the last line ended at. The arc then ends at (0.0, 1.0), which is 1.0 mm
|
||||||
|
# above (in the Y direction) where our first line started from.
|
||||||
|
# 5. An arc is drawn from the last point that ends on (-0.5, 1.0), the sag of
|
||||||
|
# the curve 0.2 determines that the curve is concave with the midpoint 0.1 mm
|
||||||
|
# from the arc baseline. If the sag was -0.2 the arc would be convex.
|
||||||
|
# This convention is valid when the profile is drawn counterclockwise.
|
||||||
|
# The reverse is true if the profile is drawn clockwise.
|
||||||
|
# Clockwise: +sag => convex, -sag => concave
|
||||||
|
# Counterclockwise: +sag => concave, -sag => convex
|
||||||
|
# 6. An arc is drawn from the last point that ends on (-0.7, -0.2), the arc is
|
||||||
|
# determined by the radius of -1.5 mm.
|
||||||
|
# Clockwise: +radius => convex, -radius => concave
|
||||||
|
# Counterclockwise: +radius => concave, -radius => convex
|
||||||
|
# 7. close() is called to automatically draw the last line for us and close
|
||||||
|
# the sketch so that it can be extruded.
|
||||||
|
# 7a. Without the close(), the 2D sketch will be left open and the extrude
|
||||||
|
# operation will provide unpredictable results.
|
||||||
|
# 8. The 2D sketch is extruded into a solid object of the specified thickness.
|
||||||
|
result = cq.Workplane("front").lineTo(width, 0) \
|
||||||
|
.lineTo(width, 1.0) \
|
||||||
|
.threePointArc((1.0, 1.5), (0.0, 1.0)) \
|
||||||
|
.sagittaArc((-0.5, 1.0), 0.2) \
|
||||||
|
.radiusArc((-0.7, -0.2), -1.5) \
|
||||||
|
.close().extrude(thickness)
|
||||||
|
|
||||||
|
# Displays the result of this script
|
||||||
|
show_object(result)
|
35
examples/Ex006_Moving_the_Current_Working_Point.py
Normal file
35
examples/Ex006_Moving_the_Current_Working_Point.py
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import cadquery as cq
|
||||||
|
|
||||||
|
# These can be modified rather than hardcoding values for each dimension.
|
||||||
|
circle_radius = 3.0 # The outside radius of the plate
|
||||||
|
thickness = 0.25 # The thickness of the plate
|
||||||
|
|
||||||
|
# Make a plate with two cutouts in it by moving the workplane center point
|
||||||
|
# 1. Establishes a workplane that an object can be built on.
|
||||||
|
# 1a. Uses the named plane orientation "front" to define the workplane, meaning
|
||||||
|
# that the positive Z direction is "up", and the negative Z direction
|
||||||
|
# is "down".
|
||||||
|
# 1b. The initial workplane center point is the center of the circle, at (0,0).
|
||||||
|
# 2. A circle is created at the center of the workplane
|
||||||
|
# 2a. Notice that circle() takes a radius and not a diameter
|
||||||
|
result = cq.Workplane("front").circle(circle_radius)
|
||||||
|
|
||||||
|
# 3. The work center is movide to (1.5, 0.0) by calling center().
|
||||||
|
# 3a. The new center is specified relative to the previous center,not
|
||||||
|
# relative to global coordinates.
|
||||||
|
# 4. A 0.5mm x 0.5mm 2D square is drawn inside the circle.
|
||||||
|
# 4a. The plate has not been extruded yet, only 2D geometry is being created.
|
||||||
|
result = result.center(1.5, 0.0).rect(0.5, 0.5)
|
||||||
|
|
||||||
|
# 5. The work center is moved again, this time to (-1.5, 1.5).
|
||||||
|
# 6. A 2D circle is created at that new center with a radius of 0.25mm.
|
||||||
|
result = result.center(-1.5, 1.5).circle(0.25)
|
||||||
|
|
||||||
|
# 7. All 2D geometry is extruded to the specified thickness of the plate.
|
||||||
|
# 7a. The small circle and the square are enclosed in the outer circle of the
|
||||||
|
# plate and so it is assumed that we want them to be cut out of the plate.
|
||||||
|
# A separate cut operation is not needed.
|
||||||
|
result = result.extrude(thickness)
|
||||||
|
|
||||||
|
# Displays the result of this script
|
||||||
|
show_object(result)
|
32
examples/Ex007_Using_Point_Lists.py
Normal file
32
examples/Ex007_Using_Point_Lists.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import cadquery as cq
|
||||||
|
|
||||||
|
# These can be modified rather than hardcoding values for each dimension.
|
||||||
|
plate_radius = 2.0 # The radius of the plate that will be extruded
|
||||||
|
hole_pattern_radius = 0.25 # Radius of circle where the holes will be placed
|
||||||
|
thickness = 0.125 # The thickness of the plate that will be extruded
|
||||||
|
|
||||||
|
# Make a plate with 4 holes in it at various points in a polar arrangement from
|
||||||
|
# the center of the workplane.
|
||||||
|
# 1. Establishes a workplane that an object can be built on.
|
||||||
|
# 1a. Uses the named plane orientation "front" to define the workplane, meaning
|
||||||
|
# that the positive Z direction is "up", and the negative Z direction
|
||||||
|
# is "down".
|
||||||
|
# 2. A 2D circle is drawn that will become though outer profile of the plate.
|
||||||
|
r = cq.Workplane("front").circle(plate_radius)
|
||||||
|
|
||||||
|
# 3. Push 4 points on the stack that will be used as the center points of the
|
||||||
|
# holes.
|
||||||
|
r = r.pushPoints([(1.5, 0), (0, 1.5), (-1.5, 0), (0, -1.5)])
|
||||||
|
|
||||||
|
# 4. This circle() call will operate on all four points, putting a circle at
|
||||||
|
# each one.
|
||||||
|
r = r.circle(hole_pattern_radius)
|
||||||
|
|
||||||
|
# 5. All 2D geometry is extruded to the specified thickness of the plate.
|
||||||
|
# 5a. The small hole circles are enclosed in the outer circle of the plate and
|
||||||
|
# so it is assumed that we want them to be cut out of the plate. A
|
||||||
|
# separate cut operation is not needed.
|
||||||
|
result = r.extrude(thickness)
|
||||||
|
|
||||||
|
# Displays the result of this script
|
||||||
|
show_object(result)
|
39
examples/Ex008_Polygon_Creation.py
Normal file
39
examples/Ex008_Polygon_Creation.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import cadquery as cq
|
||||||
|
|
||||||
|
# These can be modified rather than hardcoding values for each dimension.
|
||||||
|
width = 3.0 # The width of the plate
|
||||||
|
height = 4.0 # The height of the plate
|
||||||
|
thickness = 0.25 # The thickness of the plate
|
||||||
|
polygon_sides = 6 # The number of sides that the polygonal holes should have
|
||||||
|
polygon_dia = 1.0 # The diameter of the circle enclosing the polygon points
|
||||||
|
|
||||||
|
# Create a plate with two polygons cut through it
|
||||||
|
# 1. Establishes a workplane that an object can be built on.
|
||||||
|
# 1a. Uses the named plane orientation "front" to define the workplane, meaning
|
||||||
|
# that the positive Z direction is "up", and the negative Z direction
|
||||||
|
# is "down".
|
||||||
|
# 2. A 3D box is created in one box() operation to represent the plate.
|
||||||
|
# 2a. The box is centered around the origin, which creates a result that may
|
||||||
|
# be unituitive when the polygon cuts are made.
|
||||||
|
# 3. 2 points are pushed onto the stack and will be used as centers for the
|
||||||
|
# polygonal holes.
|
||||||
|
# 4. The two polygons are created, on for each point, with one call to
|
||||||
|
# polygon() using the number of sides and the circle that bounds the
|
||||||
|
# polygon.
|
||||||
|
# 5. The polygons are cut thru all objects that are in the line of extrusion.
|
||||||
|
# 5a. A face was not selected, and so the polygons are created on the
|
||||||
|
# workplane. Since the box was centered around the origin, the polygons end
|
||||||
|
# up being in the center of the box. This makes them cut from the center to
|
||||||
|
# the outside along the normal (positive direction).
|
||||||
|
# 6. The polygons are cut through all objects, starting at the center of the
|
||||||
|
# box/plate and going "downward" (opposite of normal) direction. Functions
|
||||||
|
# like cutBlind() assume a positive cut direction, but cutThruAll() assumes
|
||||||
|
# instead that the cut is made from a max direction and cuts downward from
|
||||||
|
# that max through all objects.
|
||||||
|
result = cq.Workplane("front").box(width, height, thickness) \
|
||||||
|
.pushPoints([(0, 0.75), (0, -0.75)]) \
|
||||||
|
.polygon(polygon_sides, polygon_dia) \
|
||||||
|
.cutThruAll()
|
||||||
|
|
||||||
|
# Displays the result of this script
|
||||||
|
show_object(result)
|
39
examples/Ex009_Polylines.py
Normal file
39
examples/Ex009_Polylines.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import cadquery as cq
|
||||||
|
|
||||||
|
# These can be modified rather than hardcoding values for each dimension.
|
||||||
|
# Define up our Length, Height, Width, and thickness of the beam
|
||||||
|
(L, H, W, t) = (100.0, 20.0, 20.0, 1.0)
|
||||||
|
|
||||||
|
# Define the points that the polyline will be drawn to/thru
|
||||||
|
pts = [
|
||||||
|
(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.
|
||||||
|
# 1. Establishes a workplane that an object can be built on.
|
||||||
|
# 1a. Uses the named plane orientation "front" to define the workplane, meaning
|
||||||
|
# that the positive Z direction is "up", and the negative Z direction
|
||||||
|
# is "down".
|
||||||
|
# 2. moveTo() is used to move the first point from the origin (0, 0) to
|
||||||
|
# (0, 10.0), with 10.0 being half the height (H/2.0). If this is not done
|
||||||
|
# the first line will start from the origin, creating an extra segment that
|
||||||
|
# will cause the extrude to have an invalid shape.
|
||||||
|
# 3. The polyline function takes a list of points and generates the lines
|
||||||
|
# through all the points at once.
|
||||||
|
# 3. Only half of the I-beam profile has been drawn so far. That half is
|
||||||
|
# mirrored around the Y-axis to create the complete I-beam profile.
|
||||||
|
# 4. The I-beam profile is extruded to the final length of the beam.
|
||||||
|
result = cq.Workplane("front").moveTo(0, H/2.0) \
|
||||||
|
.polyline(pts) \
|
||||||
|
.mirrorY() \
|
||||||
|
.extrude(L)
|
||||||
|
|
||||||
|
# Displays the result of this script
|
||||||
|
show_object(result)
|
27
examples/Ex010_Defining_an_Edge_with_a_Spline.py
Normal file
27
examples/Ex010_Defining_an_Edge_with_a_Spline.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import cadquery as cq
|
||||||
|
|
||||||
|
# 1. Establishes a workplane to create the spline on to extrude.
|
||||||
|
# 1a. Uses the X and Y origins to define the workplane, meaning that the
|
||||||
|
# positive Z direction is "up", and the negative Z direction is "down".
|
||||||
|
s = cq.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)
|
||||||
|
]
|
||||||
|
|
||||||
|
# 2. Generate our plate with the spline feature and make sure it is a
|
||||||
|
# closed entity
|
||||||
|
r = s.lineTo(3.0, 0).lineTo(3.0, 1.0).spline(sPnts).close()
|
||||||
|
|
||||||
|
# 3. Extrude to turn the wire into a plate
|
||||||
|
result = r.extrude(0.5)
|
||||||
|
|
||||||
|
# Displays the result of this script
|
||||||
|
show_object(result)
|
20
examples/Ex011_Mirroring_Symmetric_Geometry.py
Normal file
20
examples/Ex011_Mirroring_Symmetric_Geometry.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import cadquery as cq
|
||||||
|
|
||||||
|
# 1. Establishes a workplane that an object can be built on.
|
||||||
|
# 1a. Uses the named plane orientation "front" to define the workplane, meaning
|
||||||
|
# that the positive Z direction is "up", and the negative Z direction
|
||||||
|
# is "down".
|
||||||
|
# 2. A horizontal line is drawn on the workplane with the hLine function.
|
||||||
|
# 2a. 1.0 is the distance, not coordinate. hLineTo allows using xCoordinate
|
||||||
|
# not distance.
|
||||||
|
r = cq.Workplane("front").hLine(1.0)
|
||||||
|
|
||||||
|
# 3. Draw a series of vertical and horizontal lines with the vLine and hLine
|
||||||
|
# functions.
|
||||||
|
r = r.vLine(0.5).hLine(-0.25).vLine(-0.25).hLineTo(0.0)
|
||||||
|
|
||||||
|
# 4. Mirror the geometry about the Y axis and extrude it into a 3D object.
|
||||||
|
result = r.mirrorY().extrude(0.25)
|
||||||
|
|
||||||
|
# Displays the result of this script
|
||||||
|
show_object(result)
|
16
examples/Ex012_Creating_Workplanes_on_Faces.py
Normal file
16
examples/Ex012_Creating_Workplanes_on_Faces.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import cadquery as cq
|
||||||
|
|
||||||
|
# 1. Establishes a workplane that an object can be built on.
|
||||||
|
# 1a. Uses the named plane orientation "front" to define the workplane, meaning
|
||||||
|
# that the positive Z direction is "up", and the negative Z direction
|
||||||
|
# is "down".
|
||||||
|
# 2. Creates a 3D box that will have a hole placed in it later.
|
||||||
|
result = cq.Workplane("front").box(2, 3, 0.5)
|
||||||
|
|
||||||
|
# 3. Find the top-most face with the >Z max selector.
|
||||||
|
# 3a. Establish a new workplane to build geometry on.
|
||||||
|
# 3b. Create a hole down into the box.
|
||||||
|
result = result.faces(">Z").workplane().hole(0.5)
|
||||||
|
|
||||||
|
# Displays the result of this script
|
||||||
|
show_object(result)
|
21
examples/Ex013_Locating_a_Workplane_on_a_Vertex.py
Normal file
21
examples/Ex013_Locating_a_Workplane_on_a_Vertex.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import cadquery as cq
|
||||||
|
|
||||||
|
# 1. Establishes a workplane that an object can be built on.
|
||||||
|
# 1a. Uses the named plane orientation "front" to define the workplane, meaning
|
||||||
|
# that the positive Z direction is "up", and the negative Z direction
|
||||||
|
# is "down".
|
||||||
|
# 2. Creates a 3D box that will have a hole placed in it later.
|
||||||
|
result = cq.Workplane("front").box(3, 2, 0.5)
|
||||||
|
|
||||||
|
# 3. Select the lower left vertex and make a workplane.
|
||||||
|
# 3a. The top-most Z face is selected using the >Z selector.
|
||||||
|
# 3b. The lower-left vertex of the faces is selected with the <XY selector.
|
||||||
|
# 3c. A new workplane is created on the vertex to build future geometry on.
|
||||||
|
result = result.faces(">Z").vertices("<XY").workplane()
|
||||||
|
|
||||||
|
# 4. A circle is drawn with the selected vertex as its center.
|
||||||
|
# 4a. The circle is cut down through the box to cut the corner out.
|
||||||
|
result = result.circle(1.0).cutThruAll()
|
||||||
|
|
||||||
|
# Displays the result of this script
|
||||||
|
show_object(result)
|
20
examples/Ex014_Offset_Workplanes.py
Normal file
20
examples/Ex014_Offset_Workplanes.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import cadquery as cq
|
||||||
|
|
||||||
|
# 1. Establishes a workplane that an object can be built on.
|
||||||
|
# 1a. Uses the named plane orientation "front" to define the workplane, meaning
|
||||||
|
# that the positive Z direction is "up", and the negative Z direction
|
||||||
|
# is "down".
|
||||||
|
# 2. Creates a 3D box that will have geometry based off it later.
|
||||||
|
result = cq.Workplane("front").box(3, 2, 0.5)
|
||||||
|
|
||||||
|
# 3. The lowest face in the X direction is selected with the <X selector.
|
||||||
|
# 4. A new wokrplane is created
|
||||||
|
# 4a.The workplane is offset from the object surface so that it is not touching
|
||||||
|
# the original box.
|
||||||
|
result = result.faces("<X").workplane(offset=0.75)
|
||||||
|
|
||||||
|
# 5. Creates a thin disc on the offset workplane that is floating near the box.
|
||||||
|
result = result.circle(1.0).extrude(0.5)
|
||||||
|
|
||||||
|
# Displays the result of this script
|
||||||
|
show_object(result)
|
22
examples/Ex015_Rotated_Workplanes.py
Normal file
22
examples/Ex015_Rotated_Workplanes.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import cadquery as cq
|
||||||
|
|
||||||
|
# 1. Establishes a workplane that an object can be built on.
|
||||||
|
# 1a. Uses the named plane orientation "front" to define the workplane, meaning
|
||||||
|
# that the positive Z direction is "up", and the negative Z direction
|
||||||
|
# is "down".
|
||||||
|
# 2. Creates a plain box to base future geometry on with the box() function.
|
||||||
|
# 3. Selects the top-most Z face of the box.
|
||||||
|
# 4. Creates a new workplane and then moves and rotates it with the
|
||||||
|
# transformed function.
|
||||||
|
# 5. Creates a for-construction rectangle that only exists to use for placing
|
||||||
|
# other geometry.
|
||||||
|
# 6. Selects the vertices of the for-construction rectangle.
|
||||||
|
# 7. Places holes at the center of each selected vertex.
|
||||||
|
# 7a. Since the workplane is rotated, this results in angled holes in the face.
|
||||||
|
result = cq.Workplane("front").box(4.0, 4.0, 0.25).faces(">Z") \
|
||||||
|
.workplane() \
|
||||||
|
.transformed(offset=(0, -1.5, 1.0), rotate=(60, 0, 0)) \
|
||||||
|
.rect(1.5, 1.5, forConstruction=True).vertices().hole(0.25)
|
||||||
|
|
||||||
|
# Displays the result of this script
|
||||||
|
show_object(result)
|
21
examples/Ex016_Using_Construction_Geometry.py
Normal file
21
examples/Ex016_Using_Construction_Geometry.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import cadquery as cq
|
||||||
|
|
||||||
|
# Create a block with holes in each corner of a rectangle on that workplane.
|
||||||
|
# 1. Establishes a workplane that an object can be built on.
|
||||||
|
# 1a. Uses the named plane orientation "front" to define the workplane, meaning
|
||||||
|
# that the positive Z direction is "up", and the negative Z direction
|
||||||
|
# is "down".
|
||||||
|
# 2. Creates a plain box to base future geometry on with the box() function.
|
||||||
|
# 3. Selects the top-most Z face of the box.
|
||||||
|
# 4. Creates a new workplane to build new geometry on.
|
||||||
|
# 5. Creates a for-construction rectangle that only exists to use for placing
|
||||||
|
# other geometry.
|
||||||
|
# 6. Selects the vertices of the for-construction rectangle.
|
||||||
|
# 7. Places holes at the center of each selected vertex.
|
||||||
|
result = cq.Workplane("front").box(2, 2, 0.5)\
|
||||||
|
.faces(">Z").workplane() \
|
||||||
|
.rect(1.5, 1.5, forConstruction=True).vertices() \
|
||||||
|
.hole(0.125)
|
||||||
|
|
||||||
|
# Displays the result of this script
|
||||||
|
show_object(result)
|
14
examples/Ex017_Shelling_to_Create_Thin_Features.py
Normal file
14
examples/Ex017_Shelling_to_Create_Thin_Features.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import cadquery as cq
|
||||||
|
|
||||||
|
# Create a hollow box that's open on both ends with a thin wall.
|
||||||
|
# 1. Establishes a workplane that an object can be built on.
|
||||||
|
# 1a. Uses the named plane orientation "front" to define the workplane, meaning
|
||||||
|
# that the positive Z direction is "up", and the negative Z direction
|
||||||
|
# is "down".
|
||||||
|
# 2. Creates a plain box to base future geometry on with the box() function.
|
||||||
|
# 3. Selects faces with normal in +z direction.
|
||||||
|
# 4. Create a shell by cutting out the top-most Z face.
|
||||||
|
result = cq.Workplane("front").box(2, 2, 2).faces("+Z").shell(0.05)
|
||||||
|
|
||||||
|
# Displays the result of this script
|
||||||
|
show_object(result)
|
20
examples/Ex018_Making_Lofts.py
Normal file
20
examples/Ex018_Making_Lofts.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import cadquery as cq
|
||||||
|
|
||||||
|
# Create a lofted section between a rectangle and a circular section.
|
||||||
|
# 1. Establishes a workplane that an object can be built on.
|
||||||
|
# 1a. Uses the named plane orientation "front" to define the workplane, meaning
|
||||||
|
# that the positive Z direction is "up", and the negative Z direction
|
||||||
|
# is "down".
|
||||||
|
# 2. Creates a plain box to base future geometry on with the box() function.
|
||||||
|
# 3. Selects the top-most Z face of the box.
|
||||||
|
# 4. Draws a 2D circle at the center of the the top-most face of the box.
|
||||||
|
# 5. Creates a workplane 3 mm above the face the circle was drawn on.
|
||||||
|
# 6. Draws a 2D circle on the new, offset workplane.
|
||||||
|
# 7. Creates a loft between the circle and the rectangle.
|
||||||
|
result = cq.Workplane("front").box(4.0, 4.0, 0.25).faces(">Z") \
|
||||||
|
.circle(1.5).workplane(offset=3.0) \
|
||||||
|
.rect(0.75, 0.5) \
|
||||||
|
.loft(combine=True)
|
||||||
|
|
||||||
|
# Displays the result of this script
|
||||||
|
show_object(result)
|
19
examples/Ex019_Counter_Sunk_Holes.py
Normal file
19
examples/Ex019_Counter_Sunk_Holes.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import cadquery as cq
|
||||||
|
|
||||||
|
# Create a plate with 4 counter-sunk holes in it.
|
||||||
|
# 1. Establishes a workplane using an XY object instead of a named plane.
|
||||||
|
# 2. Creates a plain box to base future geometry on with the box() function.
|
||||||
|
# 3. Selects the top-most face of the box and established a workplane on that.
|
||||||
|
# 4. Draws a for-construction rectangle on the workplane which only exists for
|
||||||
|
# placing other geometry.
|
||||||
|
# 5. Selects the corner vertices of the rectangle and places a counter-sink
|
||||||
|
# hole, using each vertex as the center of a hole using the cskHole()
|
||||||
|
# function.
|
||||||
|
# 5a. When the depth of the counter-sink hole is set to None, the hole will be
|
||||||
|
# cut through.
|
||||||
|
result = cq.Workplane(cq.Plane.XY()).box(4, 2, 0.5).faces(">Z") \
|
||||||
|
.workplane().rect(3.5, 1.5, forConstruction=True) \
|
||||||
|
.vertices().cskHole(0.125, 0.25, 82.0, depth=None)
|
||||||
|
|
||||||
|
# Displays the result of this script
|
||||||
|
show_object(result)
|
13
examples/Ex020_Rounding_Corners_with_Fillets.py
Normal file
13
examples/Ex020_Rounding_Corners_with_Fillets.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import cadquery as cq
|
||||||
|
|
||||||
|
# Create a plate with 4 rounded corners in the Z-axis.
|
||||||
|
# 1. Establishes a workplane that an object can be built on.
|
||||||
|
# 1a. Uses the X and Y origins to define the workplane, meaning that the
|
||||||
|
# positive Z direction is "up", and the negative Z direction is "down".
|
||||||
|
# 2. Creates a plain box to base future geometry on with the box() function.
|
||||||
|
# 3. Selects all edges that are parallel to the Z axis.
|
||||||
|
# 4. Creates fillets on each of the selected edges with the specified radius.
|
||||||
|
result = cq.Workplane("XY").box(3, 3, 0.5).edges("|Z").fillet(0.125)
|
||||||
|
|
||||||
|
# Displays the result of this script
|
||||||
|
show_object(result)
|
25
examples/Ex021_Splitting_an_Object.py
Normal file
25
examples/Ex021_Splitting_an_Object.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import cadquery as cq
|
||||||
|
|
||||||
|
# Create a simple block with a hole through it that we can split.
|
||||||
|
# 1. Establishes a workplane that an object can be built on.
|
||||||
|
# 1a. Uses the X and Y origins to define the workplane, meaning that the
|
||||||
|
# positive Z direction is "up", and the negative Z direction is "down".
|
||||||
|
# 2. Creates a plain box to base future geometry on with the box() function.
|
||||||
|
# 3. Selects the top-most face of the box and establishes a workplane on it
|
||||||
|
# that new geometry can be built on.
|
||||||
|
# 4. Draws a 2D circle on the new workplane and then uses it to cut a hole
|
||||||
|
# all the way through the box.
|
||||||
|
c = cq.Workplane("XY").box(1, 1, 1).faces(">Z").workplane() \
|
||||||
|
.circle(0.25).cutThruAll()
|
||||||
|
|
||||||
|
# 5. Selects the face furthest away from the origin in the +Y axis direction.
|
||||||
|
# 6. Creates an offset workplane that is set in the center of the object.
|
||||||
|
# 6a. One possible improvement to this script would be to make the dimensions
|
||||||
|
# of the box variables, and then divide the Y-axis dimension by 2.0 and
|
||||||
|
# use that to create the offset workplane.
|
||||||
|
# 7. Uses the embedded workplane to split the object, keeping only the "top"
|
||||||
|
# portion.
|
||||||
|
result = c.faces(">Y").workplane(-0.5).split(keepTop=True)
|
||||||
|
|
||||||
|
# Displays the result of this script
|
||||||
|
show_object(result)
|
21
examples/Ex022_Revolution.py
Normal file
21
examples/Ex022_Revolution.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import cadquery as cq
|
||||||
|
|
||||||
|
# The dimensions of the model. These can be modified rather than changing the
|
||||||
|
# shape's code directly.
|
||||||
|
rectangle_width = 10.0
|
||||||
|
rectangle_length = 10.0
|
||||||
|
angle_degrees = 360.0
|
||||||
|
|
||||||
|
# Revolve a cylinder from a rectangle
|
||||||
|
# Switch comments around in this section to try the revolve operation with different parameters
|
||||||
|
result = cq.Workplane("XY").rect(rectangle_width, rectangle_length, False).revolve()
|
||||||
|
#result = cadquery.Workplane("XY").rect(rectangle_width, rectangle_length, False).revolve(angle_degrees)
|
||||||
|
#result = cadquery.Workplane("XY").rect(rectangle_width, rectangle_length).revolve(angle_degrees,(-5,-5))
|
||||||
|
#result = cadquery.Workplane("XY").rect(rectangle_width, rectangle_length).revolve(angle_degrees,(-5, -5),(-5, 5))
|
||||||
|
#result = cadquery.Workplane("XY").rect(rectangle_width, rectangle_length).revolve(angle_degrees,(-5,-5),(-5,5), False)
|
||||||
|
|
||||||
|
# Revolve a donut with square walls
|
||||||
|
#result = cadquery.Workplane("XY").rect(rectangle_width, rectangle_length, True).revolve(angle_degrees, (20, 0), (20, 10))
|
||||||
|
|
||||||
|
# Displays the result of this script
|
||||||
|
show_object(result)
|
40
examples/Ex023_Sweep.py
Normal file
40
examples/Ex023_Sweep.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import cadquery as cq
|
||||||
|
|
||||||
|
# Points we will use to create spline and polyline paths to sweep over
|
||||||
|
pts = [
|
||||||
|
(0, 1),
|
||||||
|
(1, 2),
|
||||||
|
(2, 4)
|
||||||
|
]
|
||||||
|
|
||||||
|
# Spline path generated from our list of points (tuples)
|
||||||
|
path = cq.Workplane("XZ").spline(pts)
|
||||||
|
|
||||||
|
# Sweep a circle with a diameter of 1.0 units along the spline path we just created
|
||||||
|
defaultSweep = cq.Workplane("XY").circle(1.0).sweep(path)
|
||||||
|
|
||||||
|
# Sweep defaults to making a solid and not generating a Frenet solid. Setting Frenet to True helps prevent creep in
|
||||||
|
# the orientation of the profile as it is being swept
|
||||||
|
frenetShell = cq.Workplane("XY").circle(1.0).sweep(path, makeSolid=True, isFrenet=True)
|
||||||
|
|
||||||
|
# We can sweep shapes other than circles
|
||||||
|
defaultRect = cq.Workplane("XY").rect(1.0, 1.0).sweep(path)
|
||||||
|
|
||||||
|
# Switch to a polyline path, but have it use the same points as the spline
|
||||||
|
path = cq.Workplane("XZ").polyline(pts)
|
||||||
|
|
||||||
|
# Using a polyline path leads to the resulting solid having segments rather than a single swept outer face
|
||||||
|
plineSweep = cq.Workplane("XY").circle(1.0).sweep(path)
|
||||||
|
|
||||||
|
# Switch to an arc for the path
|
||||||
|
path = cq.Workplane("XZ").threePointArc((1.0, 1.5), (0.0, 1.0))
|
||||||
|
|
||||||
|
# Use a smaller circle section so that the resulting solid looks a little nicer
|
||||||
|
arcSweep = cq.Workplane("XY").circle(0.5).sweep(path)
|
||||||
|
|
||||||
|
# Translate the resulting solids so that they do not overlap and display them left to right
|
||||||
|
show_object(defaultSweep)
|
||||||
|
show_object(frenetShell.translate((5, 0, 0)))
|
||||||
|
show_object(defaultRect.translate((10, 0, 0)))
|
||||||
|
show_object(plineSweep.translate((15, 0, 0)))
|
||||||
|
show_object(arcSweep.translate((20, 0, 0)))
|
47
examples/Ex024_Sweep_Along_List_Of_Wires.py
Normal file
47
examples/Ex024_Sweep_Along_List_Of_Wires.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import cadquery as cq
|
||||||
|
|
||||||
|
# X axis line length 20.0
|
||||||
|
path = cq.Workplane("XZ").moveTo(-10, 0).lineTo(10, 0)
|
||||||
|
|
||||||
|
# Sweep a circle from diameter 2.0 to diameter 1.0 to diameter 2.0 along X axis length 10.0 + 10.0
|
||||||
|
defaultSweep = cq.Workplane("YZ").workplane(offset=-10.0).circle(2.0). \
|
||||||
|
workplane(offset=10.0).circle(1.0). \
|
||||||
|
workplane(offset=10.0).circle(2.0).sweep(path, sweepAlongWires=True)
|
||||||
|
|
||||||
|
# We can sweep thrue different shapes
|
||||||
|
recttocircleSweep = cq.Workplane("YZ").workplane(offset=-10.0).rect(2.0, 2.0). \
|
||||||
|
workplane(offset=8.0).circle(1.0).workplane(offset=4.0).circle(1.0). \
|
||||||
|
workplane(offset=8.0).rect(2.0, 2.0).sweep(path, sweepAlongWires=True)
|
||||||
|
|
||||||
|
circletorectSweep = cq.Workplane("YZ").workplane(offset=-10.0).circle(1.0). \
|
||||||
|
workplane(offset=7.0).rect(2.0, 2.0).workplane(offset=6.0).rect(2.0, 2.0). \
|
||||||
|
workplane(offset=7.0).circle(1.0).sweep(path, sweepAlongWires=True)
|
||||||
|
|
||||||
|
|
||||||
|
# Placement of the Shape is important otherwise could produce unexpected shape
|
||||||
|
specialSweep = cq.Workplane("YZ").circle(1.0).workplane(offset=10.0).rect(2.0, 2.0). \
|
||||||
|
sweep(path, sweepAlongWires=True)
|
||||||
|
|
||||||
|
# Switch to an arc for the path : line l=5.0 then half circle r=4.0 then line l=5.0
|
||||||
|
path = cq.Workplane("XZ").moveTo(-5, 4).lineTo(0, 4). \
|
||||||
|
threePointArc((4, 0), (0, -4)).lineTo(-5, -4)
|
||||||
|
|
||||||
|
# Placement of different shapes should follow the path
|
||||||
|
# cylinder r=1.5 along first line
|
||||||
|
# then sweep allong arc from r=1.5 to r=1.0
|
||||||
|
# then cylinder r=1.0 along last line
|
||||||
|
arcSweep = cq.Workplane("YZ").workplane(offset=-5).moveTo(0, 4).circle(1.5). \
|
||||||
|
workplane(offset=5).circle(1.5). \
|
||||||
|
moveTo(0, -8).circle(1.0). \
|
||||||
|
workplane(offset=-5).circle(1.0). \
|
||||||
|
sweep(path, sweepAlongWires=True)
|
||||||
|
|
||||||
|
|
||||||
|
# Translate the resulting solids so that they do not overlap and display them left to right
|
||||||
|
show_object(defaultSweep)
|
||||||
|
show_object(circletorectSweep.translate((0, 5, 0)))
|
||||||
|
show_object(recttocircleSweep.translate((0, 10, 0)))
|
||||||
|
show_object(specialSweep.translate((0, 15, 0)))
|
||||||
|
show_object(arcSweep.translate((0, -5, 0)))
|
||||||
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
|||||||
#File: Ex001_Simple_Block.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 Ex001_Simple_Block
|
|
||||||
|
|
||||||
#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 can also tie these blocks of code to macros, buttons, and keybindings in FreeCAD for quicker access.
|
|
||||||
#You can get a more in-depth explanation of this example at http://parametricparts.com/docs/quickstart.html
|
|
||||||
|
|
||||||
import cadquery
|
|
||||||
import Part
|
|
||||||
|
|
||||||
#The dimensions of the box. These can be modified rather than changing the box's code directly.
|
|
||||||
length = 80.0
|
|
||||||
height = 60.0
|
|
||||||
thickness = 10.0
|
|
||||||
|
|
||||||
#Create a 3D box based on the dimension variables above
|
|
||||||
result = cadquery.Workplane("XY").box(length, height, thickness)
|
|
||||||
|
|
||||||
#Boiler plate code to render our solid in FreeCAD's GUI
|
|
||||||
Part.show(result.toFreecad())
|
|
@ -1,33 +0,0 @@
|
|||||||
#File: Ex002_Block_With_Bored_Center_Hole.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 Ex002_Block_With_Bored_Center_Hole
|
|
||||||
|
|
||||||
#If you need to reload the part after making a change, you can use the following lines within the FreeCAD console.
|
|
||||||
#reload(Ex002_Block_With_Bored_Center_Hole)
|
|
||||||
|
|
||||||
#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
|
|
||||||
|
|
||||||
import cadquery
|
|
||||||
import Part
|
|
||||||
|
|
||||||
#The dimensions of the box. These can be modified rather than changing the box's code directly.
|
|
||||||
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(center_hole_dia)
|
|
||||||
|
|
||||||
#Boiler plate code to render our solid in FreeCAD's GUI
|
|
||||||
Part.show(result.toFreecad())
|
|
@ -1,40 +0,0 @@
|
|||||||
#File: Ex003_Pillow_Block_With_Counterbored_Holes.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 Ex003_Pillow_Block_With_Counterbored_Holes
|
|
||||||
|
|
||||||
#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 can also tie these blocks of code to macros, buttons, and keybindings in FreeCAD for quicker access.
|
|
||||||
#You can get a more in-depth explanation of this example at http://parametricparts.com/docs/quickstart.html
|
|
||||||
|
|
||||||
import cadquery
|
|
||||||
import Part
|
|
||||||
|
|
||||||
#The dimensions of the box. These can be modified rather than changing the box's code directly.
|
|
||||||
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 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)
|
|
||||||
|
|
||||||
#Boiler plate code to render our solid in FreeCAD's GUI
|
|
||||||
Part.show(result.toFreecad())
|
|
@ -1,34 +0,0 @@
|
|||||||
#File: Ex004_Extruded_Cylindrical_Plate.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 Ex004_Extruded_Cylindrical_Plate
|
|
||||||
|
|
||||||
#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 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.
|
|
||||||
circle_radius = 50.0
|
|
||||||
rectangle_width = 13.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, rectangle_length).extrude(thickness)
|
|
||||||
|
|
||||||
#Boiler plate code to render our solid in FreeCAD's GUI
|
|
||||||
Part.show(result.toFreecad())
|
|
@ -1,33 +0,0 @@
|
|||||||
#File: Ex005_Extruded_Lines_and_Arcs.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 Ex005_Extruded_Lines_and_Arcs
|
|
||||||
|
|
||||||
#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 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 = 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)
|
|
||||||
|
|
||||||
#Boiler plate code to render our solid in FreeCAD's GUI
|
|
||||||
Part.show(result.toFreecad())
|
|
@ -1,38 +0,0 @@
|
|||||||
#File: Ex006_Moving_the_Current_Working_Point.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 Ex006_Moving_the_Current_Working_Point
|
|
||||||
|
|
||||||
#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 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.
|
|
||||||
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 = 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)
|
|
||||||
|
|
||||||
#Boiler plate code to render our solid in FreeCAD's GUI
|
|
||||||
Part.show(result.toFreecad())
|
|
@ -1,36 +0,0 @@
|
|||||||
#File: Ex007_Using_Point_Lists.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 Ex007_Using_Point_Lists
|
|
||||||
|
|
||||||
#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 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.
|
|
||||||
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(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)
|
|
||||||
|
|
||||||
#Boiler plate code to render our solid in FreeCAD's GUI
|
|
||||||
Part.show(result.toFreecad())
|
|
@ -1,36 +0,0 @@
|
|||||||
#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()
|
|
||||||
|
|
||||||
#Boiler plate code to render our solid in FreeCAD's GUI
|
|
||||||
Part.show(result.toFreecad())
|
|
@ -1,44 +0,0 @@
|
|||||||
#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)
|
|
||||||
|
|
||||||
#Boiler plate code to render our solid in FreeCAD's GUI
|
|
||||||
Part.show(result.toFreecad())
|
|
@ -1,45 +0,0 @@
|
|||||||
#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)
|
|
||||||
|
|
||||||
#Boiler plate code to render our solid in FreeCAD's GUI
|
|
||||||
Part.show(result.toFreecad())
|
|
@ -1,34 +0,0 @@
|
|||||||
#File: Ex011_Mirroring_Symmetric_Geometry.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 Ex011_Mirroring_Symmetric_Geometry
|
|
||||||
|
|
||||||
#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 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
|
|
||||||
|
|
||||||
#1.0 is the distance, not coordinate
|
|
||||||
r = cadquery.Workplane("front").hLine(1.0)
|
|
||||||
|
|
||||||
#hLineTo allows using xCoordinate not distance
|
|
||||||
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)
|
|
||||||
|
|
||||||
#Boiler plate code to render our solid in FreeCAD's GUI
|
|
||||||
Part.show(result.toFreecad())
|
|
@ -1,31 +0,0 @@
|
|||||||
#File: Ex012_Creating_Workplanes_on_Faces.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 Ex012_Creating_Workplanes_on_Faces
|
|
||||||
|
|
||||||
#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 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
|
|
||||||
|
|
||||||
#Make a basic prism
|
|
||||||
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)
|
|
||||||
|
|
||||||
#Boiler plate code to render our solid in FreeCAD's GUI
|
|
||||||
Part.show(result.toFreecad())
|
|
@ -1,34 +0,0 @@
|
|||||||
#File: Ex013_Locating_a_Workplane_on_a_Vertex.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 Ex013_Locating_a_Workplane_on_a_Vertex
|
|
||||||
|
|
||||||
#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 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
|
|
||||||
|
|
||||||
#Make a basic prism
|
|
||||||
result = cadquery.Workplane("front").box(3, 2, 0.5)
|
|
||||||
|
|
||||||
#Select the lower left vertex and make a workplane
|
|
||||||
result = result.faces(">Z").vertices("<XY").workplane()
|
|
||||||
|
|
||||||
#Cut the corner out
|
|
||||||
result = result.circle(1.0).cutThruAll()
|
|
||||||
|
|
||||||
#Boiler plate code to render our solid in FreeCAD's GUI
|
|
||||||
Part.show(result.toFreecad())
|
|
@ -1,34 +0,0 @@
|
|||||||
#File: Ex014_Offset_Workplanes.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 Ex014_Offset_Workplanes
|
|
||||||
|
|
||||||
#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 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
|
|
||||||
|
|
||||||
#Make a basic prism
|
|
||||||
result = cadquery.Workplane("front").box(3, 2, 0.5)
|
|
||||||
|
|
||||||
#Workplane is offset from the object surface
|
|
||||||
result = result.faces("<X").workplane(offset=0.75)
|
|
||||||
|
|
||||||
#Create a disc
|
|
||||||
result = result.circle(1.0).extrude(0.5)
|
|
||||||
|
|
||||||
#Boiler plate code to render our solid in FreeCAD's GUI
|
|
||||||
Part.show(result.toFreecad())
|
|
@ -1,32 +0,0 @@
|
|||||||
#File: Ex015_Rotated_Workplanes.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 Ex015_Rotated_Workplanes
|
|
||||||
|
|
||||||
#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 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
|
|
||||||
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
|
|
||||||
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)
|
|
||||||
|
|
||||||
#Boiler plate code to render our solid in FreeCAD's GUI
|
|
||||||
Part.show(result.toFreecad())
|
|
@ -1,29 +0,0 @@
|
|||||||
#File: Ex016_Using_Construction_Geometry.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 Ex016_Using_Construction_Geometry
|
|
||||||
|
|
||||||
#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 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
|
|
||||||
|
|
||||||
#Create a block with holes in each corner of a rectangle on that workplane
|
|
||||||
result = cadquery.Workplane("front").box(2, 2, 0.5).faces(">Z").workplane() \
|
|
||||||
.rect(1.5, 1.5, forConstruction=True).vertices().hole(0.125)
|
|
||||||
|
|
||||||
#Boiler plate code to render our solid in FreeCAD's GUI
|
|
||||||
Part.show(result.toFreecad())
|
|
@ -1,28 +0,0 @@
|
|||||||
#File: Ex017_Shelling_to_Create_Thin_Features.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 Ex017_Shelling_to_Create_Thin_Features
|
|
||||||
|
|
||||||
#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 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
|
|
||||||
|
|
||||||
#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)
|
|
||||||
|
|
||||||
#Boiler plate code to render our solid in FreeCAD's GUI
|
|
||||||
Part.show(result.toFreecad())
|
|
@ -1,29 +0,0 @@
|
|||||||
#File: Ex018_Making_Lofts.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 Ex018_Making_Lofts
|
|
||||||
|
|
||||||
#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 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
|
|
||||||
|
|
||||||
#Create a lofted section between a rectangle and a circular section
|
|
||||||
result = cadquery.Workplane("front").box(4.0, 4.0, 0.25).faces(">Z").circle(1.5) \
|
|
||||||
.workplane(offset=3.0).rect(0.75, 0.5).loft(combine=True)
|
|
||||||
|
|
||||||
#Boiler plate code to render our solid in FreeCAD's GUI
|
|
||||||
Part.show(result.toFreecad())
|
|
@ -1,30 +0,0 @@
|
|||||||
#File: Ex019_Counter_Sunk_Holes.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 Ex019_Counter_Sunk_Holes
|
|
||||||
|
|
||||||
#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 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
|
|
||||||
|
|
||||||
#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)
|
|
||||||
|
|
||||||
#Boiler plate code to render our solid in FreeCAD's GUI
|
|
||||||
Part.show(result.toFreecad())
|
|
@ -1,28 +0,0 @@
|
|||||||
#File: Ex020_Rounding_Corners_with_Fillets.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 Ex020_Rounding_Corners_with_Fillets
|
|
||||||
|
|
||||||
#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 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
|
|
||||||
|
|
||||||
#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)
|
|
||||||
|
|
||||||
#Boiler plate code to render our solid in FreeCAD's GUI
|
|
||||||
Part.show(result.toFreecad())
|
|
@ -1,31 +0,0 @@
|
|||||||
#File: Ex021_Splitting_an_Object.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 Ex021_Splitting_an_Object
|
|
||||||
|
|
||||||
#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 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
|
|
||||||
|
|
||||||
#Create a simple block with a hole through it that we can split
|
|
||||||
c = cadquery.Workplane("XY").box(1, 1, 1).faces(">Z").workplane().circle(0.25).cutThruAll()
|
|
||||||
|
|
||||||
#Cut the block in half sideways
|
|
||||||
result = c.faces(">Y").workplane(-0.5).split(keepTop=True)
|
|
||||||
|
|
||||||
#Boiler plate code to render our solid in FreeCAD's GUI
|
|
||||||
Part.show(result.toFreecad())
|
|
@ -1,40 +0,0 @@
|
|||||||
#File: Ex022_Classic_OCC_Bottle.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 Ex022_Classic_OCC_Bottle
|
|
||||||
|
|
||||||
#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 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 the length, width, and thickness
|
|
||||||
(L,w,t) = (20.0, 6.0, 3.0)
|
|
||||||
s = cadquery.Workplane("XY")
|
|
||||||
|
|
||||||
#Draw half the profile of the bottle and extrude it
|
|
||||||
p = s.center(-L / 2.0, 0).vLine(w / 2.0) \
|
|
||||||
.threePointArc((L / 2.0, w / 2.0 + t),(L, w / 2.0)).vLine(-w / 2.0) \
|
|
||||||
.mirrorX().extrude(30.0, True)
|
|
||||||
|
|
||||||
#Make the neck
|
|
||||||
p.faces(">Z").workplane().circle(3.0).extrude(2.0, True)
|
|
||||||
|
|
||||||
#Make a shell
|
|
||||||
result = p.faces(">Z").shell(0.3)
|
|
||||||
|
|
||||||
#Boiler plate code to render our solid in FreeCAD's GUI
|
|
||||||
Part.show(result.toFreecad())
|
|
@ -1,102 +0,0 @@
|
|||||||
#File: Ex023_Parametric_Enclosure.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 Ex023_Parametric_Enclosure
|
|
||||||
|
|
||||||
#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 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
|
|
||||||
|
|
||||||
#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_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_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)
|
|
||||||
|
|
||||||
#Weird geometry happens if we make the fillets in the wrong order
|
|
||||||
if p_sideRadius > p_topAndBottomRadius:
|
|
||||||
oshell.edges("|Z").fillet(p_sideRadius)
|
|
||||||
oshell.edges("#Z").fillet(p_topAndBottomRadius)
|
|
||||||
else:
|
|
||||||
oshell.edges("#Z").fillet(p_topAndBottomRadius)
|
|
||||||
oshell.edges("|Z").fillet(p_sideRadius)
|
|
||||||
|
|
||||||
#Inner shell
|
|
||||||
ishell = oshell.faces("<Z").workplane(p_thickness, True)\
|
|
||||||
.rect((p_outerWidth - 2.0 * p_thickness),(p_outerLength - 2.0 * p_thickness))\
|
|
||||||
.extrude((p_outerHeight - 2.0 * p_thickness), False) # Set combine false to produce just the new boss
|
|
||||||
ishell.edges("|Z").fillet(p_sideRadius - p_thickness)
|
|
||||||
|
|
||||||
#Make the box outer box
|
|
||||||
box = oshell.cut(ishell)
|
|
||||||
|
|
||||||
#Make the screwposts
|
|
||||||
POSTWIDTH = (p_outerWidth - 2.0 * p_screwpostInset)
|
|
||||||
POSTLENGTH = (p_outerLength - 2.0 * p_screwpostInset)
|
|
||||||
|
|
||||||
postCenters = box.faces(">Z").workplane(-p_thickness)\
|
|
||||||
.rect(POSTWIDTH, POSTLENGTH, forConstruction=True)\
|
|
||||||
.vertices()
|
|
||||||
|
|
||||||
for v in postCenters.all():
|
|
||||||
v.circle(p_screwpostOD / 2.0).circle(p_screwpostID / 2.0)\
|
|
||||||
.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()
|
|
||||||
|
|
||||||
#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))
|
|
||||||
|
|
||||||
#Compute centers for counterbore/countersink or counterbore
|
|
||||||
topOfLidCenters = cutlip.faces(">Z").workplane().rect(POSTWIDTH, POSTLENGTH, forConstruction=True).vertices()
|
|
||||||
|
|
||||||
#Add holes of the desired type
|
|
||||||
if p_boreDiameter > 0 and p_boreDepth > 0:
|
|
||||||
topOfLid = topOfLidCenters.cboreHole(p_screwpostID, p_boreDiameter, p_boreDepth, (2.0) * p_thickness)
|
|
||||||
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)
|
|
||||||
|
|
||||||
#Flip lid upside down if desired
|
|
||||||
if p_flipLid:
|
|
||||||
topOfLid.rotateAboutCenter((1, 0, 0), 180)
|
|
||||||
|
|
||||||
#Return the combined result
|
|
||||||
result = topOfLid.combineSolids(bottom)
|
|
||||||
|
|
||||||
#Boiler plate code to render our solid in FreeCAD's GUI
|
|
||||||
Part.show(result.toFreecad())
|
|
@ -1,41 +0,0 @@
|
|||||||
#File: Ex024_Using_FreeCAD_Solids_as_CQ_Objects.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 Ex024_Using_FreeCAD_Solids_as_CQ_Objects
|
|
||||||
|
|
||||||
#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 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, FreeCAD, Part
|
|
||||||
|
|
||||||
#Create a new document that we can draw our model on
|
|
||||||
newDoc = FreeCAD.newDocument()
|
|
||||||
|
|
||||||
#shows a 1x1x1 FreeCAD cube in the display
|
|
||||||
initialBox = newDoc.addObject("Part::Box","initialBox")
|
|
||||||
newDoc.recompute()
|
|
||||||
|
|
||||||
#Make a CQ object
|
|
||||||
cqBox = cadquery.CQ(cadquery.Solid(initialBox.Shape))
|
|
||||||
|
|
||||||
#Extrude a peg
|
|
||||||
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.Shape = newThing.val().wrapped
|
|
||||||
|
|
||||||
#Rerender the doc to see what the new solid looks like
|
|
||||||
newDoc.recompute()
|
|
@ -1,41 +0,0 @@
|
|||||||
#File: Ex025_Revolution.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 Ex025_Revolution
|
|
||||||
|
|
||||||
#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 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 shape's code directly.
|
|
||||||
rectangle_width = 10.0
|
|
||||||
rectangle_length = 10.0
|
|
||||||
angle_degrees = 360.0
|
|
||||||
|
|
||||||
#Revolve a cylinder from a rectangle
|
|
||||||
#Switch comments around in this section to try the revolve operation with different parameters
|
|
||||||
result = cadquery.Workplane("XY").rect(rectangle_width, rectangle_length, False).revolve()
|
|
||||||
#result = cadquery.Workplane("XY").rect(rectangle_width, rectangle_length, False).revolve(angle_degrees)
|
|
||||||
#result = cadquery.Workplane("XY").rect(rectangle_width, rectangle_length).revolve(angle_degrees,(-5,-5))
|
|
||||||
#result = cadquery.Workplane("XY").rect(rectangle_width, rectangle_length).revolve(angle_degrees,(-5, -5),(-5, 5))
|
|
||||||
#result = cadquery.Workplane("XY").rect(rectangle_width, rectangle_length).revolve(angle_degrees,(-5,-5),(-5,5), False)
|
|
||||||
|
|
||||||
#Revolve a donut with square walls
|
|
||||||
#result = cadquery.Workplane("XY").rect(rectangle_width, rectangle_length, True).revolve(angle_degrees, (20, 0), (20, 10))
|
|
||||||
|
|
||||||
#Boiler plate code to render our solid in FreeCAD's GUI
|
|
||||||
Part.show(result.toFreecad())
|
|
Reference in New Issue
Block a user