Skip to content

Commit d943ce1

Browse files
authored
Adds support for the extrusion capability to the CadDocument class. (#804)
* Adds support for the `extrusion` capability to the `CadDocument` class. * Update docstring
1 parent 8851146 commit d943ce1

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

python/jupytercad_lab/jupytercad_lab/notebook/cad_document.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,60 @@ def intersect(
738738
self.set_visible(shape2, False)
739739
return self.add_object(OBJECT_FACTORY.create_object(data, self))
740740

741+
def extrude(
742+
self,
743+
name: str = "",
744+
shape: str | int = None,
745+
direction: List[float] = [0, 0, 1],
746+
length_fwd: float = 10,
747+
length_rev: float = 0,
748+
solid: bool = False,
749+
color: Optional[str] = None,
750+
position: List[float] = [0, 0, 0],
751+
rotation_axis: List[float] = [0, 0, 1],
752+
rotation_angle: float = 0,
753+
) -> CadDocument:
754+
"""
755+
Apply an extrusion operation on an object.
756+
If no object is provided as input, the last created object will be used as operand.
757+
758+
:param name: The name that will be used for the object in the document.
759+
:param shape: The input object used for the extrusion. Can be the name of the object or its index in the objects list.
760+
:param direction: The direction of the extrusion.
761+
:param length_fwd: The length of the extrusion.
762+
:param length_rev: The length of the extrusion in the reverse direction.
763+
:param solid: Whether to create a solid or a shell.
764+
:param color: The color in hex format (e.g., "#FF5733") or RGB float list. Defaults to the base object's color if None.
765+
:param position: The shape 3D position.
766+
:param rotation_axis: The 3D axis used for the rotation.
767+
:param rotation_angle: The shape rotation angle, in degrees.
768+
:return: The document itself.
769+
"""
770+
shape = self._get_operand(shape)
771+
772+
if color is None:
773+
color = self._get_color(shape)
774+
775+
data = {
776+
"shape": Parts.Part__Extrusion.value,
777+
"name": name if name else self._new_name("Extrusion"),
778+
"parameters": {
779+
"Base": shape,
780+
"Dir": direction,
781+
"LengthFwd": length_fwd,
782+
"LengthRev": length_rev,
783+
"Solid": solid,
784+
"Color": color,
785+
"Placement": {
786+
"Position": position,
787+
"Axis": rotation_axis,
788+
"Angle": rotation_angle,
789+
},
790+
},
791+
}
792+
self.set_visible(shape, False)
793+
return self.add_object(OBJECT_FACTORY.create_object(data, self))
794+
741795
def chamfer(
742796
self,
743797
name: str = "",

0 commit comments

Comments
 (0)