Skip to content

Conversation

@Denver-22
Copy link
Contributor

Fixed a bug where the revit.pick_linked() and revit.pick_linkeds() methods returned None due to incorrectly retrieving link instance elements.

The remaining "pick_" and "get_picked_" methods were unaffected.

Fixed a bug where the revit.pick_linked() and revit.pick_linkeds() methods returned None due to incorrectly retrieving link instance elements.
Copy link
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:

This PR fixes a bug where pick_linked() and pick_linkeds() methods returned None by adding logic to retrieve linked elements from RevitLinkInstance documents. The fix adds a conditional check to handle linked elements differently from regular elements, retrieving them from the linked document using GetLinkDocument() and LinkedElementId.

Review Summary:

The fix addresses the core issue but has critical gaps: it lacks an obj_type check (affecting pick_face()/pick_edge() behavior), missing null validation for unloaded links (causing crashes per Revit API defensive patterns in knowledge base), and redundant API calls (3x per reference). The suggested refactor uses an explicit loop with proper validation to handle linked elements safely while maintaining performance.

Follow-up suggestions:

  • @devloai fix the identified issues
  • @devloai add test cases for unloaded link scenarios

@Denver-22
Copy link
Contributor Author

Is devloai's code fix proposal automatically included in the PR or do I have to do it myself?

Improved bug fix.
@jmcouffin
Copy link
Contributor

It is not. Like the copilot review when in launch them.
Always review and test. I let people do a first pass at ai reviews before reviewing myself

@jmcouffin jmcouffin requested a review from Copilot November 22, 2025 08:10
@jmcouffin jmcouffin self-assigned this Nov 22, 2025
@jmcouffin jmcouffin added the Tools Issues related to pyRevit commands [subsystem] label Nov 22, 2025
@Denver-22
Copy link
Contributor Author

I tested the code suggested by ai. It works.

Copilot finished reviewing on behalf of jmcouffin November 22, 2025 08:13
Copy link
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 fixes a bug in the pick_linked() and pick_linkeds() methods where they were incorrectly attempting to retrieve linked elements using GetGeometryObjectFromReference() instead of properly accessing the linked document and element.

Key Changes:

  • Fixed linked element retrieval by checking if the picked object is a RevitLinkInstance and using GetLinkDocument() and LinkedElementId to access the actual element in the linked document
  • Refactored the geometry object retrieval logic from a list comprehension to an explicit loop to accommodate the conditional handling

removed comment explaining change to previous code
@jmcouffin jmcouffin merged commit 76dbb3a into pyrevitlabs:develop Nov 22, 2025
@github-actions
Copy link
Contributor

📦 New work-in-progress (wip) builds are available for 5.3.1.25326+1040-wip

@github-actions
Copy link
Contributor

📦 New work-in-progress (wip) builds are available for 5.3.1.25326+2050-wip

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

Labels

Tools Issues related to pyRevit commands [subsystem]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants