Skip to content

Commit 38996be

Browse files
Update Modeling Setup Examples
1 parent 8284627 commit 38996be

File tree

4 files changed

+203
-169
lines changed

4 files changed

+203
-169
lines changed

examples/01-Modeling-Setup/Configurations.py

+24-17
Original file line numberDiff line numberDiff line change
@@ -23,41 +23,40 @@
2323
# any reason, this face position has changed or the object name in the target
2424
# design has changed, the boundary fails to apply.
2525

26-
# ## Perform required imports
26+
# ## Preparation
27+
# Import the required packages
2728

29+
# +
2830
import os
2931
import tempfile
32+
import time
3033

3134
import pyaedt
3235
from pyaedt.generic.general_methods import generate_unique_name
36+
# -
3337

34-
# Set constant values
38+
# Define constants
3539

3640
AEDT_VERSION = "2024.1"
37-
38-
# ## Set non-graphical mode
39-
40-
# You can set ``non_graphical`` either to ``True`` or ``False``.
41-
42-
non_graphical = False
41+
NG_MODE = False # Open Electronics UI when the application is launched.
4342

4443
# ## Create temporary directory
4544

46-
temp_dir = tempfile.TemporaryDirectory(suffix="_ansys")
45+
temp_dir = tempfile.TemporaryDirectory(suffix=".ansys")
4746

4847
# ## Download project
4948

5049
project_full_name = pyaedt.downloads.download_icepak(destination=temp_dir.name)
5150

5251
# ## Open project
53-
54-
# Open the project, and save it to the temporary folder.
52+
#
53+
# Open the Icepak project from the project folder.
5554

5655
ipk = pyaedt.Icepak(
5756
project=project_full_name,
5857
version=AEDT_VERSION,
5958
new_desktop=True,
60-
non_graphical=non_graphical,
59+
non_graphical=NG_MODE,
6160
)
6261
ipk.autosave_disable()
6362

@@ -99,23 +98,25 @@
9998
file_name=filename,
10099
file_path=ipk.working_directory,
101100
file_format=".step",
102-
object_list=[],
103-
removed_objects=[],
101+
assignment_to_export=[],
102+
assignment_to_remove=[],
104103
)
105104

106105
# ## Export configuration files
107106
#
108107
# Export the configuration files. You can optionally disable the export and
109108
# import sections. Supported formats are json and toml files
110109

111-
conf_file = ipk.configurations.export_config(os.path.join(ipk.working_directory, "config.toml"))
110+
conf_file = ipk.configurations.export_config(
111+
os.path.join(ipk.working_directory, "config.toml")
112+
)
112113
ipk.close_project()
113114

114115
# ## Create project
115116
#
116117
# Create an Icepak project and import the step.
117118

118-
new_project = os.path.join(temp_dir.name, generate_unique_name("example") + ".aedt")
119+
new_project = os.path.join(temp_dir.name, "example.aedt")
119120
app = pyaedt.Icepak(project=new_project)
120121
app.modeler.import_3d_cad(file_path)
121122

@@ -131,7 +132,13 @@
131132
# Close the project and release AEDT.
132133

133134
app.release_desktop()
135+
time.sleep(3) # Allow Electronics Desktop to shut down before cleaning the temporary project folder.
134136

135-
# ## Clean temporary directory
137+
# ## Cleanup
138+
#
139+
# All project files are saved in the folder ``temp_dir.name``.
140+
# If you've run this example as a Jupyter notebook you
141+
# can retrieve those project files. The following cell removes
142+
# all temporary files, including the project folder.
136143

137144
temp_dir.cleanup()

examples/01-Modeling-Setup/HFSS_CoordinateSystem.py

+80-66
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,32 @@
22
#
33
# This example shows how you can use PyAEDT to create and modify coordinate systems in the modeler.
44
#
5-
# ## Perform required imports
6-
#
7-
# Perform required imports
5+
# ## Preparation
6+
# Import the required packages
87

98
import tempfile
10-
9+
import time
1110
import pyaedt
11+
import os
1212

13-
# Set constant values
13+
# Define constants
1414

1515
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.
2317

2418
# ## Create temporary directory
2519

26-
temp_dir = tempfile.TemporaryDirectory(suffix="_ansys")
20+
temp_dir = tempfile.TemporaryDirectory(suffix=".ansys")
2721

2822
# ## Launch AEDT
2923

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)
3325

3426
# ## Insert HFSS design
3527
#
3628
# Insert an HFSS design with the default name.
3729

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")
4131
hfss = pyaedt.Hfss(project=project_name)
4232

4333
# ## Create coordinate system
@@ -57,7 +47,8 @@
5747
cs1.props["OriginY"] = 10
5848
cs1.props["OriginZ"] = 10
5949

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.
6152

6253
ypoint = [0, -1, 0]
6354
cs1.props["YAxisXvec"] = ypoint[0]
@@ -72,13 +63,16 @@
7263

7364
# ## Change coordinate system mode
7465
#
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+
#
7771
# Here ``1`` sets Euler angle ZXZ as the mode.
7872

