How to construct a sketch using the edga-based API and then extrude it in a empty workplane. #1374
-
I checked CadQuery's read the docs (https://cadquery.readthedocs.io) for working with sketches. Perhaps I missed something, but I would like to extrude a sketch to get my first 3D object. From the examples I see how to add a sketch to an existing face, however I am running into road blocks when trying to extrude a sketch off the default workplane. Here is my example sketch:
I have tried a several things so far including:
This leads to the error 'Sketch; object has no attribute 'extrude'. Since the workplane does not yet have a face, I cannot use I would be grateful for guidance. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
Here's an example I have in my notes that seems to work.
|
Beta Was this translation helpful? Give feedback.
-
Remove import cadquery as cq
r1 = 3/16
r2 = 2*r1
h = 2
b = 1
angle = 30 # degrees
s = (
cq.Sketch()
.segment((0,0),(0,h))
.segment(r1,0)
.segment(h,-90)
.arc((r2,0), r1, 180, angle)
.segment(b, 270+angle)
.segment(r1,180+angle)
.segment(b,90+angle)
.arc((r2,0), r2, 180+angle, -angle)
.assemble()
)
result = cq.Workplane().placeSketch(s).extrude(10) See the docs section on the Edge-based API and the notes on
To define the sketch inline (instead of ...
result = (
cq.Workplane()
.sketch()
.segment((0,0),(0,h))
...
.arc((r2,0), r2, 180+angle, -angle)
.assemble()
.finalize() # finish the sketch
.extrude(10)
) |
Beta Was this translation helpful? Give feedback.
-
@Willy-Schnackenpfefferhausen also read this section of the docs https://cadquery.readthedocs.io/en/latest/sketch.html#workplane-integration . |
Beta Was this translation helpful? Give feedback.
-
Thank you for the suggestion. In each of the cases that are presented in #workplane-integration, the code begins with an existing face. I began by using these examples but unfortunately overlooked the answer to my question, which was addressed in #edge-based-api on the same page. The necessary step for my situation was to use |
Beta Was this translation helpful? Give feedback.
Remove
close()
(because the final arc already closes the edges).Add
assemble()
.See the docs section on the Edge-based API and the notes on
assemble
.https://cadquery.readthedocs.io/en/latest/sketch.html#edge-based-api
assemble
is not required in @jmwright's example because it callsrect
which automatically r…