|
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 | +# |
| 68 | +# - ``0`` for axis/position |
| 69 | +# - ``1`` for Euler angle ZXZ |
| 70 | +# - ``2`` for Euler angle ZYZ. |
| 71 | +# |
77 | 72 | # Here ``1`` sets Euler angle ZXZ as the mode.
|
78 | 73 |
|
79 | 74 | cs1.change_cs_mode(1)
|
80 | 75 |
|
81 |
| -# In the new mode, these properties can be edited |
| 76 | +# The following lines use the ZXZ Euler angle definition to rotate the coordinate system. |
82 | 77 |
|
83 | 78 | cs1.props["Phi"] = "10deg"
|
84 | 79 | cs1.props["Theta"] = "22deg"
|
|
90 | 85 |
|
91 | 86 | cs1.delete()
|
92 | 87 |
|
93 |
| -# ## Create coordinate system by defining axes |
| 88 | +# ## Define a new coordinate system |
94 | 89 | #
|
95 |
| -# Create a coordinate system by defining the axes. During creation, you can |
96 |
| -# specify all coordinate system properties. |
| 90 | +# Create a coordinate system by defining the axes. You can |
| 91 | +# specify all coordinate system properties as shown here. |
97 | 92 |
|
98 | 93 | 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] |
| 94 | + name="CS2", |
| 95 | + origin=[1, 2, 3.5], |
| 96 | + mode="axis", |
| 97 | + x_pointing=[1, 0, 1], |
| 98 | + y_pointing=[0, -1, 0], |
100 | 99 | )
|
101 | 100 |
|
102 |
| -# ## Create coordinate system by defining Euler angles |
103 |
| -# |
104 |
| -# Create a coordinate system by defining Euler angles. |
| 101 | +# A new coordinate system can also be created based on the Euler angle convention. |
105 | 102 |
|
106 | 103 | cs3 = hfss.modeler.create_coordinate_system(
|
107 | 104 | name="CS3", origin=[2, 2, 2], mode="zyz", phi=10, theta=20, psi=30
|
108 | 105 | )
|
109 | 106 |
|
110 |
| -# ## Create coordinate system by defining view |
| 107 | +# Create a coordinate system that is defined by standard views in the modeler. The options are |
| 108 | +# |
| 109 | +# - ``"iso"`` |
| 110 | +# - ``"XY"`` |
| 111 | +# - ``"XZ"`` |
| 112 | +# - ``"XY"``. |
111 | 113 | #
|
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. |
| 114 | +# Here ``"iso"`` is specified. The axes are set automatically. |
115 | 115 |
|
116 | 116 | cs4 = hfss.modeler.create_coordinate_system(
|
117 | 117 | name="CS4", origin=[1, 0, 0], reference_cs="CS3", mode="view", view="iso"
|
|
123 | 123 | # specify the axis and angle rotation, this data is automatically translated
|
124 | 124 | # to Euler angles.
|
125 | 125 |
|
126 |
| -cs5 = hfss.modeler.create_coordinate_system(name="CS5", mode="axisrotation", u=[1, 0, 0], theta=123) |
| 126 | +cs5 = hfss.modeler.create_coordinate_system( |
| 127 | + name="CS5", mode="axisrotation", u=[1, 0, 0], theta=123 |
| 128 | +) |
127 | 129 |
|
128 |
| -# ## Create face coordinate system |
129 |
| -# |
130 | 130 | # Face coordinate systems are bound to an object face.
|
131 | 131 | # First create a box and then define the face coordinate system on one of its
|
132 | 132 | # faces. To create the reference face for the face coordinate system, you must
|
|
138 | 138 | face=face, origin=face.edges[0], axis_position=face.edges[1], name="FCS1"
|
139 | 139 | )
|
140 | 140 |
|
141 |
| -# ## Create face coordinate system centered on face |
142 |
| -# |
143 | 141 | # Create a face coordinate system centered on the face with the X axis pointing
|
144 | 142 | # to the edge vertex.
|
145 | 143 |
|
146 | 144 | fcs2 = hfss.modeler.create_face_coordinate_system(
|
147 | 145 | face=face, origin=face, axis_position=face.edges[0].vertices[0], name="FCS2"
|
148 | 146 | )
|
149 | 147 |
|
150 |
| -# ## Swap X and Y axes of face coordinate system |
151 |
| -# |
152 | 148 | # Swap the X axis and Y axis of the face coordinate system. The X axis is the
|
153 | 149 | # pointing ``axis_position`` by default. You can optionally select the Y axis.
|
154 | 150 |
|
155 | 151 | fcs3 = hfss.modeler.create_face_coordinate_system(
|
156 | 152 | face=face, origin=face, axis_position=face.edges[0], axis="Y"
|
157 | 153 | )
|
158 | 154 |
|
159 |
| -# Axis can also be changed after coordinate system creation |
| 155 | +# The face coordinate system can also be rotated by changing the |
| 156 | +# reference axis. |
| 157 | + |
160 | 158 | fcs3.props["WhichAxis"] = "X"
|
161 | 159 |
|
162 | 160 |
|
163 |
| -# ## Apply a rotation around Z axis |
| 161 | +# ### Rotate the coordinate system |
164 | 162 | #
|
165 | 163 | # Apply a rotation around the Z axis. The Z axis of a face coordinate system
|
166 | 164 | # is always orthogonal to the face. A rotation can be applied at definition.
|
|
170 | 168 | face=face, origin=face, axis_position=face.edges[1], rotation=10.3
|
171 | 169 | )
|
172 | 170 |
|
173 |
| -# ### Rotation can also be changed after coordinate system creation |
| 171 | +# Rotation can also be changed after coordinate system creation |
174 | 172 |
|
175 | 173 | fcs4.props["ZRotationAngle"] = "3deg"
|
176 | 174 |
|
177 |
| -# ## Apply offset to X and Y axes of face coordinate system |
| 175 | +# ### Offset the coordinate system |
178 | 176 | #
|
179 | 177 | # Apply an offset to the X axis and Y axis of a face coordinate system.
|
180 | 178 | # The offset is in respect to the face coordinate system itself.
|
|
183 | 181 | face=face, origin=face, axis_position=face.edges[2], offset=[0.5, 0.3]
|
184 | 182 | )
|
185 | 183 |
|
186 |
| -# ### The offset can also be changed after the coordinate system is created. |
| 184 | +# The offset can be changed after the coordinate system has been created. |
187 | 185 |
|
188 | 186 | fcs5.props["XOffset"] = "0.2mm"
|
189 | 187 | fcs5.props["YOffset"] = "0.1mm"
|
190 | 188 |
|
191 |
| -# ## Create coordinate system relative to face coordinate system |
| 189 | +# ### Dependent coordinate systems |
192 | 190 | #
|
193 |
| -# Create a coordinate system relative to a face coordinate system. Coordinate |
194 |
| -# systems and face coordinate systems interact with each other. |
| 191 | +# The use of dependent coordinate systems can simplify model creation. The following |
| 192 | +# cell demonstrates how to create a coordinate system whose reference is the face coordinate system. |
195 | 193 |
|
196 | 194 | face = box.faces[1]
|
197 | 195 | fcs6 = hfss.modeler.create_face_coordinate_system(
|
|
201 | 199 | name="CS_FCS", origin=[0, 0, 0], reference_cs=fcs6.name, mode="view", view="iso"
|
202 | 200 | )
|
203 | 201 |
|
204 |
| -# ## Create object coordinate system |
| 202 | +# ### Object coordinate systems |
205 | 203 | #
|
206 |
| -# Create object coordinate system with origin on face |
| 204 | +# A coordinate system can also be defined relative to elements |
| 205 | +# belonging to an object. For example, the coordinate system can be |
| 206 | +# connected to an object face. |
207 | 207 |
|
208 | 208 | 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" |
| 209 | + assignment=box, |
| 210 | + origin=box.faces[0], |
| 211 | + x_axis=box.edges[0], |
| 212 | + y_axis=[0, 0, 0], |
| 213 | + name="box_obj_cs", |
210 | 214 | )
|
211 | 215 | obj_cs.rename("new_obj_cs")
|
212 | 216 |
|
213 |
| -# ## Create object coordinate system |
214 |
| -# |
215 |
| -# Create object coordinate system with origin on edge |
| 217 | +# Create an object coordinate system whose origin is linked to the edge of an object. |
216 | 218 |
|
217 | 219 | 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" |
| 220 | + assignment=box.name, |
| 221 | + origin=box.edges[0], |
| 222 | + x_axis=[1, 0, 0], |
| 223 | + y_axis=[0, 1, 0], |
| 224 | + name="obj_cs_1", |
219 | 225 | )
|
220 | 226 | obj_cs_1.set_as_working_cs()
|
221 | 227 |
|
222 |
| -# ## Create object coordinate system |
223 |
| -# |
224 |
| -# Create object coordinate system with origin specified on point |
| 228 | +# Create object coordinate system with origin specified on a point within an object. |
225 | 229 |
|
226 | 230 | 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" |
| 231 | + assignment=box.name, |
| 232 | + origin=[0, 0.8, 0], |
| 233 | + x_axis=[1, 0, 0], |
| 234 | + y_axis=[0, 1, 0], |
| 235 | + name="obj_cs_2", |
228 | 236 | )
|
229 | 237 | new_obj_cs_2 = hfss.modeler.duplicate_coordinate_system_to_global(obj_cs_2)
|
230 | 238 | obj_cs_2.delete()
|
231 | 239 |
|
232 |
| -# ## Create object coordinate system |
233 |
| -# |
234 |
| -# Create object coordinate system with origin on vertex |
| 240 | +# Create object coordinate system with origin on vertex. |
235 | 241 |
|
236 | 242 | 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" |
| 243 | + obj=box.name, |
| 244 | + origin=box.vertices[1], |
| 245 | + x_axis=box.faces[2], |
| 246 | + y_axis=box.faces[4], |
| 247 | + name="obj_cs_3", |
238 | 248 | )
|
239 | 249 | obj_cs_3.props["MoveToEnd"] = False
|
240 | 250 | obj_cs_3.update()
|
241 | 251 |
|
242 |
| -# ## Get all coordinate systems |
| 252 | +# ### Get all coordinate systems |
| 253 | +# |
| 254 | +# All coordinate systems can easily be retrieved and subsequently manipulated. |
243 | 255 |
|
244 | 256 | css = hfss.modeler.coordinate_systems
|
245 | 257 | names = [i.name for i in css]
|
|
268 | 280 | # Close the project and release AEDT.
|
269 | 281 |
|
270 | 282 | d.release_desktop()
|
| 283 | +time.sleep(3) |
271 | 284 |
|
272 |
| -# ## Clean temporary directory |
| 285 | +# ## Cleanup |
| 286 | +# |
| 287 | +# All project files are saved in the folder ``temp_dir.name``. If you've run this example as a Jupyter notebook you |
| 288 | +# can retrieve those project files. The following cell removes all temporary files, including the project folder. |
273 | 289 |
|
274 | 290 | temp_dir.cleanup()
|
0 commit comments