Update get_name() in query.py with worksets support#3187
Update get_name() in query.py with worksets support#3187jmcouffin merged 5 commits intopyrevitlabs:developfrom
Conversation
A universal method, including support for obtaining a name from worksets
The arguments of the get_name function have been clarified.
There was a problem hiding this comment.
PR Summary:
- Extends
get_name()inquery.pyto supportDB.Worksetobjects (which are notDB.Elementsubclasses and therefore had no.Nameretrieval path). - Replaces the
if PY3:engine guard withif 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 aDB.Worksetinstance and common element types (e.g.WallType,Room) under both IronPython 2 and CPython 3 engines to prevent future regressions. Apply
Added worksets support.
There was a problem hiding this comment.
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 documentDB.Worksetsupport. - Adds an explicit
DB.Worksettype check soget_name()can returnworkset.Name(notably preventing the IronPython/PY2 fallback path from trying to treat a workset like aDB.Element).
|
📦 New work-in-progress (wip) builds are available for 6.1.0.26083+2031-wip |
|
📦 New work-in-progress (wip) builds are available for 6.1.0.26083+2042-wip |
|
📦 New work-in-progress (wip) builds are available for 6.1.0.26083+2045-wip |
|
📦 New work-in-progress (wip) builds are available for 6.1.0.26083+2048-wip |
|
📦 New work-in-progress (wip) builds are available for 6.1.0.26083+2106-wip |
|
📦 New work-in-progress (wip) builds are available for 6.1.0.26083+2130-wip |
|
📦 New work-in-progress (wip) builds are available for 6.1.0.26086+2004-wip |
|
📦 New work-in-progress (wip) builds are available for 6.1.0.26088+1318-wip |
|
📦 New work-in-progress (wip) builds are available for 6.1.0.26089+1231-wip |
|
📦 New work-in-progress (wip) builds are available for 6.1.0.26090+0549-wip |
|
📦 New work-in-progress (wip) builds are available for 6.1.0.26090+1533-wip |
|
📦 New work-in-progress (wip) builds are available for 6.1.0.26090+1536-wip |
|
📦 New work-in-progress (wip) builds are available for 6.1.0.26090+1540-wip |
|
📦 New work-in-progress (wip) builds are available for 6.1.0.26090+1540-wip |
|
📦 New work-in-progress (wip) builds are available for 6.1.0.26090+1556-wip |
|
📦 New public release are available for 6.2.0.26090+1754 |

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