25
25
import csv
26
26
import ntpath
27
27
import os
28
+ from pathlib import Path
29
+ from typing import List
30
+ from typing import Union
31
+ import warnings
28
32
29
33
from ansys .aedt .core .application .analysis import Analysis
30
34
from ansys .aedt .core .generic .checks import min_aedt_version
31
35
from ansys .aedt .core .generic .configurations import Configurations
32
36
from ansys .aedt .core .generic .constants import unit_converter
37
+ from ansys .aedt .core .generic .file_utils import get_dxf_layers
38
+ from ansys .aedt .core .generic .file_utils import read_component_file
33
39
from ansys .aedt .core .generic .general_methods import generate_unique_name
34
40
from ansys .aedt .core .generic .general_methods import open_file
35
41
from ansys .aedt .core .generic .general_methods import pyaedt_function_handler
@@ -297,8 +303,8 @@ def plot(
297
303
show_grid = show_grid ,
298
304
)
299
305
300
- @pyaedt_function_handler (setup_name = "setup" , variation_string = "variations" )
301
- def export_mesh_stats (self , setup , variations = "" , mesh_path = None ):
306
+ @pyaedt_function_handler (setup_name = "setup" , variation_string = "variations" , mesh_path = "output_file" )
307
+ def export_mesh_stats (self , setup , variations = "" , output_file = None ):
302
308
"""Export mesh statistics to a file.
303
309
304
310
Parameters
@@ -307,7 +313,7 @@ def export_mesh_stats(self, setup, variations="", mesh_path=None):
307
313
Setup name.
308
314
variations : str, optional
309
315
Variation list. The default is ``""``.
310
- mesh_path : str, optional
316
+ output_file : str, optional
311
317
Full path to the mesh statistics file. The default is ``None``, in which
312
318
caswe the working directory is used.
313
319
@@ -320,15 +326,38 @@ def export_mesh_stats(self, setup, variations="", mesh_path=None):
320
326
----------
321
327
>>> oDesign.ExportMeshStats
322
328
"""
323
- if not mesh_path :
324
- mesh_path = os .path .join (self .working_directory , "meshstats.ms" )
325
- self .odesign .ExportMeshStats (setup , variations , mesh_path )
326
- return mesh_path
329
+ if not output_file :
330
+ output_file = str (Path (self .working_directory ) / "meshstats.ms" )
331
+ self .odesign .ExportMeshStats (setup , variations , output_file )
332
+ return output_file
333
+
334
+ @pyaedt_function_handler ()
335
+ def get_component_variables (self , name : Union [str , Path ]) -> dict :
336
+ """Read component file and extract variables.
337
+
338
+ Parameters
339
+ ----------
340
+ name : str or :class:`pathlib.Path`
341
+ Name of the 3D component, which must be in the ``syslib`` or ``userlib`` directory.
342
+ Otherwise, you must specify the full absolute path to the component file.
343
+
344
+ Returns
345
+ -------
346
+ dict
347
+ Dictionary of variables in the component file.
348
+ """
349
+ if str (name ) not in self .components3d :
350
+ return read_component_file (name )
351
+ else :
352
+ return read_component_file (self .components3d [name ])
327
353
328
354
@pyaedt_function_handler (component3dname = "component_name" )
329
355
def get_components3d_vars (self , component_name ):
330
356
"""Read the A3DCOMP file and check for variables.
331
357
358
+ .. deprecated:: 0.15.1
359
+ Use :func:`get_component_variables` method instead.
360
+
332
361
Parameters
333
362
----------
334
363
component_name :
@@ -340,43 +369,10 @@ def get_components3d_vars(self, component_name):
340
369
dict
341
370
Dictionary of variables in the A3DCOMP file.
342
371
"""
343
- vars = {}
344
- if component_name not in self .components3d :
345
- aedt_fh = open_file (component_name , "rb" )
346
- if aedt_fh :
347
- temp = aedt_fh .read ().splitlines ()
348
- _all_lines = []
349
- for line in temp :
350
- try :
351
- _all_lines .append (line .decode ("utf-8" ).lstrip ("\t " ))
352
- except UnicodeDecodeError :
353
- break
354
- for line in _all_lines :
355
- if "VariableProp(" in line :
356
- line_list = line .split ("'" )
357
- if not [
358
- c for c in line_list [len (line_list ) - 2 ] if c in ["+" , "-" , "*" , "'" "," "/" , "(" , ")" ]
359
- ]:
360
- self [line_list [1 ]] = line_list [len (line_list ) - 2 ]
361
- else :
362
- vars [line_list [1 ]] = line_list [len (line_list ) - 2 ]
363
- aedt_fh .close ()
364
- return vars
365
- else :
366
- return False
367
- with open_file (self .components3d [component_name ], "rb" ) as aedt_fh :
368
- temp = aedt_fh .read ().splitlines ()
369
- _all_lines = []
370
- for line in temp :
371
- try :
372
- _all_lines .append (line .decode ("utf-8" ).lstrip ("\t " ))
373
- except UnicodeDecodeError :
374
- break
375
- for line in _all_lines :
376
- if "VariableProp(" in line :
377
- line_list = line .split ("'" )
378
- vars [line_list [1 ]] = line_list [len (line_list ) - 2 ]
379
- return vars
372
+ warnings .warn (
373
+ "`get_components3d_vars` is deprecated. Use `get_component_variables` method instead." , DeprecationWarning
374
+ )
375
+ return self .get_component_variables (component_name )
380
376
381
377
@pyaedt_function_handler (objectname = "assignment" , property = "property_name" , type = "property_type" )
382
378
def get_property_value (self , assignment , property_name , property_type = None ):
@@ -1227,56 +1223,52 @@ def check_intersections(output, input_list, cad_in=None):
1227
1223
break
1228
1224
return nets
1229
1225
1230
- @pyaedt_function_handler ()
1231
- def get_dxf_layers (self , file_path ):
1232
- # type: (str) -> list[str]
1226
+ @pyaedt_function_handler (file_path = "input_file" )
1227
+ def get_dxf_layers (self , input_file : Union [str , Path ]) -> List [str ]:
1233
1228
"""Read a DXF file and return all layer names.
1234
1229
1230
+ .. deprecated:: 0.15.1
1231
+ Use :func:`ansys.aedt.core.generic.file_utils.get_dxf_layers` method instead.
1232
+
1235
1233
Parameters
1236
1234
----------
1237
- file_path : str
1235
+ input_file : str or :class:`pathlib.Path`
1238
1236
Full path to the DXF file.
1239
1237
1240
1238
Returns
1241
1239
-------
1242
1240
list
1243
1241
List of layers in the DXF file.
1244
1242
"""
1245
- layer_names = []
1246
- with open_file (file_path , encoding = "utf8" ) as f :
1247
- lines = f .readlines ()
1248
- indices = self ._find_indices (lines , "AcDbLayerTableRecord\n " )
1249
- index_offset = 1
1250
- if not indices :
1251
- indices = self ._find_indices (lines , "LAYER\n " )
1252
- index_offset = 3
1253
- for idx in indices :
1254
- if "2" in lines [idx + index_offset ]:
1255
- layer_names .append (lines [idx + index_offset + 1 ].replace ("\n " , "" ))
1256
- return layer_names
1257
-
1258
- @pyaedt_function_handler (layers_list = "layers" )
1243
+ warnings .warn (
1244
+ "`get_dxf_layers` is deprecated. "
1245
+ "Use `ansys.aedt.core.generic.file_utils.get_dxf_layers` method instead." ,
1246
+ DeprecationWarning ,
1247
+ )
1248
+
1249
+ return get_dxf_layers (input_file )
1250
+
1251
+ @pyaedt_function_handler (layers_list = "layers" , file_path = "input_file" )
1259
1252
def import_dxf (
1260
1253
self ,
1261
- file_path ,
1262
- layers ,
1263
- auto_detect_close = True ,
1264
- self_stitch = True ,
1265
- self_stitch_tolerance = 0 ,
1266
- scale = 0.001 ,
1267
- defeature_geometry = False ,
1268
- defeature_distance = 0 ,
1269
- round_coordinates = False ,
1270
- round_num_digits = 4 ,
1271
- write_poly_with_width_as_filled_poly = False ,
1272
- import_method = 1 ,
1273
- ): # pragma: no cover
1274
- # type: (str, list, bool, bool, float, float, bool, float, bool, int, bool, int, bool) -> bool
1254
+ input_file : str ,
1255
+ layers : List [str ],
1256
+ auto_detect_close : bool = True ,
1257
+ self_stitch : bool = True ,
1258
+ self_stitch_tolerance : float = 0.0 ,
1259
+ scale : float = 0.001 ,
1260
+ defeature_geometry : bool = False ,
1261
+ defeature_distance : float = 0.0 ,
1262
+ round_coordinates : bool = False ,
1263
+ round_num_digits : int = 4 ,
1264
+ write_poly_with_width_as_filled_poly : bool = False ,
1265
+ import_method : Union [int , bool ] = 1 ,
1266
+ ) -> bool : # pragma: no cover
1275
1267
"""Import a DXF file.
1276
1268
1277
1269
Parameters
1278
1270
----------
1279
- file_path : str
1271
+ input_file : str
1280
1272
Path to the DXF file.
1281
1273
layers : list
1282
1274
List of layer names to import. To get the dxf_layers in the DXF file,
@@ -1306,7 +1298,7 @@ def import_dxf(
1306
1298
The default is ``4``.
1307
1299
write_poly_with_width_as_filled_poly : bool, optional
1308
1300
Imports wide polylines as polygons. The default is ``False``.
1309
- import_method : int, bool
1301
+ import_method : int or bool, optional
1310
1302
Whether the import method is ``Script`` or ``Acis``.
1311
1303
The default is ``1``, which means that the ``Acis`` is used.
1312
1304
@@ -1323,7 +1315,7 @@ def import_dxf(
1323
1315
if self .desktop_class .non_graphical and self .desktop_class .aedt_version_id < "2024.2" : # pragma: no cover
1324
1316
self .logger .error ("Method is supported only in graphical mode." )
1325
1317
return False
1326
- dxf_layers = self .get_dxf_layers (file_path )
1318
+ dxf_layers = self .get_dxf_layers (input_file )
1327
1319
for layer in layers :
1328
1320
if layer not in dxf_layers :
1329
1321
self .logger .error (f"{ layer } does not exist in specified dxf." )
@@ -1335,7 +1327,7 @@ def import_dxf(
1335
1327
sheet_bodies_2d = True
1336
1328
1337
1329
vArg1 = ["NAME:options" ]
1338
- vArg1 .append ("FileName:=" ), vArg1 .append (file_path .replace (os .sep , "/" ))
1330
+ vArg1 .append ("FileName:=" ), vArg1 .append (input_file .replace (os .sep , "/" ))
1339
1331
vArg1 .append ("Scale:=" ), vArg1 .append (scale )
1340
1332
vArg1 .append ("AutoDetectClosed:=" ), vArg1 .append (auto_detect_close )
1341
1333
vArg1 .append ("SelfStitch:=" ), vArg1 .append (self_stitch )
@@ -1461,22 +1453,3 @@ def import_gds_3d(self, input_file: str, mapping_layers: dict, units: str = "um"
1461
1453
)
1462
1454
self .logger .info ("GDS layer imported with elevations and thickness." )
1463
1455
return True
1464
-
1465
- @pyaedt_function_handler ()
1466
- def _find_indices (self , list_to_check , item_to_find ):
1467
- # type: (list, str|int) -> list
1468
- """Given a list, returns the list of indices for all occurrences of a given element.
1469
-
1470
- Parameters
1471
- ----------
1472
- list_to_check: list
1473
- List to check.
1474
- item_to_find: str, int
1475
- Element to search for in the list.
1476
-
1477
- Returns
1478
- -------
1479
- list
1480
- Indices of the occurrences of a given element.
1481
- """
1482
- return [idx for idx , value in enumerate (list_to_check ) if value == item_to_find ]
0 commit comments