@@ -810,9 +810,9 @@ def project_name(self) -> Optional[str]:
810810 ----------
811811 >>> oProject.GetName
812812 """
813- if self ._project_name :
813+ if self ._project_name and self . _project_name in self . desktop_class . project_list :
814814 return self ._project_name
815- if self .oproject :
815+ elif self .oproject :
816816 try :
817817 self ._project_name = self .oproject .GetName ()
818818 self ._project_path = None
@@ -2007,14 +2007,14 @@ def set_active_dso_config_name(self, product_name="HFSS", config_name="Local"):
20072007 return False
20082008
20092009 @pyaedt_function_handler ()
2010- def set_registry_from_file (self , registry_file , make_active = True ):
2010+ def set_registry_from_file (self , registry_file : Union [ str , Path ], make_active : bool = True ) -> bool :
20112011 """Apply desktop registry settings from an ACT file.
20122012
20132013 One way to get an ACF file is to export a configuration from the AEDT UI and then edit and reuse it.
20142014
20152015 Parameters
20162016 ----------
2017- registry_file : str
2017+ registry_file : str or :class:`pathlib.Path`
20182018 Full path to the ACF file.
20192019 make_active : bool, optional
20202020 Whether to set the imported configuration as active. The default is ``True``.
@@ -2028,8 +2028,9 @@ def set_registry_from_file(self, registry_file, make_active=True):
20282028 ----------
20292029 >>> oDesktop.SetRegistryFromFile
20302030 """
2031+ registry_file = Path (registry_file )
20312032 try :
2032- self .odesktop .SetRegistryFromFile (registry_file )
2033+ self .odesktop .SetRegistryFromFile (str ( registry_file ) )
20332034 if make_active :
20342035 with open_file (registry_file , "r" ) as f :
20352036 for line in f :
@@ -2940,12 +2941,18 @@ def create_dataset3d(
29402941 )
29412942
29422943 @pyaedt_function_handler (filename = "input_file" , dsname = "name" )
2943- def import_dataset1d (self , input_file , name = None , is_project_dataset = True , sort = True ):
2944+ def import_dataset1d (
2945+ self ,
2946+ input_file : Union [str , Path ],
2947+ name : Optional [str ] = None ,
2948+ is_project_dataset : bool = True ,
2949+ sort : bool = True ,
2950+ ):
29442951 """Import a 1D dataset.
29452952
29462953 Parameters
29472954 ----------
2948- input_file : str
2955+ input_file : str or :class:`pathlib.Path`
29492956 Full path and name for the TAB file.
29502957 name : str, optional
29512958 Name of the dataset. The default is the file name.
@@ -2963,6 +2970,7 @@ def import_dataset1d(self, input_file, name=None, is_project_dataset=True, sort=
29632970 >>> oProject.AddDataset
29642971 >>> oDesign.AddDataset
29652972 """
2973+ input_file = Path (input_file )
29662974 with open_file (input_file , "r" ) as f :
29672975 lines = f .read ().splitlines ()
29682976 header = lines [0 ]
@@ -2984,7 +2992,7 @@ def import_dataset1d(self, input_file, name=None, is_project_dataset=True, sort=
29842992 ylist .append (float (item .split ()[1 ]))
29852993
29862994 if not name :
2987- name = Path ( input_file ) .stem
2995+ name = input_file .stem
29882996
29892997 if name [0 ] == "$" :
29902998 name = name [1 :]
@@ -2995,12 +3003,19 @@ def import_dataset1d(self, input_file, name=None, is_project_dataset=True, sort=
29953003 )
29963004
29973005 @pyaedt_function_handler (filename = "input_file" , dsname = "name" )
2998- def import_dataset3d (self , input_file , name = None , encoding = "utf-8-sig" , is_project_dataset = True , sort = True ):
3006+ def import_dataset3d (
3007+ self ,
3008+ input_file : Union [str , Path ],
3009+ name : Optional [str ] = None ,
3010+ encoding : str = "utf-8-sig" ,
3011+ is_project_dataset : bool = True ,
3012+ sort : bool = True ,
3013+ ):
29993014 """Import a 3D dataset.
30003015
30013016 Parameters
30023017 ----------
3003- input_file : str
3018+ input_file : str or :class:`pathlib.Path`
30043019 Full path and name for the tab/csv/xlsx file.
30053020 name : str, optional
30063021 Name of the dataset. The default is the file name.
@@ -3019,16 +3034,17 @@ def import_dataset3d(self, input_file, name=None, encoding="utf-8-sig", is_proje
30193034 ----------
30203035 >>> oProject.AddDataset
30213036 """
3022- index_of_dot = input_file .rfind ("." )
3023- file_extension = input_file [index_of_dot + 1 :]
3037+ path = Path (input_file )
3038+ file_extension = path .suffix .lstrip ("." ).lower ()
3039+
30243040 xlist = []
30253041 ylist = []
30263042 zlist = []
30273043 vlist = []
30283044
30293045 if file_extension == "xlsx" :
30303046 self .logger .warning ("You need pandas and openpyxl library installed for reading excel files" )
3031- lines = read_xlsx (input_file )
3047+ lines = read_xlsx (path )
30323048 if list (lines ):
30333049 header = str ([lines .columns [i ] for i in range (len (lines .columns ))])
30343050 xlist = list ((lines .iloc [:, 0 ]).array )
@@ -3040,7 +3056,7 @@ def import_dataset3d(self, input_file, name=None, encoding="utf-8-sig", is_proje
30403056 return False
30413057
30423058 elif file_extension == "csv" :
3043- lines = read_csv (input_file , encoding )
3059+ lines = read_csv (path , encoding )
30443060 header = " " .join (lines [0 ])
30453061 for row in lines [1 :]:
30463062 xlist .append (float (row [0 ]))
@@ -3049,13 +3065,14 @@ def import_dataset3d(self, input_file, name=None, encoding="utf-8-sig", is_proje
30493065 vlist .append (float (row [3 ]))
30503066
30513067 elif file_extension == "tab" :
3052- lines = read_tab (input_file )
3068+ lines = read_tab (path )
30533069 header = lines [0 ]
30543070 for item in lines [1 :]:
3055- xlist .append (float (item .split ()[0 ]))
3056- ylist .append (float (item .split ()[1 ]))
3057- zlist .append (float (item .split ()[2 ]))
3058- vlist .append (float (item .split ()[3 ]))
3071+ cols = item .split ()
3072+ xlist .append (float (cols [0 ]))
3073+ ylist .append (float (cols [1 ]))
3074+ zlist .append (float (cols [2 ]))
3075+ vlist .append (float (cols [3 ]))
30593076
30603077 header_list = header .split ()
30613078 units = ["" , "" , "" , "" ]
@@ -3067,12 +3084,14 @@ def import_dataset3d(self, input_file, name=None, encoding="utf-8-sig", is_proje
30673084 cont += 1
30683085
30693086 if not name :
3070- name = Path ( input_file ) .stem
3087+ name = path .stem
30713088
3072- if name [0 ] == "$" :
3089+ is_project_dataset = False
3090+ if name .startswith ("$" ):
30733091 name = name [1 :]
30743092 is_project_dataset = True
3075- if self .design_type != "Maxwell 3D" and self .design_type != "Icepak" :
3093+
3094+ if self .design_type not in ["Maxwell 3D" , "Icepak" ]:
30763095 is_project_dataset = True
30773096
30783097 return self .create_dataset (
@@ -3833,12 +3852,17 @@ def export_design_preview_to_jpg(self, output_file):
38333852 @pyaedt_function_handler (
38343853 filename = "output_file" , export_project = "export_project_variables" , export_design = "export_design_properties"
38353854 )
3836- def export_variables_to_csv (self , output_file , export_project_variables = True , export_design_properties = True ):
3855+ def export_variables_to_csv (
3856+ self ,
3857+ output_file : Union [str , Path ],
3858+ export_project_variables : bool = True ,
3859+ export_design_properties : bool = True ,
3860+ ) -> bool :
38373861 """Export design properties, project variables, or both to a CSV file.
38383862
38393863 Parameters
38403864 ----------
3841- output_file : str
3865+ output_file : str or :class:`pathlib.Path`
38423866 Full path and name for the CSV file.
38433867 export_project_variables : bool, optional
38443868 Whether to export project variables. The default is ``True``.
@@ -3858,6 +3882,7 @@ def export_variables_to_csv(self, output_file, export_project_variables=True, ex
38583882 >>> oProject.GetVariableValue
38593883 >>> oDesign.GetVariableValue
38603884 """
3885+ output_file = Path (output_file )
38613886 varnames = []
38623887 desnames = []
38633888 if export_project_variables :
@@ -3873,7 +3898,7 @@ def export_variables_to_csv(self, output_file, export_project_variables=True, ex
38733898 for el in desnames :
38743899 value = self .odesign .GetVariableValue (el )
38753900 list_full .append ([el , value ])
3876- return write_csv (output_file , list_full )
3901+ return write_csv (str ( output_file ) , list_full )
38773902
38783903 @pyaedt_function_handler ()
38793904 def read_design_data (self ):
@@ -4305,12 +4330,12 @@ def check_if_project_is_loaded(self, input_file):
43054330 return False
43064331
43074332 @pyaedt_function_handler (temp_dir_path = "path" )
4308- def set_temporary_directory (self , path ) :
4333+ def set_temporary_directory (self , path : Union [ str , Path ]) -> bool :
43094334 """Set temporary directory path.
43104335
43114336 Parameters
43124337 ----------
4313- path : str
4338+ path : str or :class:`pathlib.Path`
43144339 Temporary directory path.
43154340
43164341 Returns
@@ -4322,7 +4347,8 @@ def set_temporary_directory(self, path):
43224347 ----------
43234348 >>> oDesktop.SetTempDirectory()
43244349 """
4325- self .odesktop .SetTempDirectory (path )
4350+ path = Path (path )
4351+ self .odesktop .SetTempDirectory (str (path ))
43264352 return True
43274353
43284354 @pyaedt_function_handler ()
0 commit comments