7973
cs1.change_cs_mode(1)
8074

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.
8276

8377
cs1.props["Phi"] = "10deg"
8478
cs1.props["Theta"] = "22deg"
@@ -90,28 +84,32 @@
9084

9185
cs1.delete()
9286

93-
# ## Create coordinate system by defining axes
87+
# ## Define a new coordinate system
9488
#
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.
9791

9892
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],
10098
)
10199

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.
105101

106102
cs3 = hfss.modeler.create_coordinate_system(
107103
name="CS3", origin=[2, 2, 2], mode="zyz", phi=10, theta=20, psi=30
108104
)
109105

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"``.
111111
#
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.
115113

116114
cs4 = hfss.modeler.create_coordinate_system(
117115
name="CS4", origin=[1, 0, 0], reference_cs="CS3", mode="view", view="iso"
@@ -123,10 +121,10 @@
123121
# specify the axis and angle rotation, this data is automatically translated
124122
# to Euler angles.
125123

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+
)
127127

128-
# ## Create face coordinate system
129-
#
130128
# Face coordinate systems are bound to an object face.
131129
# First create a box and then define the face coordinate system on one of its
132130
# faces. To create the reference face for the face coordinate system, you must
@@ -138,29 +136,27 @@
138136
face=face, origin=face.edges[0], axis_position=face.edges[1], name="FCS1"
139137
)
140138

141-
# ## Create face coordinate system centered on face
142-
#
143139
# Create a face coordinate system centered on the face with the X axis pointing
144140
# to the edge vertex.
145141

146142
fcs2 = hfss.modeler.create_face_coordinate_system(
147143
face=face, origin=face, axis_position=face.edges[0].vertices[0], name="FCS2"
148144
)
149145

150-
# ## Swap X and Y axes of face coordinate system
151-
#
152146
# Swap the X axis and Y axis of the face coordinate system. The X axis is the
153147
# pointing ``axis_position`` by default. You can optionally select the Y axis.
154148

155149
fcs3 = hfss.modeler.create_face_coordinate_system(
156150
face=face, origin=face, axis_position=face.edges[0], axis="Y"
157151
)
158152

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+
160156
fcs3.props["WhichAxis"] = "X"
161157

162158

163-
# ## Apply a rotation around Z axis
159+
# ### Rotate the coordinate system
164160
#
165161
# Apply a rotation around the Z axis. The Z axis of a face coordinate system
166162
# is always orthogonal to the face. A rotation can be applied at definition.
@@ -170,11 +166,11 @@
170166
face=face, origin=face, axis_position=face.edges[1], rotation=10.3
171167
)
172168

173-
# ### Rotation can also be changed after coordinate system creation
169+
# Rotation can also be changed after coordinate system creation
174170

175171
fcs4.props["ZRotationAngle"] = "3deg"
176172

177-
# ## Apply offset to X and Y axes of face coordinate system
173+
# ### Offset the coordinate system
178174
#
179175
# Apply an offset to the X axis and Y axis of a face coordinate system.
180176
# The offset is in respect to the face coordinate system itself.
@@ -183,15 +179,15 @@
183179
face=face, origin=face, axis_position=face.edges[2], offset=[0.5, 0.3]
184180
)
185181

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.
187183

188184
fcs5.props["XOffset"] = "0.2mm"
189185
fcs5.props["YOffset"] = "0.1mm"
190186

191-
# ## Create coordinate system relative to face coordinate system
187+
# ### Dependent coordinate systems
192188
#
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.
195191

196192
face = box.faces[1]
197193
fcs6 = hfss.modeler.create_face_coordinate_system(
@@ -201,45 +197,59 @@
201197
name="CS_FCS", origin=[0, 0, 0], reference_cs=fcs6.name, mode="view", view="iso"
202198
)
203199

204-
# ## Create object coordinate system
200+
# ### Object coordinate systems
205201
#
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.
207205

208206
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",
210212
)
211213
obj_cs.rename("new_obj_cs")
212214

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.
216216

217217
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",
219223
)
220224
obj_cs_1.set_as_working_cs()
221225

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.
225227

226228
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",
228234
)
229235
new_obj_cs_2 = hfss.modeler.duplicate_coordinate_system_to_global(obj_cs_2)
230236
obj_cs_2.delete()
231237

232-
# ## Create object coordinate system
233-
#
234-
# Create object coordinate system with origin on vertex
238+
# Create object coordinate system with origin on vertex.
235239

236240
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",
238246
)
239247
obj_cs_3.props["MoveToEnd"] = False
240248
obj_cs_3.update()
241249

242-
# ## Get all coordinate systems
250+
# ### Get all coordinate systems
251+
#
252+
# All coordinate systems can easily be retrieved and subsequently manipulated.
243253

244254
css = hfss.modeler.coordinate_systems
245255
names = [i.name for i in css]
@@ -268,7 +278,11 @@
268278
# Close the project and release AEDT.
269279

270280
d.release_desktop()
281+
time.sleep(3)
271282

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.
273287

274288
temp_dir.cleanup()

0 commit comments

Comments
 (0)