Cleaned up, commented and converted the first five examples to be CQGI-compliant.
This commit is contained in:
parent
da82797677
commit
24a77b727e
|
@ -1,20 +0,0 @@
|
|||
# This example is meant to be used from within the CadQuery module of FreeCAD.
|
||||
# From within FreeCAD, you can make changes to this script and then click
|
||||
# CadQuery > Execute Script, or you can press F2.
|
||||
# There are more examples in the Examples directory included with this module.
|
||||
# Ex026_Lego_Brick.py is highly recommended as a great example of what CadQuery
|
||||
# can do.
|
||||
import cadquery
|
||||
from Helpers import show
|
||||
|
||||
# The dimensions of the box. These can be modified rather than changing the
|
||||
# object's code directly.
|
||||
length = 2.0
|
||||
height = 1.0
|
||||
thickness = 1.0
|
||||
|
||||
# Create a 3D box based on the dimension variables above
|
||||
result = cadquery.Workplane("XY").box(length, height, thickness)
|
||||
|
||||
# Render the solid
|
||||
show(result)
|
|
@ -1,15 +1,19 @@
|
|||
# This example is meant to be used from within the CadQuery module of FreeCAD.
|
||||
import cadquery
|
||||
from Helpers import show
|
||||
import cadquery as cq
|
||||
|
||||
# The dimensions of the box. These can be modified rather than changing the
|
||||
# object's code directly.
|
||||
length = 80.0
|
||||
height = 60.0
|
||||
thickness = 10.0
|
||||
# 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 box based on the dimension variables above
|
||||
result = cadquery.Workplane("XY").box(length, height, thickness)
|
||||
# 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)
|
||||
|
||||
# Render the solid
|
||||
show(result)
|
||||
# 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
|
||||
|
||||
build_object(result)
|
||||
|
|
|
@ -1,17 +1,20 @@
|
|||
# This example is meant to be used from within the CadQuery module of FreeCAD.
|
||||
import cadquery
|
||||
from Helpers import show
|
||||
import cadquery as cq
|
||||
|
||||
# The dimensions of the box. These can be modified rather than changing the
|
||||
# object's code directly.
|
||||
length = 80.0
|
||||
height = 60.0
|
||||
thickness = 10.0
|
||||
center_hole_dia = 22.0
|
||||
# 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 box based on the dimensions above and add a 22mm center hole
|
||||
result = cadquery.Workplane("XY").box(length, height, thickness) \
|
||||
# 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)
|
||||
|
||||
# Render the solid
|
||||
show(result)
|
||||
# Displays the result of this script
|
||||
build_object(result)
|
||||
|
|
|
@ -1,23 +1,34 @@
|
|||
# This example is meant to be used from within the CadQuery module of FreeCAD.
|
||||
import cadquery
|
||||
from Helpers import show
|
||||
import cadquery as cq
|
||||
|
||||
# The dimensions of the box. These can be modified rather than changing the
|
||||
# object'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
|
||||
# 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 box based on the dimensions above and add 4 counterbored holes
|
||||
result = cadquery.Workplane("XY").box(length, height, thickness) \
|
||||
# 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)
|
||||
|
||||
# Render the solid
|
||||
show(result)
|
||||
# Displays the result of this script
|
||||
build_object(result)
|
||||
|
|
|
@ -1,18 +1,29 @@
|
|||
# This example is meant to be used from within the CadQuery module of FreeCAD.
|
||||
import cadquery
|
||||
from Helpers import show
|
||||
import cadquery as cq
|
||||
|
||||
# The dimensions of the model. These can be modified rather than changing the
|
||||
# object's code directly.
|
||||
circle_radius = 50.0
|
||||
rectangle_width = 13.0
|
||||
rectangle_length = 19.0
|
||||
thickness = 13.0
|
||||
# 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
|
||||
result = cadquery.Workplane("front").circle(circle_radius) \
|
||||
.rect(rectangle_width, rectangle_length) \
|
||||
.extrude(thickness)
|
||||
# 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)
|
||||
|
||||
# Render the solid
|
||||
show(result)
|
||||
# Displays the result of this script
|
||||
build_object(result)
|
||||
|
|
|
@ -1,17 +1,32 @@
|
|||
# This example is meant to be used from within the CadQuery module of FreeCAD.
|
||||
import cadquery
|
||||
from Helpers import show
|
||||
import cadquery as cq
|
||||
|
||||
# The dimensions of the model. These can be modified rather than changing the
|
||||
# object's code directly.
|
||||
width = 2.0
|
||||
thickness = 0.25
|
||||
# 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
|
||||
result = cadquery.Workplane("front").lineTo(width, 0) \
|
||||
.lineTo(width, 1.0) \
|
||||
.threePointArc((1.0, 1.5), (0.0, 1.0)) \
|
||||
.close().extrude(thickness)
|
||||
# 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. close() is called to automatically draw the last line for us and close
|
||||
# the sketch so that it can be extruded.
|
||||
# 5a. Without the close(), the 2D sketch will be left open and the extrude
|
||||
# operation will provide unpredictable results.
|
||||
# 6. 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)) \
|
||||
.close().extrude(thickness)
|
||||
|
||||
# Render the solid
|
||||
show(result)
|
||||
# Displays the result of this script
|
||||
build_object(result)
|
||||
|
|
Loading…
Reference in New Issue
Block a user