Skip to content

Commit a941811

Browse files
authored
Merge branch 'main' into refacto/maxwell_examples
2 parents 2fff7dc + 62dcb1f commit a941811

File tree

4 files changed

+205
-169
lines changed

4 files changed

+205
-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

+82-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,17 @@
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+
#
68+
# - ``0`` for axis/position
69+
# - ``1`` for Euler angle ZXZ
70+
# - ``2`` for Euler angle ZYZ.
71+
#
7772
# Here ``1`` sets Euler angle ZXZ as the mode.
7873

7974
cs1.change_cs_mode(1)
8075

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

8378
cs1.props["Phi"] = "10deg"
8479
cs1.props["Theta"] = "22deg"
@@ -90,28 +85,33 @@
9085

9186
cs1.delete()
9287

93-
# ## Create coordinate system by defining axes
88+
# ## Define a new coordinate system
9489
#
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.
9792

9893
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],
10099
)
101100

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

106103
cs3 = hfss.modeler.create_coordinate_system(
107104
name="CS3", origin=[2, 2, 2], mode="zyz", phi=10, theta=20, psi=30
108105
)
109106

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"``.
111113
#
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.
115115

116116
cs4 = hfss.modeler.create_coordinate_system(
117117
name="CS4", origin=[1, 0, 0], reference_cs="CS3", mode="view", view="iso"
@@ -123,10 +123,10 @@
123123
# specify the axis and angle rotation, this data is automatically translated
124124
# to Euler angles.
125125

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

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

141-
# ## Create face coordinate system centered on face
142-
#
143141
# Create a face coordinate system centered on the face with the X axis pointing
144142
# to the edge vertex.
145143

146144
fcs2 = hfss.modeler.create_face_coordinate_system(
147145
face=face, origin=face, axis_position=face.edges[0].vertices[0], name="FCS2"
148146
)
149147

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

155151
fcs3 = hfss.modeler.create_face_coordinate_system(
156152
face=face, origin=face, axis_position=face.edges[0], axis="Y"
157153
)
158154

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

162160

163-
# ## Apply a rotation around Z axis
161+
# ### Rotate the coordinate system
164162
#
165163
# Apply a rotation around the Z axis. The Z axis of a face coordinate system
166164
# is always orthogonal to the face. A rotation can be applied at definition.
@@ -170,11 +168,11 @@
170168
face=face, origin=face, axis_position=face.edges[1], rotation=10.3
171169
)
172170

173-
# ### Rotation can also be changed after coordinate system creation
171+
# Rotation can also be changed after coordinate system creation
174172

175173
fcs4.props["ZRotationAngle"] = "3deg"
176174

177-
# ## Apply offset to X and Y axes of face coordinate system
175+
# ### Offset the coordinate system
178176
#
179177
# Apply an offset to the X axis and Y axis of a face coordinate system.
180178
# The offset is in respect to the face coordinate system itself.
@@ -183,15 +181,15 @@
183181
face=face, origin=face, axis_position=face.edges[2], offset=[0.5, 0.3]
184182
)
185183

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

188186
fcs5.props["XOffset"] = "0.2mm"
189187
fcs5.props["YOffset"] = "0.1mm"
190188

191-
# ## Create coordinate system relative to face coordinate system
189+
# ### Dependent coordinate systems
192190
#
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.
195193

196194
face = box.faces[1]
197195
fcs6 = hfss.modeler.create_face_coordinate_system(
@@ -201,45 +199,59 @@
201199
name="CS_FCS", origin=[0, 0, 0], reference_cs=fcs6.name, mode="view", view="iso"
202200
)
203201

204-
# ## Create object coordinate system
202+
# ### Object coordinate systems
205203
#
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.
207207

208208
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",
210214
)
211215
obj_cs.rename("new_obj_cs")
212216

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

217219
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",
219225
)
220226
obj_cs_1.set_as_working_cs()
221227

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

226230
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",
228236
)
229237
new_obj_cs_2 = hfss.modeler.duplicate_coordinate_system_to_global(obj_cs_2)
230238
obj_cs_2.delete()
231239

232-
# ## Create object coordinate system
233-
#
234-
# Create object coordinate system with origin on vertex
240+
# Create object coordinate system with origin on vertex.
235241

236242
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",
238248
)
239249
obj_cs_3.props["MoveToEnd"] = False
240250
obj_cs_3.update()
241251

242-
# ## Get all coordinate systems
252+
# ### Get all coordinate systems
253+
#
254+
# All coordinate systems can easily be retrieved and subsequently manipulated.
243255

244256
css = hfss.modeler.coordinate_systems
245257
names = [i.name for i in css]
@@ -268,7 +280,11 @@
268280
# Close the project and release AEDT.
269281

270282
d.release_desktop()
283+
time.sleep(3)
271284

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

274290
temp_dir.cleanup()

0 commit comments

Comments
 (0)