Finished converting the rest of the examples and then started fixing the ones that are broken.
This commit is contained in:
parent
e31b95099f
commit
a661b0ec4b
|
@ -8,7 +8,7 @@ import cadquery as cq
|
|||
# 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 plancing
|
||||
# 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.
|
||||
|
|
|
@ -1,11 +1,21 @@
|
|||
# This example is meant to be used from within the CadQuery module of FreeCAD.
|
||||
import cadquery
|
||||
from Helpers import show
|
||||
import cadquery as cq
|
||||
|
||||
# Create a block with holes in each corner of a rectangle on that workplane
|
||||
result = cadquery.Workplane("front").box(2, 2, 0.5)\
|
||||
# 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)
|
||||
.rect(1.5, 1.5, forConstruction=True).vertices() \
|
||||
.hole(0.125)
|
||||
|
||||
# Render the solid
|
||||
show(result)
|
||||
# Displays the result of this script
|
||||
show_object(result)
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
# This example is meant to be used from within the CadQuery module of FreeCAD.
|
||||
import cadquery
|
||||
from Helpers import show
|
||||
import cadquery as cq
|
||||
|
||||
# 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)
|
||||
# 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)
|
||||
|
||||
# Render the solid
|
||||
show(result)
|
||||
# Displays the result of this script
|
||||
show_object(result)
|
||||
|
|
|
@ -1,11 +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
|
||||
|
||||
# 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)
|
||||
# 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)
|
||||
|
||||
# Render the solid
|
||||
show(result)
|
||||
# Displays the result of this script
|
||||
show_object(result)
|
||||
|
|
|
@ -1,11 +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
|
||||
|
||||
# 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)\
|
||||
# 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)
|
||||
|
||||
# Render the solid
|
||||
show(result)
|
||||
# Displays the result of this script
|
||||
show_object(result)
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
# This example is meant to be used from within the CadQuery module of FreeCAD.
|
||||
import cadquery
|
||||
from Helpers import show
|
||||
import cadquery as cq
|
||||
|
||||
# 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)
|
||||
# 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)
|
||||
|
||||
# Render the solid
|
||||
show(result)
|
||||
# Displays the result of this script
|
||||
show_object(result)
|
||||
|
|
|
@ -1,13 +1,25 @@
|
|||
# This example is meant to be used from within the CadQuery module of FreeCAD.
|
||||
import cadquery
|
||||
from Helpers import show
|
||||
import cadquery as cq
|
||||
|
||||
# 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()
|
||||
# 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()
|
||||
|
||||
# Cut the block in half sideways
|
||||
# 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)
|
||||
|
||||
# Render the solid
|
||||
show(result)
|
||||
# Displays the result of this script
|
||||
show_object(result)
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
# This example is meant to be used from within the CadQuery module of FreeCAD.
|
||||
import cadquery
|
||||
from Helpers import show
|
||||
import cadquery as cq
|
||||
|
||||
# Set up the length, width, and thickness
|
||||
(L, w, t) = (20.0, 6.0, 3.0)
|
||||
s = cadquery.Workplane("XY")
|
||||
s = cq.Workplane("XY")
|
||||
|
||||
# Draw half the profile of the bottle and extrude it
|
||||
p = s.center(-L / 2.0, 0).vLine(w / 2.0) \
|
||||
|
@ -17,5 +15,5 @@ p.faces(">Z").workplane().circle(3.0).extrude(2.0, True)
|
|||
# Make a shell
|
||||
result = p.faces(">Z").shell(0.3)
|
||||
|
||||
# Render the solid
|
||||
show(result)
|
||||
# Displays the result of this script
|
||||
show_object(result)
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
# This example is meant to be used from within the CadQuery module of FreeCAD.
|
||||
import cadquery
|
||||
from Helpers import show
|
||||
import cadquery as cq
|
||||
|
||||
# Parameter definitions
|
||||
p_outerWidth = 100.0 # Outer width of box enclosure
|
||||
|
@ -22,7 +20,7 @@ p_countersinkAngle = 90.0 # Countersink angle (complete angle between opposite
|
|||
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) \
|
||||
oshell = cq.Workplane("XY").rect(p_outerWidth, p_outerLength) \
|
||||
.extrude(p_outerHeight + p_lipHeight)
|
||||
|
||||
# Weird geometry happens if we make the fillets in the wrong order
|
||||
|
@ -75,5 +73,5 @@ else:
|
|||
# Return the combined result
|
||||
result = topOfLid.combineSolids(bottom)
|
||||
|
||||
# Render the solid
|
||||
show(result)
|
||||
# Displays the result of this script
|
||||
show_object(result)
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
# 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
|
||||
# shape's code directly.
|
||||
|
@ -10,7 +8,7 @@ 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 = 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))
|
||||
|
@ -19,5 +17,5 @@ result = cadquery.Workplane("XY").rect(rectangle_width, rectangle_length, False)
|
|||
# Revolve a donut with square walls
|
||||
#result = cadquery.Workplane("XY").rect(rectangle_width, rectangle_length, True).revolve(angle_degrees, (20, 0), (20, 10))
|
||||
|
||||
# Render the solid
|
||||
show(result)
|
||||
# Displays the result of this script
|
||||
show_object(result)
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
# This example is meant to be used from within the CadQuery module of FreeCAD.
|
||||
# This script can create any regular rectangular Lego(TM) Brick
|
||||
import cadquery
|
||||
from Helpers import show
|
||||
import cadquery as cq
|
||||
|
||||
#####
|
||||
# Inputs
|
||||
|
@ -28,7 +26,7 @@ total_length = lbumps*pitch - 2.0*clearance
|
|||
total_width = wbumps*pitch - 2.0*clearance
|
||||
|
||||
# make the base
|
||||
s = cadquery.Workplane("XY").box(total_length, total_width, height)
|
||||
s = cq.Workplane("XY").box(total_length, total_width, height)
|
||||
|
||||
# shell inwards not outwards
|
||||
s = s.faces("<Z").shell(-1.0 * t)
|
||||
|
@ -55,4 +53,4 @@ else:
|
|||
tmp = s
|
||||
|
||||
# Render the solid
|
||||
show(tmp)
|
||||
show_object(tmp)
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
# This example is meant to be used from within the CadQuery module of FreeCAD.
|
||||
import cadquery as cq
|
||||
from Helpers import show
|
||||
|
||||
exploded = False # when true, moves the base away from the top so we see
|
||||
showTop = True # When true, the top is rendered.
|
||||
|
@ -30,12 +28,10 @@ def trapezoid(b1, b2, h):
|
|||
y = h / 2
|
||||
x1 = b1 / 2
|
||||
x2 = b2 / 2
|
||||
return (xyplane
|
||||
.polyline([(-x1, y),
|
||||
(x1, y),
|
||||
return (xyplane.moveTo(-x1, y)
|
||||
.polyline([(x1, y),
|
||||
(x2, -y),
|
||||
(-x2, -y),
|
||||
(-x1, y)]))
|
||||
(-x2, -y)]).close())
|
||||
|
||||
|
||||
# Defines our base shape: a box with fillets around the vertical edges.
|
||||
|
@ -54,10 +50,10 @@ top = (base(height)
|
|||
.edges(">Z")
|
||||
.fillet(yFilletRadius)
|
||||
# shell the solid from the bottom face, with a .060" wall thickness
|
||||
.faces("-Z")
|
||||
.faces("<Z")
|
||||
.shell(-wallThickness)
|
||||
# cut five button holes into the top face in a cross pattern.
|
||||
.faces("+Z")
|
||||
.faces(">Z")
|
||||
.workplane()
|
||||
.pushPoints([(0, 0),
|
||||
(-xHoleOffset, 0),
|
||||
|
@ -84,6 +80,6 @@ cover = (base(coverThickness)
|
|||
|
||||
# Conditionally render the parts
|
||||
if showTop:
|
||||
show(top)
|
||||
show_object(top)
|
||||
if showCover:
|
||||
show(cover)
|
||||
show_object(cover)
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
# This example is meant to be used from within the CadQuery module of FreeCAD.
|
||||
import numpy as np
|
||||
import cadquery
|
||||
from Helpers import show
|
||||
import cadquery as cq
|
||||
|
||||
# Square side and offset in x and y.
|
||||
side = 10
|
||||
|
@ -11,16 +9,15 @@ offset = 5
|
|||
# The polyline is defined as numpy.array so that operations like translation
|
||||
# of all points are simplified.
|
||||
pts = np.array([
|
||||
(0, 0),
|
||||
(side, 0),
|
||||
(side, side),
|
||||
(0, side),
|
||||
(0, 0),
|
||||
]) + [offset, offset]
|
||||
|
||||
result = cadquery.Workplane('XY') \
|
||||
.polyline(pts).extrude(2) \
|
||||
result = cq.Workplane('XY') \
|
||||
.polyline(pts).close().extrude(2) \
|
||||
.faces('+Z').workplane().circle(side / 2).extrude(1)
|
||||
|
||||
# Render the solid
|
||||
show(result)
|
||||
show_object(result)
|
||||
|
|
|
@ -5,7 +5,6 @@ from __future__ import unicode_literals, division
|
|||
from collections import namedtuple
|
||||
|
||||
import cadquery as cq
|
||||
from Helpers import show
|
||||
|
||||
# text_lines is a list of text lines.
|
||||
# FreeCAD in braille (converted with braille-converter:
|
||||
|
@ -180,4 +179,4 @@ _cell_geometry = BrailleCellGeometry(
|
|||
if base_thickness < get_cylinder_radius(_cell_geometry):
|
||||
raise ValueError('Base thickness should be at least {}'.format(dot_height))
|
||||
|
||||
show(make_embossed_plate(text_lines, _cell_geometry))
|
||||
show_object(make_embossed_plate(text_lines, _cell_geometry))
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
# 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.
|
||||
|
@ -9,7 +7,7 @@ height = 500
|
|||
thickness = 2
|
||||
|
||||
# Create a plate with two polygons cut through it
|
||||
result = cadquery.Workplane("front").box(width, height, thickness)
|
||||
result = cq.Workplane("front").box(width, height, thickness)
|
||||
|
||||
h_sep = 60
|
||||
for idx in range(4):
|
||||
|
@ -44,4 +42,4 @@ for idx in range(4):
|
|||
result = result.workplane(offset=1, centerOption='CenterOfBoundBox').center(-173,-30-idx*h_sep).moveTo(-2.9176,-5.3).threePointArc((-6.05,0),(-2.9176,5.3)).lineTo(2.9176,5.3).threePointArc((6.05,0),(2.9176,-5.3)).close().cutThruAll()
|
||||
|
||||
# Render the solid
|
||||
show(result)
|
||||
show_object(result)
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
# This example is meant to be used from within the CadQuery module for FreeCAD
|
||||
import cadquery
|
||||
from Helpers import show
|
||||
import cadquery as cq
|
||||
|
||||
# Points we will use to create spline and polyline paths to sweep over
|
||||
pts = [
|
||||
|
@ -10,33 +8,33 @@ pts = [
|
|||
]
|
||||
|
||||
# Spline path generated from our list of points (tuples)
|
||||
path = cadquery.Workplane("XZ").spline(pts)
|
||||
path = cq.Workplane("XZ").spline(pts)
|
||||
|
||||
# Sweep a circle with a diameter of 1.0 units along the spline path we just created
|
||||
defaultSweep = cadquery.Workplane("XY").circle(1.0).sweep(path)
|
||||
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 = cadquery.Workplane("XY").circle(1.0).sweep(path, makeSolid=False, isFrenet=True)
|
||||
frenetShell = cq.Workplane("XY").circle(1.0).sweep(path, makeSolid=False, isFrenet=True)
|
||||
|
||||
# We can sweep shapes other than circles
|
||||
defaultRect = cadquery.Workplane("XY").rect(1.0, 1.0).sweep(path)
|
||||
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 = cadquery.Workplane("XZ").polyline(pts)
|
||||
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 = cadquery.Workplane("XY").circle(1.0).sweep(path)
|
||||
plineSweep = cq.Workplane("XY").circle(1.0).sweep(path)
|
||||
|
||||
# Switch to an arc for the path
|
||||
path = cadquery.Workplane("XZ").threePointArc((1.0, 1.5), (0.0, 1.0))
|
||||
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 = cadquery.Workplane("XY").circle(0.5).sweep(path)
|
||||
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(defaultSweep)
|
||||
show(frenetShell.translate((5, 0, 0)))
|
||||
show(defaultRect.translate((10, 0, 0)))
|
||||
show(plineSweep.translate((15, 0, 0)))
|
||||
show(arcSweep.translate((20, 0, 0)))
|
||||
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)))
|
|
@ -1,7 +1,6 @@
|
|||
# 3d printer for mounting hotend to X-carriage inspired by the P3steel Toolson
|
||||
# edition - http://www.thingiverse.com/thing:1054909
|
||||
import cadquery as cq
|
||||
from Helpers import show
|
||||
|
||||
|
||||
def move_to_center(cqObject, shape):
|
||||
|
@ -213,4 +212,4 @@ hole_sep = 0.5*face_right.Area()/main_plate_thickness
|
|||
res = make_aux_holes(res, hole_sep, 2)
|
||||
|
||||
# show the result
|
||||
show(res)
|
||||
show_object(res)
|
|
@ -1,11 +1,10 @@
|
|||
# Example using advanced logical operators in string selectors
|
||||
# to select only the inside edges on a shelled cube to chamfer.
|
||||
# Example using advanced logical operators in string selectors to select only
|
||||
# the inside edges on a shelled cube to chamfer.
|
||||
import cadquery as cq
|
||||
from Helpers import show
|
||||
|
||||
result = cq.Workplane("XY").box(2, 2, 2).\
|
||||
faces(">Z").shell(-0.2).\
|
||||
faces(">Z").edges("not(<X or >X or <Y or >Y)").\
|
||||
chamfer(0.125)
|
||||
|
||||
show(result)
|
||||
show_object(result)
|
||||
|
|
Loading…
Reference in New Issue
Block a user