-
Notifications
You must be signed in to change notification settings - Fork 146
/
Copy pathDesign.py
4045 lines (3463 loc) · 135 KB
/
Design.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
This module contains these classes: ``Design``.
This module provides all functionalities for basic project information and objects.
These classes are inherited in the main tool class.
"""
from __future__ import absolute_import # noreorder
from collections import OrderedDict
import gc
import json
import os
import random
import re
import shutil
import string
import sys
import threading
import time
import warnings
from pyaedt.application.Variables import DataSet
from pyaedt.application.Variables import VariableManager
from pyaedt.application.Variables import decompose_variable_value
from pyaedt.application.aedt_objects import AedtObjects
from pyaedt.application.design_solutions import DesignSolution
from pyaedt.application.design_solutions import HFSSDesignSolution
from pyaedt.application.design_solutions import IcepakDesignSolution
from pyaedt.application.design_solutions import Maxwell2DDesignSolution
from pyaedt.application.design_solutions import RmXprtDesignSolution
from pyaedt.application.design_solutions import model_names
from pyaedt.application.design_solutions import solutions_defaults
from pyaedt.desktop import _init_desktop_from_design
from pyaedt.desktop import exception_to_desktop
from pyaedt.desktop import get_version_env_variable
from pyaedt.generic.DataHandlers import variation_string_to_dict
from pyaedt.generic.LoadAEDTFile import load_entire_aedt_file
from pyaedt.generic.constants import AEDT_UNITS
from pyaedt.generic.constants import unit_system
from pyaedt.generic.general_methods import check_and_download_file
from pyaedt.generic.general_methods import generate_unique_name
from pyaedt.generic.general_methods import is_ironpython
from pyaedt.generic.general_methods import is_project_locked
from pyaedt.generic.general_methods import is_windows
from pyaedt.generic.general_methods import open_file
from pyaedt.generic.general_methods import pyaedt_function_handler
from pyaedt.generic.general_methods import read_csv
from pyaedt.generic.general_methods import read_tab
from pyaedt.generic.general_methods import read_xlsx
from pyaedt.generic.general_methods import settings
from pyaedt.generic.general_methods import write_csv
from pyaedt.modules.Boundary import BoundaryObject
from pyaedt.modules.Boundary import MaxwellParameters
from pyaedt.modules.Boundary import NetworkObject
if sys.version_info.major > 2:
import base64
def load_aedt_thread(project_path):
pp = load_entire_aedt_file(project_path)
settings._project_properties[os.path.normpath(project_path)] = pp
settings._project_time_stamp = os.path.getmtime(project_path)
class Design(AedtObjects):
"""Contains all functions and objects connected to the active project and design.
This class is inherited in the caller application and is accessible through it (for
example, ``hfss.method_name``.
Parameters
----------
design_type : str
Type of the design.
project_name : str, optional
Name of the project to select or the full path to the project
or AEDTZ archive to open. The default is ``None``, in which
case an attempt is made to get an active project. If no
projects are present, an empty project is created.
design_name : str, optional
Name of the design to select. The default is ``None``, in
which case an attempt is made to get an active design. If no
designs are present, an empty design is created.
solution_type : str, optional
Solution type to apply to the design. The default is
``None``, in which case the default type is applied.
specified_version : str, int, float, optional
Version of AEDT to use. The default is ``None``, in which case
the active version or latest installed version is used.
non_graphical : bool, optional
Whether to run AEDT in non-graphical mode. The default
is ``False``, in which case AEDT launches in graphical mode.
new_desktop_session : bool, optional
Whether to launch an instance of AEDT in a new thread, even if
another instance of the ``specified_version`` is active on the
machine. The default is ``False``.
close_on_exit : bool, optional
Whether to release AEDT on exit. The default is ``False``.
student_version : bool, optional
Whether to enable the student version of AEDT. The default
is ``False``.
aedt_process_id : int, optional
Only used when ``new_desktop_session = False``, specifies by process ID which instance
of Electronics Desktop to point PyAEDT at.
"""
@property
def _pyaedt_details(self):
import platform
from pyaedt import __version__ as pyaedt_version
_p_dets = {
"PyAEDT Version": pyaedt_version,
"Product": "Ansys Electronics Desktop {}".format(settings.aedt_version),
"Design Type": self.design_type,
"Solution Type": self.solution_type,
"Project Name": self.project_name,
"Design Name": self.design_name,
"Project Path": "",
}
if self._oproject:
_p_dets["Project Path"] = self.project_file
_p_dets["Platform"] = platform.platform()
_p_dets["Python Version"] = platform.python_version()
_p_dets["AEDT Process ID"] = self.desktop_class.aedt_process_id
_p_dets["AEDT GRPC Port"] = self.desktop_class.port
return _p_dets
def __str__(self):
return "\n".join(
[
"{}:".format(each_name).ljust(25) + "{}".format(each_attr).ljust(25)
for each_name, each_attr in self._pyaedt_details.items()
]
)
def __exit__(self, ex_type, ex_value, ex_traceback):
if ex_type:
exception_to_desktop(ex_value, ex_traceback)
if self._desktop_class._connected_app_instances > 0: # pragma: no cover
self._desktop_class._connected_app_instances -= 1
if self._desktop_class._connected_app_instances <= 0 and self._desktop_class._initialized_from_design:
self.release_desktop(self.close_on_exit, self.close_on_exit)
def __enter__(self): # pragma: no cover
self._desktop_class._connected_app_instances += 1
return self
@pyaedt_function_handler()
def __getitem__(self, variable_name):
return self.variable_manager[variable_name].expression
@pyaedt_function_handler()
def __setitem__(self, variable_name, variable_value):
self.variable_manager[variable_name] = variable_value
return True
@property
def info(self):
"""Dictionary of the PyAEDT session information.
Returns
-------
dict
"""
return self._pyaedt_details
def _init_design(self, project_name, design_name, solution_type=None):
# calls the method from the application class
self._init_from_design(
projectname=project_name,
designname=design_name,
solution_type=solution_type,
specified_version=settings.aedt_version,
non_graphical=self._desktop_class.non_graphical,
new_desktop_session=False,
close_on_exit=self.close_on_exit,
student_version=self.student_version,
machine=self._desktop_class.machine,
port=self._desktop_class.port,
)
def __init__(
self,
design_type,
project_name=None,
design_name=None,
solution_type=None,
specified_version=None,
non_graphical=False,
new_desktop_session=False,
close_on_exit=False,
student_version=False,
machine="",
port=0,
aedt_process_id=None,
):
self.__t = None
if (
not is_ironpython
and project_name
and os.path.exists(project_name)
and (os.path.splitext(project_name)[1] == ".aedt" or os.path.splitext(project_name)[1] == ".a3dcomp")
):
self.__t = threading.Thread(target=load_aedt_thread, args=(project_name,), daemon=True)
self.__t.start()
self._init_variables()
self._design_type = design_type
self.last_run_log = ""
self.last_run_job = ""
self._design_dictionary = None
# Get Desktop from global Desktop Environment
self._project_dictionary = OrderedDict()
self._boundaries = {}
self._project_datasets = {}
self._design_datasets = {}
self.close_on_exit = close_on_exit
self._desktop_class = None
self._desktop_class = _init_desktop_from_design(
specified_version,
non_graphical,
new_desktop_session,
close_on_exit,
student_version,
machine,
port,
aedt_process_id,
)
self._global_logger = self._desktop_class.logger
self._logger = self._desktop_class.logger
self.student_version = self._desktop_class.student_version
if self.student_version:
settings.disable_bounding_box_sat = True
self._mttime = None
self._desktop = self._desktop_class.odesktop
self._desktop_install_dir = settings.aedt_install_dir
self._odesign = None
self._oproject = None
if design_type == "HFSS":
self.design_solutions = HFSSDesignSolution(None, design_type, self._aedt_version)
elif design_type == "Icepak":
self.design_solutions = IcepakDesignSolution(None, design_type, self._aedt_version)
elif design_type == "Maxwell 2D":
self.design_solutions = Maxwell2DDesignSolution(None, design_type, self._aedt_version)
elif design_type == "RMxprtSolution" or design_type == "ModelCreation":
self.design_solutions = RmXprtDesignSolution(None, design_type, self._aedt_version)
else:
self.design_solutions = DesignSolution(None, design_type, self._aedt_version)
self.design_solutions._solution_type = solution_type
self._temp_solution_type = solution_type
self.oproject = project_name
self.odesign = design_name
self._logger.oproject = self.oproject
self._logger.odesign = self.odesign
AedtObjects.__init__(self, self._desktop_class, self.oproject, self.odesign, is_inherithed=True)
self.logger.info("Aedt Objects correctly read")
# if t:
# t.join()
if not self.__t and not settings.lazy_load and not is_ironpython and os.path.exists(self.project_file):
self.__t = threading.Thread(target=load_aedt_thread, args=(self.project_file,), daemon=True)
self.__t.start()
self._variable_manager = VariableManager(self)
self._project_datasets = []
self._design_datasets = []
@property
def desktop_class(self):
"""``Desktop`` class.
Returns
-------
:class:`pyaedt.desktop.Desktop`
"""
return self._desktop_class
@property
def project_datasets(self):
"""Dictionary of project datasets.
Returns
-------
Dict[str, :class:`pyaedt.application.Variables.DataSet`]
"""
if not self._project_datasets:
self._project_datasets = self._get_project_datasets()
return self._project_datasets
@property
def design_datasets(self):
"""Dictionary of Design Datasets.
Returns
-------
Dict[str, :class:`pyaedt.application.Variables.DataSet`]
"""
if not self._design_datasets:
self._design_datasets = self._get_design_datasets()
return self._design_datasets
@property
def boundaries(self):
"""Design boundaries and excitations.
Returns
-------
List of :class:`pyaedt.modules.Boundary.BoundaryObject`
"""
bb = []
if "GetBoundaries" in self.oboundary.__dir__():
bb = list(self.oboundary.GetBoundaries())
elif "Boundaries" in self.get_oo_name(self.odesign):
bb = self.get_oo_name(self.odesign, "Boundaries")
if "GetHybridRegions" in self.oboundary.__dir__():
hybrid_regions = self.oboundary.GetHybridRegions()
for region in hybrid_regions:
bb.append(region)
bb.append("FE-BI")
# Parameters and Motion definitions
if self.design_type in ["Maxwell 3D", "Maxwell 2D"]:
maxwell_parameters = list(self.get_oo_name(self.odesign, "Parameters"))
for parameter in maxwell_parameters:
bb.append(parameter)
bb.append("MaxwellParameters")
if "Model" in list(self.get_oo_name(self.odesign)):
maxwell_model = list(self.get_oo_name(self.odesign, "Model"))
for parameter in maxwell_model:
if self.get_oo_property_value(self.odesign, "Model\\{}".format(parameter), "Type") == "Band":
bb.append(parameter)
bb.append("MotionSetup")
# Icepak definition
elif self.design_type == "Icepak":
othermal = self.get_oo_object(self.odesign, "Thermal")
thermal_definitions = list(self.get_oo_name(othermal))
for thermal in thermal_definitions:
bb.append(thermal)
bb.append(self.get_oo_property_value(othermal, thermal, "Type"))
if self.modeler.user_defined_components.items():
for component in self.modeler.user_defined_components.keys():
thermal_properties = self.get_oo_properties(self.oeditor, component)
if thermal_properties and "Type" not in thermal_properties and thermal_properties[-1] != "Icepak":
thermal_boundaries = self.design_properties["BoundarySetup"]["Boundaries"]
for component_boundary in thermal_boundaries:
if component_boundary not in bb and isinstance(
thermal_boundaries[component_boundary], dict
):
boundarytype = thermal_boundaries[component_boundary]["BoundType"]
bb.append(component_boundary)
bb.append(boundarytype)
current_boundaries = bb[::2]
current_types = bb[1::2]
for boundary, boundarytype in zip(current_boundaries, current_types):
if boundary in self._boundaries:
continue
if boundarytype == "MaxwellParameters":
maxwell_parameter_type = self.get_oo_property_value(
self.odesign, "Parameters\\{}".format(boundary), "Type"
)
self._boundaries[boundary] = MaxwellParameters(self, boundary, boundarytype=maxwell_parameter_type)
elif boundarytype == "MotionSetup":
maxwell_motion_type = self.get_oo_property_value(self.odesign, "Model\\{}".format(boundary), "Type")
self._boundaries[boundary] = BoundaryObject(self, boundary, boundarytype=maxwell_motion_type)
elif boundarytype == "Network":
self._boundaries[boundary] = NetworkObject(self, boundary)
else:
self._boundaries[boundary] = BoundaryObject(self, boundary, boundarytype=boundarytype)
excitations = self.design_excitations
for exc in excitations:
if not self._boundaries or exc.name not in list(self._boundaries.keys()):
self._boundaries[exc.name] = exc
return list(self._boundaries.values())
@property
def boundaries_by_type(self):
"""Design boundaries by type.
Returns
-------
Dictionary of boundaries.
"""
_dict_out = {}
for bound in self.boundaries:
if bound.type in _dict_out:
_dict_out[bound.type].append(bound)
else:
_dict_out[bound.type] = [bound]
return _dict_out
@property
def excitations_by_type(self):
"""Design excitations by type.
Returns
-------
dict
Dictionary of excitations.
"""
_dict_out = {}
for bound in self.design_excitations:
if bound.type in _dict_out:
_dict_out[bound.type].append(bound)
else:
_dict_out[bound.type] = [bound]
return _dict_out
@property
def design_excitations(self):
"""Design excitations.
Returns
-------
list
List of :class:`pyaedt.modules.Boundary.BoundaryObject`.
"""
design_excitations = {}
if "GetExcitations" in self.oboundary.__dir__():
ee = list(self.oboundary.GetExcitations())
current_boundaries = [i.split(":")[0] for i in ee[::2]]
current_types = ee[1::2]
for i in set(current_types):
new_port = []
if "GetExcitationsOfType" in self.oboundary.__dir__():
new_port = list(self.oboundary.GetExcitationsOfType(i))
if new_port:
current_boundaries = current_boundaries + new_port
current_types = current_types + [i] * len(new_port)
for boundary, boundarytype in zip(current_boundaries, current_types):
design_excitations[boundary] = BoundaryObject(self, boundary, boundarytype=boundarytype)
if (
design_excitations[boundary].object_properties
and design_excitations[boundary].object_properties.props["Type"] == "Terminal"
): # pragma: no cover
props_terminal = OrderedDict()
props_terminal["TerminalResistance"] = design_excitations[boundary].object_properties.props[
"Terminal Renormalizing Impedance"
]
props_terminal["ParentBndID"] = design_excitations[boundary].object_properties.props["Port Name"]
design_excitations[boundary] = BoundaryObject(
self, boundary, props=props_terminal, boundarytype="Terminal"
)
elif "GetAllPortsList" in self.oboundary.__dir__() and self.design_type in ["HFSS 3D Layout Design"]:
for port in self.oboundary.GetAllPortsList():
if port in self._boundaries:
continue
bound = self._update_port_info(port)
if bound:
design_excitations[port] = bound
if design_excitations:
return list(design_excitations.values())
return []
@property
def odesktop(self):
"""AEDT instance containing all projects and designs.
Examples
--------
Get the COM object representing the desktop.
>>> from pyaedt import Hfss
>>> hfss = Hfss()
>>> hfss.odesktop
<class 'win32com.client.CDispatch'>
"""
return self._desktop
@pyaedt_function_handler()
def __delitem__(self, key):
"""Implement destructor with array name or index."""
del self._variable_manager[key]
def _init_variables(self):
self.__aedt_version = ""
self._modeler = None
self._post = None
self._materials = None
self._variable_manager = None
self._parametrics = None
self._optimizations = None
self._native_components = None
self._mesh = None
@property
def settings(self):
"""Settings of the current Python/Pyaedt session."""
return settings
@property
def logger(self):
"""Logger for the design.
Returns
-------
:class:`pyaedt.aedt_logger.AedtLogger`
"""
return self._logger
@property
def project_properties(self):
"""Project properties.
Returns
-------
dict
Dictionary of the project properties.
"""
if self.__t:
self.__t.join()
self.__t = None
start = time.time()
if self.project_timestamp_changed or (
os.path.exists(self.project_file)
and os.path.normpath(self.project_file) not in settings._project_properties
):
settings._project_properties[os.path.normpath(self.project_file)] = load_entire_aedt_file(self.project_file)
self._logger.info("aedt file load time {}".format(time.time() - start))
elif (
os.path.normpath(self.project_file) not in settings._project_properties
and settings.remote_rpc_session
and settings.remote_rpc_session.filemanager.pathexists(self.project_file)
):
file_path = check_and_download_file(self.project_file)
try:
settings._project_properties[os.path.normpath(self.project_file)] = load_entire_aedt_file(file_path)
except Exception:
pass
self._logger.info("aedt file load time {}".format(time.time() - start))
if os.path.normpath(self.project_file) in settings._project_properties:
return settings._project_properties[os.path.normpath(self.project_file)]
return {}
@property
def design_properties(self):
"""Design properties.
Returns
-------
dict
Dictionary of the design properties.
"""
try:
if model_names[self._design_type] in self.project_properties["AnsoftProject"]:
designs = self.project_properties["AnsoftProject"][model_names[self._design_type]]
if isinstance(designs, list):
for design in designs:
if design["Name"] == self.design_name:
return design
else:
if designs["Name"] == self.design_name:
return designs
except Exception:
return OrderedDict()
@property
def aedt_version_id(self):
"""AEDT version.
Returns
-------
str
Version of AEDT.
References
----------
>>> oDesktop.GetVersion()
"""
return get_version_env_variable(self.desktop_class.aedt_version_id)
@property
def _aedt_version(self):
return self.desktop_class.aedt_version_id
@property
def design_name(self):
"""Design name.
Returns
-------
str
Name of the parent AEDT design.
References
----------
>>> oDesign.GetName
>>> oDesign.RenameDesignInstance
Examples
--------
Set the design name.
>>> from pyaedt import Hfss
>>> hfss = Hfss()
>>> hfss.design_name = 'new_design'
"""
from pyaedt.generic.general_methods import _retry_ntimes
if not self.odesign:
return None
name = _retry_ntimes(5, self.odesign.GetName)
if ";" in name:
return name.split(";")[1]
else:
return name
@design_name.setter
def design_name(self, new_name):
if ";" in new_name:
new_name = new_name.split(";")[1]
# If new_name is the name of an existing design, set the current
# design to this design.
if new_name in self.design_list:
self.set_active_design(new_name)
else: # Otherwise rename the current design.
self.odesign.RenameDesignInstance(self.design_name, new_name)
timeout = 5.0
timestep = 0.1
while new_name not in [
i.GetName() if ";" not in i.GetName() else i.GetName().split(";")[1]
for i in list(self._oproject.GetDesigns())
]:
time.sleep(timestep)
timeout -= timestep
assert timeout >= 0
@property
def design_list(self):
"""Design list.
Returns
-------
list
List of the designs.
References
----------
>>> oProject.GetTopDesignList()
"""
deslist = list(self.oproject.GetTopDesignList())
updateddeslist = []
for el in deslist:
m = re.search(r"[^;]+$", el)
updateddeslist.append(m.group(0))
return updateddeslist
@property
def design_type(self):
"""Design type.
Options are ``"Circuit Design"``, ``"Emit"``, ``"HFSS"``,
``"HFSS 3D Layout Design"``, ``"Icepak"``, ``"Maxwell 2D"``,
``"Maxwell 3D"``, ``"Maxwell Circuit"``, ``"Mechanical"``, ``"ModelCreation"``,
``"Q2D Extractor"``, ``"Q3D Extractor"``, ``"RMxprtSolution"``,
and ``"Twin Builder"``.
Returns
-------
str
Type of the design. See above for a list of possible return values.
"""
return self._design_type
@property
def project_name(self):
"""Project name.
Returns
-------
str
Name of the project.
References
----------
>>> oProject.GetName
"""
if self.oproject:
try:
return self.oproject.GetName()
except Exception:
return None
else:
return None
@property
def project_list(self):
"""Project list.
Returns
-------
list
List of projects.
References
----------
>>> oDesktop.GetProjectList
"""
return list(self.odesktop.GetProjectList())
@property
def project_path(self):
"""Project path.
Returns
-------
str
Path to the project.
References
----------
>>> oProject.GetPath
"""
if self.oproject:
return self.oproject.GetPath()
return None
@property
def project_time_stamp(self):
"""Return Project time stamp."""
if os.path.exists(self.project_file):
settings._project_time_stamp = os.path.getmtime(self.project_file)
else:
settings._project_time_stamp = 0
return settings._project_time_stamp
@property
def project_timestamp_changed(self):
"""Return a bool if time stamp changed or not."""
old_time = settings._project_time_stamp
return old_time != self.project_time_stamp
@property
def project_file(self):
"""Project name and path.
Returns
-------
str
Full absolute name and path for the project.
"""
if self.project_path:
return os.path.join(self.project_path, self.project_name + ".aedt")
@property
def lock_file(self):
"""Lock file.
Returns
-------
str
Full absolute name and path for the project's lock file.
"""
if self.project_path:
return os.path.join(self.project_path, self.project_name + ".aedt.lock")
@property
def results_directory(self):
"""Results directory.
Returns
-------
str
Full absolute path for the ``aedtresults`` directory.
"""
if self.project_path:
return os.path.join(self.project_path, self.project_name + ".aedtresults")
@property
def solution_type(self):
"""Solution type.
Returns
-------
str
Type of the solution.
References
----------
>>> oDesign.GetSolutionType
>>> oDesign.SetSolutionType
"""
if self.design_solutions:
return self.design_solutions.solution_type
return None
@solution_type.setter
def solution_type(self, soltype):
if self.design_solutions:
if (
self.design_type == "HFSS" and self.design_solutions.solution_type == "Terminal" and soltype == "Modal"
): # pragma: no cover
boundaries = self.boundaries
for exc in boundaries:
if exc.type == "Terminal":
del self._boundaries[exc.name]
self.design_solutions.solution_type = soltype
@property
def valid_design(self):
"""Valid design.
Returns
-------
bool
``True`` when the project and design exists, ``False`` otherwise.
"""
if self._oproject and self._odesign:
return True
else:
return False
@property
def personallib(self):
"""PersonalLib directory.
Returns
-------
str
Full absolute path for the ``PersonalLib`` directory.
References
----------
>>> oDesktop.GetPersonalLibDirectory
"""
return self.desktop_class.personallib
@property
def userlib(self):
"""UserLib directory.
Returns
-------
str
Full absolute path for the ``UserLib`` directory.
References
----------
>>> oDesktop.GetUserLibDirectory
"""
return self.desktop_class.userlib
@property
def syslib(self):
"""SysLib directory.
Returns
-------
str
Full absolute path for the ``SysLib`` directory.
References
----------
>>> oDesktop.GetLibraryDirectory
"""
return self.desktop_class.syslib
@property
def src_dir(self):
"""Source directory for Python.
Returns
-------
str
Full absolute path for the ``python`` directory.
"""
return os.path.dirname(os.path.realpath(__file__))
@property
def pyaedt_dir(self):
"""PyAEDT directory.
Returns
-------
str
Full absolute path for the ``pyaedt`` directory.
"""
return os.path.realpath(os.path.join(self.src_dir, ".."))
@property
def library_list(self):
"""Library list.
Returns
-------
list
List of libraries: ``[syslib, userlib, personallib]``.
"""
return [self.syslib, self.userlib, self.personallib]
@property
def temp_directory(self):
"""Path to the temporary directory.
Returns
-------
str
Full absolute path for the ``temp`` directory.
"""
return self.odesktop.GetTempDirectory()
@property
def toolkit_directory(self):
"""Path to the toolkit directory.
Returns
-------
str
Full absolute path for the ``pyaedt`` directory for this project.
If this directory does not exist, it is created.
"""
if self.project_name:
name = self.project_name.replace(" ", "_")
else:
name = generate_unique_name("prj")
toolkit_directory = os.path.join(self.project_path, name + ".pyaedt")
if settings.remote_rpc_session:
toolkit_directory = self.project_path + "/" + name + ".pyaedt"
try:
settings.remote_rpc_session.filemanager.makedirs(toolkit_directory)
except Exception:
toolkit_directory = settings.remote_rpc_session.filemanager.temp_dir() + "/" + name + ".pyaedt"
elif settings.remote_api or settings.remote_rpc_session:
toolkit_directory = self.results_directory
elif not os.path.isdir(toolkit_directory):
try:
os.makedirs(toolkit_directory)
except FileNotFoundError:
toolkit_directory = self.results_directory
return toolkit_directory
@property
def working_directory(self):
"""Path to the working directory.
Returns
-------
str
Full absolute path for the project's working directory.
If this directory does not exist, it is created.
"""
if self.design_name:
name = self.design_name.replace(" ", "_")
else:
name = generate_unique_name("prj")
working_directory = os.path.join(self.toolkit_directory, name)
if settings.remote_rpc_session:
working_directory = self.toolkit_directory + "/" + name
settings.remote_rpc_session.filemanager.makedirs(working_directory)
elif not os.path.isdir(working_directory):
try:
os.makedirs(working_directory)
except FileNotFoundError:
working_directory = os.path.join(self.toolkit_directory, name + ".results")
return working_directory
@property
def default_solution_type(self):