Skip to content

Update get_name() in query.py with worksets support#3187

Merged
jmcouffin merged 5 commits intopyrevitlabs:developfrom
Denver-22:develop
Mar 24, 2026
Merged

Update get_name() in query.py with worksets support#3187
jmcouffin merged 5 commits intopyrevitlabs:developfrom
Denver-22:develop

Conversation

@Denver-22
Copy link
Copy Markdown
Contributor

A universal method, including support for obtaining a name from worksets.

A universal method, including support for obtaining a name from worksets
The arguments of the get_name function have been clarified.
Copy link
Copy Markdown
Contributor

@devloai devloai bot left a comment

Choose a reason for hiding this comment

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

PR Summary:

  • Extends get_name() in query.py to support DB.Workset objects (which are not DB.Element subclasses and therefore had no .Name retrieval path).
  • Replaces the if PY3: engine guard with if hasattr(element, "Name"): to detect name-capable objects dynamically.
  • Updates docstring to reflect the expanded type signature.

Review Summary:

The intent of the PR is valid — DB.Workset is not a DB.Element, so the original code had a gap. However, the chosen approach introduces a regression for IronPython 2 (IPY2712), which is the primary runtime for this codebase. In IronPython 2.7, DB.Element objects do expose a .Name attribute via the .NET bridge, so hasattr(element, "Name") always returns True for standard elements — this causes the else: Element.Name.GetValue(element) branch to become permanently unreachable. That branch exists specifically to work around a well-documented IronPython 2.7 bug where direct .Name access on derived element types (e.g. WallType, FamilySymbol, Room) returns the unbound descriptor object instead of the name string. A safer fix uses an explicit isinstance(element, DB.Workset) check while restoring the original PY3 guard.

Suggestions

  • Add a unit/integration test covering get_name() with a DB.Workset instance and common element types (e.g. WallType, Room) under both IronPython 2 and CPython 3 engines to prevent future regressions. Apply

@jmcouffin jmcouffin requested a review from Copilot March 21, 2026 11:41
@jmcouffin jmcouffin added the Enhancement Enhancement request [class->Improved #{number}: {title}] label Mar 21, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR extends pyrevit.revit.db.query.get_name() to also return a meaningful name when passed a Revit DB.Workset, making the helper more universally usable across Revit object types.

Changes:

  • Updates get_name() docstring to document DB.Workset support.
  • Adds an explicit DB.Workset type check so get_name() can return workset.Name (notably preventing the IronPython/PY2 fallback path from trying to treat a workset like a DB.Element).

@jmcouffin jmcouffin self-assigned this Mar 24, 2026
@jmcouffin
Copy link
Copy Markdown
Contributor

added new unittest for the method since this is a fundamental one
image

@jmcouffin jmcouffin merged commit c6e55bf into pyrevitlabs:develop Mar 24, 2026
@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 6.1.0.26083+2031-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 6.1.0.26083+2042-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 6.1.0.26083+2045-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 6.1.0.26083+2048-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 6.1.0.26083+2106-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 6.1.0.26083+2130-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 6.1.0.26086+2004-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 6.1.0.26088+1318-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 6.1.0.26089+1231-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 6.1.0.26090+0549-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 6.1.0.26090+1533-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 6.1.0.26090+1536-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 6.1.0.26090+1540-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 6.1.0.26090+1540-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 6.1.0.26090+1556-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New public release are available for 6.2.0.26090+1754

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement Enhancement request [class->Improved #{number}: {title}]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants