Skip to content

FEAT: Improve consistency#7264

Open
Devin-Crawford wants to merge 25 commits intomainfrom
fix/7257_improve_consistency_get_object
Open

FEAT: Improve consistency#7264
Devin-Crawford wants to merge 25 commits intomainfrom
fix/7257_improve_consistency_get_object

Conversation

@Devin-Crawford
Copy link
Contributor

@Devin-Crawford Devin-Crawford commented Feb 15, 2026

Description

Add method modeler.get_objects_by_name to be consistent with modeler.get_objects_by_material

Issue linked

Close #7257

Checklist

  • I have tested my changes locally.
  • I have added necessary documentation or updated existing documentation.
  • I have followed the coding style guidelines of this project.
  • I have added appropriate tests (unit, integration, system).
  • I have reviewed my changes before submitting this pull request.
  • I have linked the issue or issues that are solved by the PR if any.
  • I have agreed with the Contributor License Agreement (CLA).

Add method modeler.get_objects_by_name to be consistent with modeler.get_objects_by_material
@Devin-Crawford Devin-Crawford requested a review from a team as a code owner February 15, 2026 12:13
@github-actions github-actions bot added the bug Something isn't working label Feb 15, 2026
MaxJPRey
MaxJPRey previously approved these changes Feb 15, 2026
…_object' into fix/7257_improve_consistency_get_object
Copy link
Collaborator

@SMoraisAnsys SMoraisAnsys left a comment

Choose a reason for hiding this comment

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

Should we rework the API to work differently ? Like having a single method to do both approaches ? We could allow different kind of matching mechanism, e.g. (exact, contains, start/endswith, regex), whille keeping the pattern argument (meaning varying depending on the matching mechanism) and en/disabling case sensitive.

Open to discussion

A file containing x,y datapoints can be assigned as
a table to permeability.
…_object' into fix/7257_improve_consistency_get_object
@SMoraisAnsys
Copy link
Collaborator

Any thoughts on my comment @Devin-Crawford @Samuelopez-ansys @MaxJPRey (you reviewed, blame yourself for the ping :p)

@Samuelopez-ansys
Copy link
Member

Should we rework the API to work differently ? Like having a single method to do both approaches ? We could allow different kind of matching mechanism, e.g. (exact, contains, start/endswith, regex), whille keeping the pattern argument (meaning varying depending on the matching mechanism) and en/disabling case sensitive.

Open to discussion

What do you mean @SMoraisAnsys ?

get_objects_by_name and get_object_from_name?

I would keep get_object_from_name which already exist, and I would add a new argument to specify if you want a perfect match (like now) or partial (with Sebastien's ideas).

Thanks.

Co-authored-by: Sébastien Morais <146729917+SMoraisAnsys@users.noreply.github.com>
@Devin-Crawford
Copy link
Contributor Author

Devin-Crawford commented Feb 20, 2026

Should we rework the API to work differently ? Like having a single method to do both approaches ? We could allow different kind of matching mechanism, e.g. (exact, contains, start/endswith, regex), whille keeping the pattern argument (meaning varying depending on the matching mechanism) and en/disabling case sensitive.
Open to discussion

What do you mean @SMoraisAnsys ?

get_objects_by_name and get_object_from_name?

I would keep get_object_from_name which already exist, and I would add a new argument to specify if you want a perfect match (like now) or partial (with Sebastien's ideas).

  • get_objects_by_material() returns a list of objects.
  • get_object_from_name() returns a single object and the name must be specified exactly.
  • get_objects_by_name() is new and is consistent with the first method above. There
    are two inconsistencies: "from" vs "by". It doesn't matter which preposition
    is used but they should
    be consistent. get_object_from_name() wouldn't be necessary if we
    have get_objects_by_name(). We could add a named argument exact_match to return only
    a single object and then we would have get_object_from_name() functionality.

@Samuelopez-ansys
Copy link
Member

Hi @Devin-Crawford , could you please add a test for the new material case, where you pass a tab file?

@Samuelopez-ansys
Copy link
Member

@SMoraisAnsys @Devin-Crawford I added with fnmatch what you suggested, now get_objects_by_name is very complete and accept the wildcard pattern *, like other Ansys tools:

    # Exact match
    >>> objs = modeler.get_objects_by_name("Patch_1")

    # All objects whose name starts with "Substrate"
    >>> objs = modeler.get_objects_by_name("Substrate*")

    # All objects whose name ends with "_gnd"
    >>> objs = modeler.get_objects_by_name("*_gnd")

    # All objects whose name contains "patch"
    >>> objs = modeler.get_objects_by_name("*patch*", case_sensitive=False)

    # Mid-string wildcard: names like "Sub_1", "Sub_gnd_1".
    >>> objs = modeler.get_objects_by_name("Sub*_1")

eblanco-ansys
eblanco-ansys previously approved these changes Mar 23, 2026
@Samuelopez-ansys
Copy link
Member

Before merging, @SMoraisAnsys could you please make a last review?

Copy link
Collaborator

@SMoraisAnsys SMoraisAnsys left a comment

Choose a reason for hiding this comment

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

Except for those minor comments, the PR seems fine. Thanks for the changes @Devin-Crawford

Comment on lines +4500 to 4502
old_bondwire = self.get_objects_by_name(assignment)[0]
if not old_bondwire:
return False
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
old_bondwire = self.get_objects_by_name(assignment)[0]
if not old_bondwire:
return False
bojects = self.get_objects_by_name(assignment)
if objects:
old_bondwire = objects[0]
else:
raise ValueError(f"Assignment {assignment} does not match an object.")

If the returned list is empty, the code will return an exception.

"""Return the objects whose names match a wildcard pattern.

The ``*`` character acts as a wildcard that matches any sequence of
characters (including none). The matching mode is inferred
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
characters (including none). The matching mode is inferred
characters (including none). The matching mode is inferred

if assignment in self.object_names:
# object_id = self.get_obj_id(objname)
return self.objects[assignment]
return None
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure if this is required as, by default, every python function return 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, Path):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe adding a check on the kind of file here ? Just to ensure that we call csv.reader() on a CSV file ?

SMoraisAnsys and others added 2 commits March 23, 2026 14:40
Co-authored-by: Sébastien Morais <146729917+SMoraisAnsys@users.noreply.github.com>
@Samuelopez-ansys Samuelopez-ansys dismissed stale reviews from eblanco-ansys and themself via 52b5610 March 23, 2026 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve consistency of get_object...

6 participants