1
+ ---
2
+ jupytext:
3
+ text_representation:
4
+ extension: .mystnb
5
+ format_name: myst
6
+ format_version: 0.13
7
+ jupytext_version: 1.14.1
8
+ kernelspec:
9
+ display_name: Python 3 (ipykernel)
10
+ language: python
11
+ name: python3
12
+ ---
13
+ # Single body with material assignment
14
+
15
+ In PyGeometry, a ``Body`` represents solids or surfaces organized within the ``Design`` assembly.
16
+ The current state of ``Sketch``, which is a client-side execution, can be used for the operations of
17
+ the geometric design assembly. The Geometry Service also provides data structures to create individual materials
18
+ and its properties, which are also exposed through PyGeometry.
19
+
20
+ This example demonstrates how to create a single body from a sketch, by requesting its extrusion,
21
+ and how to assign a material to it.
22
+
23
+ ```{code-cell} ipython3
24
+ from pint import Quantity
25
+
26
+ from ansys.geometry.core import Modeler
27
+ from ansys.geometry.core.materials import Material, MaterialProperty, MaterialPropertyType
28
+ from ansys.geometry.core.math import UNITVECTOR3D_Z, Frame, Plane, Point2D, Point3D, UnitVector3D
29
+ from ansys.geometry.core.misc import UNITS
30
+ from ansys.geometry.core.sketch import Sketch
31
+ ```
32
+ ## Defining the ``Sketch``
33
+
34
+ Create a basic ``circle`` sketch instance with radius 10mm in the default plane.
35
+
36
+ ```{code-cell} ipython3
37
+ sketch = Sketch()
38
+ sketch.circle(Point2D([10, 10], UNITS.mm), Quantity(10, UNITS.mm))
39
+ ```
40
+
41
+ ## Initiate the design in the server
42
+
43
+ A server connection is established and a design has been initiated.
44
+ ```{code-cell} ipython3
45
+ modeler = Modeler()
46
+ design_name = "ExtrudeProfile"
47
+ design = modeler.create_design(design_name)
48
+ ```
49
+
50
+ ## Add materials to the design
51
+
52
+ Adding materials and its properties to the design. Additional properties of
53
+ the material can be added at construction of the ``Material`` object or afterwards,
54
+ as it is shown in the code snippet.
55
+ ```{code-cell} ipython3
56
+ density = Quantity(125, 10 * UNITS.kg / (UNITS.m * UNITS.m * UNITS.m))
57
+ poisson_ratio = Quantity(0.33, UNITS.dimensionless)
58
+ tensile_strength = Quantity(45)
59
+ material = Material(
60
+ "steel",
61
+ density,
62
+ [MaterialProperty(MaterialPropertyType.POISSON_RATIO, "PoissonRatio", poisson_ratio)],
63
+ )
64
+ material.add_property(MaterialPropertyType.TENSILE_STRENGTH, "TensileProp", Quantity(45))
65
+ design.add_material(material)
66
+ ```
67
+ ## Extrude the body from the sketch
68
+
69
+ Extrude the sketch to create the body and assign a material to it.
70
+
71
+ ```{code-cell} ipython3
72
+ # Extrude the sketch to create a Body
73
+ body = design.extrude_sketch("SingleBody", sketch, Quantity(10, UNITS.mm))
74
+
75
+ # Assign a material to a Body
76
+ body.assign_material(material)
77
+
78
+ body.plot()
79
+ ```
0 commit comments