|
2 | 2 | #
|
3 | 3 | # This example shows how you can use PyAEDT to create and modify coordinate systems in the modeler.
|
4 | 4 | #
|
5 |
| -# ## Perform required imports |
6 |
| -# |
7 |
| -# Perform required imports |
| 5 | +# ## Preparation |
| 6 | +# Import the required packages |
8 | 7 |
|
9 | 8 | import tempfile
|
10 |
| - |
| 9 | +import time |
11 | 10 | import pyaedt
|
| 11 | +import os |
12 | 12 |
|
13 |
| -# Set constant values |
| 13 | +# Define constants |
14 | 14 |
|
15 | 15 | AEDT_VERSION = "2024.1"
|
16 |
| - |
17 |
| -# ## Set non-graphical mode |
18 |
| - |
19 |
| -# Set non-graphical mode. |
20 |
| -# You can set ``non_graphical`` either to ``True`` or ``False``. |
21 |
| - |
22 |
| -non_graphical = False |
| 16 | +NG_MODE = False # Open Electronics UI when the application is launched. |
23 | 17 |
|
24 | 18 | # ## Create temporary directory
|
25 | 19 |
|
26 |
| -temp_dir = tempfile.TemporaryDirectory(suffix="_ansys") |
| 20 | +temp_dir = tempfile.TemporaryDirectory(suffix=".ansys") |
27 | 21 |
|
28 | 22 | # ## Launch AEDT
|
29 | 23 |
|
30 |
| -d = pyaedt.launch_desktop( |
31 |
| - version=AEDT_VERSION, non_graphical=non_graphical, new_desktop=True |
32 |
| -) |
| 24 | +d = pyaedt.launch_desktop(version=AEDT_VERSION, non_graphical=NG_MODE, new_desktop=True) |
33 | 25 |
|
34 | 26 | # ## Insert HFSS design
|
35 | 27 | #
|
36 | 28 | # Insert an HFSS design with the default name.
|
37 | 29 |
|
38 |
| -project_name = pyaedt.generate_unique_project_name( |
39 |
| - rootname=temp_dir.name, project_name="CoordSysDemo" |
40 |
| -) |
| 30 | +project_name = os.path.join(temp_dir.name, "CoordSysDemo.aedt") |
41 | 31 | hfss = pyaedt.Hfss(project=project_name)
|
42 | 32 |
|
43 | 33 | # ## Create coordinate system
|
|
57 | 47 | cs1.props["OriginY"] = 10
|
58 | 48 | cs1.props["OriginZ"] = 10
|
59 | 49 |
|
60 |
| -# Pointing vectors can be changed |
| 50 | +# The orientation of the coordinate system can be modified by |
| 51 | +# updating the direction vectors for the coordinate system. |
61 | 52 |
|
62 | 53 | ypoint = [0, -1, 0]
|
63 | 54 | cs1.props["YAxisXvec"] = ypoint[0]
|
|
72 | 63 |
|
73 | 64 | # ## Change coordinate system mode
|
74 | 65 | #
|
75 |
| -# Use the ``change_cs_mode`` method to change the mode. Options are ``0`` |
76 |
| -# for axis/position, ``1`` for Euler angle ZXZ, and ``2`` for Euler angle ZYZ. |
| 66 | +# Use the ``change_cs_mode`` method to change the mode. Options are |
| 67 | +# - ``0`` for axis/position |
| 68 | +# - ``1`` for Euler angle ZXZ |
| 69 | +# - ``2`` for Euler angle ZYZ. |
| 70 | +# |
77 | 71 | # Here ``1`` sets Euler angle ZXZ as the mode.
|
78 | 72 |
|
79 | 73 | cs1.change_cs_mode(1)
|
80 | 74 |
|
81 |
| -# In the new mode, these properties can be edited |
| 75 | +# The following lines use the ZXZ Euler angle definition to rotate the coordinate system. |
82 | 76 |
|
83 | 77 | cs1.props["Phi"] = "10deg"
|
84 | 78 | cs1.props["Theta"] = "22deg"
|
|
90 | 84 |
|
91 | 85 | cs1.delete()
|
92 | 86 |
|
93 |
| -# ## Create coordinate system by defining axes |
| 87 | +# ## Define a new coordinate system |
94 | 88 | #
|
95 |
| -# Create a coordinate system by defining the axes. During creation, you can |
96 |
| -# specify all coordinate system properties. |
| 89 | +# Create a coordinate system by defining the axes. You can |
| 90 | +# specify all coordinate system properties as shown here. |
97 | 91 |
|
98 | 92 | cs2 = hfss.modeler.create_coordinate_system(
|
99 |
| - name="CS2", origin=[1, 2, 3.5], mode="axis", x_pointing=[1, 0, 1], y_pointing=[0, -1, 0] |
| 93 | + name="CS2", |
| 94 | + origin=[1, 2, 3.5], |
| 95 | + mode="axis", |
| 96 | + x_pointing=[1, 0, 1], |
| 97 | + y_pointing=[0, -1, 0], |
100 | 98 | )
|
101 | 99 |
|
102 |
| -# ## Create coordinate system by defining Euler angles |
103 |
| -# |
104 |
| -# Create a coordinate system by defining Euler angles. |
| 100 | +# A new coordinate system can also be created based on the Euler angle convention. |
105 | 101 |
|
106 | 102 | cs3 = hfss.modeler.create_coordinate_system(
|
107 | 103 | name="CS3", origin=[2, 2, 2], mode="zyz", phi=10, theta=20, psi=30
|
108 | 104 | )
|
109 | 105 |
|
110 |
| -# ## Create coordinate system by defining view |
| 106 | +# Create a coordinate system that is defined by standard views in the modeler. The options are |
| 107 | +# - ``"iso"`` |
| 108 | +# - ``"XY"`` |
| 109 | +# - ``"XZ"`` |
| 110 | +# - ``"XY"``. |
111 | 111 | #
|
112 |
| -# Create a coordinate system by defining the view. Options are ``"iso"``, |
113 |
| -# ``"XY"``, ``"XZ"``, and ``"XY"``. Here ``"iso"`` is specified. |
114 |
| -# The axes are set automatically. |
| 112 | +# Here ``"iso"`` is specified. The axes are set automatically. |
115 | 113 |
|
116 | 114 | cs4 = hfss.modeler.create_coordinate_system(
|
117 | 115 | name="CS4", origin=[1, 0, 0], reference_cs="CS3", mode="view", view="iso"
|
|
123 | 121 | # specify the axis and angle rotation, this data is automatically translated
|
124 | 122 | # to Euler angles.
|
125 | 123 |
|
126 |
| -cs5 = hfss.modeler.create_coordinate_system(name="CS5", mode="axisrotation", u=[1, 0, 0], theta=123) |
| 124 | +cs5 = hfss.modeler.create_coordinate_system( |
| 125 | + name="CS5", mode="axisrotation", u=[1, 0, 0], theta=123 |
| 126 | +) |
127 | 127 |
|
128 |
| -# ## Create face coordinate system |
129 |
| -# |
130 | 128 | # Face coordinate systems are bound to an object face.
|
131 | 129 | # First create a box and then define the face coordinate system on one of its
|
132 | 130 | # faces. To create the reference face for the face coordinate system, you must
|
|
138 | 136 | face=face, origin=face.edges[0], axis_position=face.edges[1], name="FCS1"
|
139 | 137 | )
|
140 | 138 |
|
141 |
| -# ## Create face coordinate system centered on face |
142 |
| -# |
143 | 139 | # Create a face coordinate system centered on the face with the X axis pointing
|
144 | 140 | # to the edge vertex.
|
145 | 141 |
|
146 | 142 | fcs2 = hfss.modeler.create_face_coordinate_system(
|
147 | 143 | face=face, origin=face, axis_position=face.edges[0].vertices[0], name="FCS2"
|
148 | 144 | )
|
149 | 145 |
|
150 |
| -# ## Swap X and Y axes of face coordinate system |
151 |
| -# |
152 | 146 | # Swap the X axis and Y axis of the face coordinate system. The X axis is the
|
153 | 147 | # pointing ``axis_position`` by default. You can optionally select the Y axis.
|
154 | 148 |
|
155 | 149 | fcs3 = hfss.modeler.create_face_coordinate_system(
|
156 | 150 | face=face, origin=face, axis_position=face.edges[0], axis="Y"
|
157 | 151 | )
|
158 | 152 |
|
159 |
| -# Axis can also be changed after coordinate system creation |
| 153 | +# The face coordinate system can also be rotated by changing the |
| 154 | +# reference axis. |
| 155 | + |
160 | 156 | fcs3.props["WhichAxis"] = "X"
|
161 | 157 |
|
162 | 158 |
|
163 |
| -# ## Apply a rotation around Z axis |
| 159 | +# ### Rotate the coordinate system |
164 | 160 | #
|
165 | 161 | # Apply a rotation around the Z axis. The Z axis of a face coordinate system
|
166 | 162 | # is always orthogonal to the face. A rotation can be applied at definition.
|
|
170 | 166 | face=face, origin=face, axis_position=face.edges[1], rotation=10.3
|
171 | 167 | )
|
172 | 168 |
|
173 |
| -# ### Rotation can also be changed after coordinate system creation |
| 169 | +# Rotation can also be changed after coordinate system creation |
174 | 170 |
|
175 | 171 | fcs4.props["ZRotationAngle"] = "3deg"
|
176 | 172 |
|
177 |
| -# ## Apply offset to X and Y axes of face coordinate system |
| 173 | +# ### Offset the coordinate system |
178 | 174 | #
|
179 | 175 | # Apply an offset to the X axis and Y axis of a face coordinate system.
|
180 | 176 | # The offset is in respect to the face coordinate system itself.
|
|
183 | 179 | face=face, origin=face, axis_position=face.edges[2], offset=[0.5, 0.3]
|
184 | 180 | )
|
185 | 181 |
|
186 |
| -# ### The offset can also be changed after the coordinate system is created. |
| 182 | +# The offset can be changed after the coordinate system has been created. |
187 | 183 |
|
188 | 184 | fcs5.props["XOffset"] = "0.2mm"
|
189 | 185 | fcs5.props["YOffset"] = "0.1mm"
|
190 | 186 |
|
191 |
| -# ## Create coordinate system relative to face coordinate system |
| 187 | +# ### Dependent coordinate systems |
192 | 188 | #
|
193 |
| -# Create a coordinate system relative to a face coordinate system. Coordinate |
194 |
| -# systems and face coordinate systems interact with each other. |
| 189 | +# The use of dependent coordinate systems can simplify model creation. The following |
| 190 | +# cell demonstrates how to create a coordinate system whose reference is the face coordinate system. |
195 | 191 |
|
196 | 192 | face = box.faces[1]
|
197 | 193 | fcs6 = hfss.modeler.create_face_coordinate_system(
|
|
201 | 197 | name="CS_FCS", origin=[0, 0, 0], reference_cs=fcs6.name, mode="view", view="iso"
|
202 | 198 | )
|
203 | 199 |
|
204 |
| -# ## Create object coordinate system |
| 200 | +# ### Object coordinate systems |
205 | 201 | #
|
206 |
| -# Create object coordinate system with origin on face |
| 202 | +# A coordinate system can also be defined relative to elements |
| 203 | +# belonging to an object. For example, the coordinate system can be |
| 204 | +# connected to an object face. |
207 | 205 |
|
208 | 206 | obj_cs = hfss.modeler.create_object_coordinate_system(
|
209 |
| - obj=box, origin=box.faces[0], x_axis=box.edges[0], y_axis=[0, 0, 0], name="box_obj_cs" |
| 207 | + assignment=box, |
| 208 | + origin=box.faces[0], |
| 209 | + x_axis=box.edges[0], |
| 210 | + y_axis=[0, 0, 0], |
| 211 | + name="box_obj_cs", |
210 | 212 | )
|
211 | 213 | obj_cs.rename("new_obj_cs")
|
212 | 214 |
|
213 |
| -# ## Create object coordinate system |
214 |
| -# |
215 |
| -# Create object coordinate system with origin on edge |
| 215 | +# Create an object coordinate system whose origin is linked to the edge of an object. |
216 | 216 |
|
217 | 217 | obj_cs_1 = hfss.modeler.create_object_coordinate_system(
|
218 |
| - obj=box.name, origin=box.edges[0], x_axis=[1, 0, 0], y_axis=[0, 1, 0], name="obj_cs_1" |
| 218 | + assignment=box.name, |
| 219 | + origin=box.edges[0], |
| 220 | + x_axis=[1, 0, 0], |
| 221 | + y_axis=[0, 1, 0], |
| 222 | + name="obj_cs_1", |
219 | 223 | )
|
220 | 224 | obj_cs_1.set_as_working_cs()
|
221 | 225 |
|
222 |
| -# ## Create object coordinate system |
223 |
| -# |
224 |
| -# Create object coordinate system with origin specified on point |
| 226 | +# Create object coordinate system with origin specified on a point within an object. |
225 | 227 |
|
226 | 228 | obj_cs_2 = hfss.modeler.create_object_coordinate_system(
|
227 |
| - obj=box.name, origin=[0, 0.8, 0], x_axis=[1, 0, 0], y_axis=[0, 1, 0], name="obj_cs_2" |
| 229 | + assignment=box.name, |
| 230 | + origin=[0, 0.8, 0], |
| 231 | + x_axis=[1, 0, 0], |
| 232 | + y_axis=[0, 1, 0], |
| 233 | + name="obj_cs_2", |
228 | 234 | )
|
229 | 235 | new_obj_cs_2 = hfss.modeler.duplicate_coordinate_system_to_global(obj_cs_2)
|
230 | 236 | obj_cs_2.delete()
|
231 | 237 |
|
232 |
| -# ## Create object coordinate system |
233 |
| -# |
234 |
| -# Create object coordinate system with origin on vertex |
| 238 | +# Create object coordinate system with origin on vertex. |
235 | 239 |
|
236 | 240 | obj_cs_3 = hfss.modeler.create_object_coordinate_system(
|
237 |
| - obj=box.name, origin=box.vertices[1], x_axis=box.faces[2], y_axis=box.faces[4], name="obj_cs_3" |
| 241 | + obj=box.name, |
| 242 | + origin=box.vertices[1], |
| 243 | + x_axis=box.faces[2], |
| 244 | + y_axis=box.faces[4], |
| 245 | + name="obj_cs_3", |
238 | 246 | )
|
239 | 247 | obj_cs_3.props["MoveToEnd"] = False
|
240 | 248 | obj_cs_3.update()
|
241 | 249 |
|
242 |
| -# ## Get all coordinate systems |
| 250 | +# ### Get all coordinate systems |
| 251 | +# |
| 252 | +# All coordinate systems can easily be retrieved and subsequently manipulated. |
243 | 253 |
|
244 | 254 | css = hfss.modeler.coordinate_systems
|
245 | 255 | names = [i.name for i in css]
|
|
268 | 278 | # Close the project and release AEDT.
|
269 | 279 |
|
270 | 280 | d.release_desktop()
|
| 281 | +time.sleep(3) |
271 | 282 |
|
272 |
| -# ## Clean temporary directory |
| 283 | +# ## Cleanup |
| 284 | +# |
| 285 | +# All project files are saved in the folder ``temp_dir.name``. If you've run this example as a Jupyter notebook you |
| 286 | +# can retrieve those project files. The following cell removes all temporary files, including the project folder. |
273 | 287 |
|
274 | 288 | temp_dir.cleanup()
|
0 commit comments