Skip to content

Commit

Permalink
Remove ezdxf
Browse files Browse the repository at this point in the history
Restore the original custom implmentation for reading DXF layer names
with an extension to support DXF R12 format files.
  • Loading branch information
isaacwaldron committed Dec 9, 2024
1 parent 805de9e commit 60251a8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ tests = [
"scikit-rf>=0.30.0,<1.6",
"SRTM.py",
"utm",
"ezdxf",
]
dotnet = [
"ansys-pythonnet>=3.1.0rc3",
Expand Down Expand Up @@ -117,7 +116,6 @@ all = [
"scikit-rf>=0.30.0,<1.6",
"SRTM.py",
"utm",
"ezdxf",
]
installer = [
"matplotlib>=3.5.0,<3.10",
Expand Down
40 changes: 29 additions & 11 deletions src/ansys/aedt/core/application/analysis_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1252,17 +1252,18 @@ def get_dxf_layers(self, file_path):
list
List of layers in the DXF file.
"""
try:
import ezdxf

doc = ezdxf.readfile(file_path)
return [layer.dxf.name for layer in doc.layers if layer.dxf.plot]
except ImportError: # pragma: no cover
self.logger.warning(
"The ezdxf module is required to import DXF files.\n"
"Install with pip install pyaedt[all] or install with pip install ezdxf"
)
return []
layer_names = []
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 + index_offset]:
layer_names.append(lines[idx + index_offset + 1].replace("\n", ""))
return layer_names

@pyaedt_function_handler(layers_list="layers")
def import_dxf(
Expand Down Expand Up @@ -1474,3 +1475,20 @@ def import_gds_3d(self, input_file, mapping_layers, units="um", import_method=1)
)
self.logger.info("GDS layer imported with elevations and thickness.")
return True

@pyaedt_function_handler()
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.
"""
return [idx for idx, value in enumerate(list_to_check) if value == item_to_find]

0 comments on commit 60251a8

Please sign in to comment.