Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/7264.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve consistency
66 changes: 35 additions & 31 deletions src/ansys/aedt/core/application/design.py
Original file line number Diff line number Diff line change
Expand Up @@ -2842,37 +2842,41 @@ def import_dataset1d(
>>> oProject.AddDataset
>>> oDesign.AddDataset
"""
input_file = Path(input_file)
with open_file(input_file, "r") as f:
lines = f.read().splitlines()
header = lines[0]
points = lines[1:]

header_list = header.split("\t")
units = ["", ""]
cont = 0
for h in header_list:
result = re.search(r"\[([A-Za-z0-9_]+)\]", h)
if result:
units[cont] = result.group(1)
cont += 1

xlist = []
ylist = []
for item in points:
xlist.append(float(item.split()[0]))
ylist.append(float(item.split()[1]))

if not name:
name = input_file.stem

if name[0] == "$":
name = name[1:]
is_project_dataset = True

return self.create_dataset(
name, xlist, ylist, is_project_dataset=is_project_dataset, x_unit=units[0], y_unit=units[1], sort=sort
)
in_file = Path(input_file)
if in_file.is_file():
with in_file.open(encoding="utf-8") as f:
lines = f.read().splitlines()
header = lines[0]
points = lines[1:]

header_list = header.split("\t")
units = ["", ""]
cont = 0
for h in header_list:
result = re.search(r"\[([A-Za-z0-9_]+)\]", h)
if result:
units[cont] = result.group(1)
cont += 1

xlist = []
ylist = []
for item in points:
xlist.append(float(item.split()[0]))
ylist.append(float(item.split()[1]))

if not name:
name = input_file.stem

if name[0] == "$":
name = name[1:]
is_project_dataset = True

return self.create_dataset(
name, xlist, ylist, is_project_dataset=is_project_dataset, x_unit=units[0], y_unit=units[1], sort=sort
)
else:
self.logger.error("Input file does not exist.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should raise an Exception

Copy link
Contributor Author

@Devin-Crawford Devin-Crawford Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree.

Suggested change
self.logger.error("Input file does not exist.")
error_message = f"Input file '{in_file}' does not exist."
self.logger.error(error_message)
raise FileNotFoundError(error_message)

return None

@pyaedt_function_handler()
def import_dataset3d(
Expand Down
25 changes: 24 additions & 1 deletion src/ansys/aedt/core/modeler/cad/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -4443,7 +4443,7 @@ def create_faceted_bondwire_from_true_surface(
str
Name of the bondwire created.
"""
old_bondwire = self.get_object_from_name(assignment)
old_bondwire = self.get_objects_by_name(assignment)[0]
if not old_bondwire:
return False
edges = old_bondwire.edges
Expand Down Expand Up @@ -7505,6 +7505,29 @@ def get_obj_id(self, assignment):
return self.objects_by_name[assignment].id
return None

@pyaedt_function_handler()
def get_objects_by_name(self, assignment, case_sensitive: bool = True):
"""Return the objects given a search string.

Parameters
----------
assignment : str
String used to filter by object names.
case_sensitive : bool, optional
Whether the string is case-sensitive. The default is ``True``.

Returns
-------
list of class:`ansys.aedt.core.modeler.cad.object_3d.Object3d`
Returns a list of objects whose names contain the
search string.

"""
if case_sensitive:
return [o for name, o in self.objects_by_name.items() if assignment in name]
else:
return [o for name, o in self.objects_by_name.items() if assignment.lower() in name.lower()]

@pyaedt_function_handler()
def get_object_from_name(self, assignment):
"""Return the object from an object name.
Expand Down
22 changes: 21 additions & 1 deletion src/ansys/aedt/core/modules/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
"""

import copy
import csv
from pathlib import Path

from ansys.aedt.core.base import PyAedtBase
from ansys.aedt.core.generic.constants import CSS4_COLORS
Expand Down Expand Up @@ -430,7 +432,7 @@ def value(self):
return [i.value for i in self._property_value]

@value.setter
def value(self, val) -> None:
def value(self, val: str | list | Path | float | int) -> None:
if isinstance(val, list) and isinstance(val[0], list):
self._property_value[0].value = val
self.set_non_linear()
Expand All @@ -452,6 +454,24 @@ def value(self, val) -> None:
if len(val) == 4:
self._property_value[0].value = val
self._material._update_props(self.name, val, update_aedt=self._material._material_update)
elif isinstance(val, (str, Path)):
val = Path(val)
if not val.is_file():
raise FileNotFoundError(f"Argument {val} is not a file.")
try:
datalist = []
with open(val) as f:
reader = csv.reader(f, delimiter="\t")
next(reader)
for row in reader:
if len(row) != 2:
raise ValueError(f"Line {lineno}: expected 2 columns, got {len(parts)}")
if not (row[0].isnumeric() and row[1].isnumeric()):
raise ValueError(f"Line {lineno}: expected numeric values, got {row[0]} and {row[1]}")
datalist.append([float(row[0]), float(row[1])])
self.value = datalist
except AttributeError:
raise FileNotFoundError(f"Argument {val} is not a file.")
else:
self.type = "simple"
self._property_value[0].value = val
Expand Down
Loading