What is the difference between polyline and rect in this example?

284 views
Skip to first unread message

Paul Jurczak

unread,
Apr 2, 2022, 2:22:59 AM4/2/22
to CadQuery
I thought that `polyline` and `rect` should produce the same result in this example:
```
import cadquery as cq

pts = [(-1, -1), (1, -1), (1, 1), (-1, 1), (-1, -1)]
rod = cq.Workplane('XY').polyline(pts).extrude(9)
# rod = cq.Workplane('XY').rect(2, 2).extrude(9)
```
`rect` works as expected, but `polyline` produces `list index out of range` error. What am I doing wrong?

Jeremy Wright

unread,
Apr 2, 2022, 7:13:12 AM4/2/22
to Paul Jurczak, CadQuery
polyline returns a list of edges and extrude works on wires. There are other ways to do it, but I usually call close on my polylines so that I get a wire back that I can extrude.

pts = [(-1, -1), (1, -1), (1, 1), (-1, 1)] # notice that I removed the last, closing point
rod = cq.Workplane('XY').polyline(pts).close().extrude(9) # called close() here


--
cadquery home: https://github.com/CadQuery/cadquery
post issues at https://github.com/CadQuery/cadquery/issues
run it at home at : https://github.com/CadQuery/CQ-editor
---
You received this message because you are subscribed to the Google Groups "CadQuery" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cadquery+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cadquery/734b48b5-f101-4848-88a9-552bbf99762fn%40googlegroups.com.

Paul Jurczak

unread,
Apr 2, 2022, 2:40:14 PM4/2/22
to CadQuery
Thanks a lot. That was my suspicion, but I couldn't find it in the documentation, not knowing CAD lingo.

Paul Jurczak

unread,
Apr 2, 2022, 4:44:24 PM4/2/22
to CadQuery
I looked at the documentation again, and I'm curious if I missed something. `polyline` docs reads: "NOTE most commonly, the resulting wire should be closed.", which suggest that a wire is created. Granted, it also reads: "Returns a new CQ object with a list of edges on the stack". Documentation of `close` just reads: "Close an Edge", but it works on `Union[EdgeWire]`. Does it turn Edge into Wire? What about list of edges, which is what `polyline` seems to be?

In general, there seems to be something missing in the documentation for a newbie with no previous CAD exposure. Is there a discussion of fundamental concepts other than https://cadquery.readthedocs.io/en/latest/primer.html?

Jeremy Wright

unread,
Apr 11, 2022, 10:16:06 AM4/11/22
to Paul Jurczak, CadQuery
The function signature you reference for close is from the Edge class instead of the Workplane class, which I think was covered in another conversation. Here's the docstring from the Workplane class, and note that the method returns self.wire. https://github.com/CadQuery/cadquery/blob/3f6da6d8b528d1556382e691b92b70a8e6c5d1b6/cadquery/cq.py#L2723

polyline does not place any wires in the new object, so that note in the polyline docstring seems misleading to me. https://github.com/CadQuery/cadquery/blob/3f6da6d8b528d1556382e691b92b70a8e6c5d1b6/cadquery/cq.py#L2719

Reply all
Reply to author
Forward
0 new messages