Skip to content

Commit aba24c0

Browse files
authored
Added docs for new extrude capabilities (#894)
* Added docs for new extrude capabilities Added examples for extrude and cutblind until extrusion parameter Updated weird leftover text in Example page * added note on relative axis coords for Workplane.revolve * added mixed extrude cutblind example
1 parent b4d638a commit aba24c0

File tree

3 files changed

+131
-11
lines changed

3 files changed

+131
-11
lines changed

cadquery/cq.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2993,7 +2993,7 @@ def extrude(
29932993
to the normal of the plane. The string "next" extrudes until the next face orthogonal to
29942994
the wire normal. "last" extrudes to the last face. If a object of type Face is passed then
29952995
the extrusion will extend until this face.
2996-
:param boolean combine: True to combine the resulting solid with parent solids if found.
2996+
:param boolean combine: True to combine the resulting solid with parent solids if found. (Cannot be set to False when `until` is not set as a float)
29972997
:param boolean clean: call :py:meth:`clean` afterwards to have a clean shape
29982998
:param boolean both: extrude in both directions symmetrically
29992999
:param float taper: angle for optional tapered extrusion
@@ -3070,6 +3070,12 @@ def revolve(
30703070
* if combine is False, the new value is pushed onto the stack.
30713071
* if combine is true, the value is combined with the context solid if it exists,
30723072
and the resulting solid becomes the new context solid.
3073+
3074+
.. note::
3075+
Keep in mind that `axisStart` and `axisEnd` are defined relative to the current Workplane center position.
3076+
So if for example you want to revolve a circle centered at (10,0,0) around the Y axis, be sure to either :py:meth:`move` (or :py:meth:`moveTo`)
3077+
the current Workplane position or specify `axisStart` and `axisEnd` with the correct vector position.
3078+
In this example (0,0,0), (0,1,0) as axis coords would fail.
30733079
"""
30743080
# Make sure we account for users specifying angles larger than 360 degrees
30753081
angleDegrees %= 360.0

doc/examples.rst

Lines changed: 124 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,19 @@ They are organized from simple to complex, so working through them in order is t
1313
Each example lists the API elements used in the example for easy reference.
1414
Items introduced in the example are marked with a **!**
1515

16-
.. note::
17-
18-
You may want to work through these examples by pasting the text into a code editor in a CadQuery .
19-
If you do, make sure to take these steps so that they work:
2016

21-
1. paste the content into the build() method, properly indented, and
22-
2. add the line 'return result' at the end. The samples below are autogenerated, but they use a different
23-
syntax than the models on the website need to be.
2417

2518
.. note::
2619

2720
We strongly recommend installing `CQ-editor <https://github.com/CadQuery/CQ-editor>`_,
2821
so that you can work along with these examples interactively. See :ref:`installation` for more info.
2922

23+
If you do, make sure to take these steps so that they work:
24+
25+
1. import cadquery as cq
26+
2. add the line ``show_object(result)`` at the end. The samples below are autogenerated, but they use a different
27+
syntax than the models on the website need to be.
28+
3029
.. warning::
3130

3231
* You have to have an svg capable browser to view these!
@@ -622,6 +621,124 @@ and a circular section.
622621
* :py:meth:`Workplane.circle`
623622
* :py:meth:`Workplane.rect`
624623

624+
Extruding until a given face
625+
--------------------------------------------
626+
627+
Sometimes you will want to extrude a wire until a given face that can be not planar or where you
628+
might not know easily the distance you have to extrude to. In such cases you can use `next`, `last`
629+
or even give a :class:`~cadquery.Face` object for the `until` argument of
630+
:meth:`~cadquery.Workplane.extrude`.
631+
632+
633+
.. cadquery::
634+
635+
result = (cq.Workplane(origin = (20,0,0))
636+
.circle(2)
637+
.revolve(180, (-20,0,0),(-20,-1,0))
638+
.center(-20,0)
639+
.workplane()
640+
.rect(20,4)
641+
.extrude("next")
642+
)
643+
644+
The same behaviour is available with :meth:`~cadquery.Workplane.cutBlind` and as you can see it is
645+
also possible to work on several :class:`~cadquery.Wire` objects at a time (the
646+
same is true for :meth:`~cadquery.Workplane.extrude`).
647+
648+
.. cadquery::
649+
650+
skycrappers_locations = [(-16,1),(-8,0),(7,0.2),(17,-1.2)]
651+
angles = iter([15,0,-8,10])
652+
skycrappers = (cq.Workplane()
653+
.pushPoints(skycrappers_locations)
654+
.eachpoint(lambda loc: (cq.Workplane()
655+
.rect(5,16)
656+
.workplane(offset=10)
657+
.ellipse(3,8)
658+
.workplane(offset=10)
659+
.slot2D(20,5, 90)
660+
.loft()
661+
.rotateAboutCenter((0,0,1),next(angles))
662+
.val().located(loc)
663+
)
664+
)
665+
)
666+
667+
result = (skycrappers
668+
.transformed((0,-90,0))
669+
.moveTo(15,0)
670+
.rect(3,3, forConstruction=True)
671+
.vertices()
672+
.circle(1)
673+
.cutBlind("last")
674+
)
675+
676+
Here is a typical situation where extruding and cuting until a given surface is very handy. It allows us to extrude or cut until a curved surface without overlapping issues.
677+
678+
.. cadquery::
679+
680+
import cadquery as cq
681+
682+
sphere = cq.Workplane().sphere(5)
683+
base = (cq.Workplane(origin=(0,0,-2))
684+
.box(12,12,10)
685+
.cut(sphere)
686+
.edges("|Z")
687+
.fillet(2)
688+
)
689+
sphere_face = base.faces(">>X[2] and (not |Z) and (not |Y)").val()
690+
base = (base
691+
.faces("<Z")
692+
.workplane()
693+
.circle(2)
694+
.extrude(10)
695+
)
696+
697+
shaft = (cq.Workplane()
698+
.sphere(4.5)
699+
.circle(1.5)
700+
.extrude(20)
701+
)
702+
703+
spherical_joint = (base.union(shaft)
704+
.faces(">X")
705+
.workplane(centerOption="CenterOfMass")
706+
.move(0,4)
707+
.slot2D(10,2,90)
708+
.cutBlind(sphere_face)
709+
.workplane(offset=10)
710+
.move(0,2)
711+
.circle(0.9)
712+
.extrude("next")
713+
)
714+
715+
result = spherical_joint
716+
717+
.. warning::
718+
719+
If the wire you want to extrude cannot be fully projected on the target surface, the result will
720+
be unpredictable. Furthermore the algorithm in charge of finding the candidates faces do it's
721+
search by counting all the faces intersected by a line created from your wire center along your
722+
extrusion direction. So make sure your wire can be projected on your target face to avoid
723+
unexpected behaviour.
724+
725+
.. topic:: Api References
726+
727+
.. hlist::
728+
:columns: 3
729+
730+
* :py:meth:`Workplane.cutBlind` **!**
731+
* :py:meth:`Workplane.rect`
732+
* :py:meth:`Workplane.ellipse`
733+
* :py:meth:`Workplane.workplane`
734+
* :py:meth:`Workplane.slot2D`
735+
* :py:meth:`Workplane.loft`
736+
* :py:meth:`Workplane.rotateAboutCenter`
737+
* :py:meth:`Workplane.transformed`
738+
* :py:meth:`Workplane.moveTo`
739+
* :py:meth:`Workplane.circle`
740+
741+
625742
Making Counter-bored and Counter-sunk Holes
626743
----------------------------------------------
627744

doc/roadmap.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,3 @@ primitive creation
8383
* cone
8484
* torus
8585
* wedge
86-
87-
extrude/cut up to surface
88-
allow a cut or extrude to terminate at another surface, rather than either through all or a fixed distance

0 commit comments

Comments
 (0)