Skip to content

Commit

Permalink
FEAT: DXF import updates (#5523)
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacwaldron authored Dec 10, 2024
2 parents 273097b + 023ea4b commit d9b6f5f
Show file tree
Hide file tree
Showing 3 changed files with 3,401 additions and 17 deletions.
23 changes: 11 additions & 12 deletions src/ansys/aedt/core/application/analysis_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1256,9 +1256,13 @@ def get_dxf_layers(self, file_path):
with open_file(file_path, encoding="utf8") as f:
lines = f.readlines()
indices = self._find_indices(lines, "AcDbLayerTableRecord\n")
index_offset = 1
if not indices:
indices = self._find_indices(lines, "LAYER\n")
index_offset = 3
for idx in indices:
if "2" in lines[idx + 1]:
layer_names.append(lines[idx + 2].replace("\n", ""))
if "2" in lines[idx + index_offset]:
layer_names.append(lines[idx + index_offset + 1].replace("\n", ""))
return layer_names

@pyaedt_function_handler(layers_list="layers")
Expand Down Expand Up @@ -1295,7 +1299,7 @@ def import_dxf(
Whether to join multiple straight line segments to form polylines.
The default is ``True``.
self_stitch_tolerance : float, optional
Self stitch tolerance value. The default is ``0``.
Self stitch tolerance value. If negative, let importer use its default tolerance. The default is ``0``.
scale : float, optional
Scaling factor. The default is ``0.001``. The units are ``mm``.
defeature_geometry : bool, optional
Expand Down Expand Up @@ -1330,7 +1334,7 @@ def import_dxf(
>>> oEditor.ImportDXF
"""
if self.desktop_class.non_graphical:
if self.desktop_class.non_graphical and self.desktop_class.aedt_version_id < "2024.2":
self.logger.error("Method is supported only in graphical mode.")
return False
dxf_layers = self.get_dxf_layers(file_path)
Expand All @@ -1349,7 +1353,8 @@ def import_dxf(
vArg1.append("Scale:="), vArg1.append(scale)
vArg1.append("AutoDetectClosed:="), vArg1.append(auto_detect_close)
vArg1.append("SelfStitch:="), vArg1.append(self_stitch)
vArg1.append("SelfStitchTolerance:="), vArg1.append(self_stitch_tolerance)
if self_stitch_tolerance >= 0.0:
vArg1.append("SelfStitchTolerance:="), vArg1.append(self_stitch_tolerance)
vArg1.append("DefeatureGeometry:="), vArg1.append(defeature_geometry)
vArg1.append("DefeatureDistance:="), vArg1.append(defeature_distance)
vArg1.append("RoundCoordinates:="), vArg1.append(round_coordinates)
Expand Down Expand Up @@ -1475,21 +1480,15 @@ def import_gds_3d(self, input_file, mapping_layers, units="um", import_method=1)
def _find_indices(self, list_to_check, item_to_find):
# type: (list, str|int) -> list
"""Given a list, returns the list of indices for all occurrences of a given element.
Parameters
----------
list_to_check: list
List to check.
item_to_find: str, int
Element to search for in the list.
Returns
-------
list
Indices of the occurrences of a given element.
"""
indices = []
for idx, value in enumerate(list_to_check):
if value == item_to_find:
indices.append(idx)
return indices
return [idx for idx, value in enumerate(list_to_check) if value == item_to_find]
Loading

0 comments on commit d9b6f5f

Please sign in to comment.