Can't select elements in a linked model

Can't select elements in a linked model

DanielKP2Z9V
Advocate Advocate
778 Views
6 Replies
Message 1 of 7

Can't select elements in a linked model

DanielKP2Z9V
Advocate
Advocate

I'm trying to select all columns in a linked model. However this doesn't work. It correctly gets Ids of the column elements, but the final ` uiDoc.Selection.SetElementIds(columnIds);` doesn't select anything.

 

Any help would be really appreciated.

 

    [Transaction(TransactionMode.Manual)]
    public class SelectLinkedColumns : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            // Get the Revit application and document
            UIApplication uiApp = commandData.Application;
            UIDocument uiDoc = uiApp.ActiveUIDocument;
            Document doc = uiDoc.Document;

            try
            {
                // Prompt user to select a linked Revit model
                Reference linkedRef = uiDoc.Selection.PickObject(ObjectType.LinkedElement, "Select a linked Revit model");
                Element linkedElement = doc.GetElement(linkedRef.LinkedElementId);
                RevitLinkInstance linkedInstance = linkedElement as RevitLinkInstance;
                Document linkedDoc = linkedInstance.GetLinkDocument();

                // Select all columns in the linked model
                FilteredElementCollector collector = new FilteredElementCollector(linkedDoc);
                ICollection<ElementId> columnIds = collector.OfCategory(BuiltInCategory.OST_Columns)
                                                            .WhereElementIsNotElementType()
                                                            .ToElementIds();

                // Select the columns
                uiDoc.Selection.SetElementIds(columnIds);

                TaskDialog.Show("Success", $"Selected {columnIds.Count} columns in the linked model.");
            }
            catch (Exception ex)
            {
                TaskDialog.Show("Error", ex.Message);
                return Result.Failed;
            }

            return Result.Succeeded;
        }
    }
0 Likes
779 Views
6 Replies
Replies (6)
Message 2 of 7

scgq425
Advocate
Advocate
Accepted solution

Hi @DanielKP2Z9V :

u can see this solution , has code to select link element

https://forums.autodesk.com/t5/revit-api-forum/can-not-select-any-linked-element-in-revit-using-revi...  

LanHui Xu 徐兰辉
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Blog
LinkedIn
Revit/CAD Development | Steel Product Manager

EESignature

0 Likes
Message 3 of 7

Mohamed_Arshad
Advisor
Advisor
Accepted solution

HI @DanielKP2Z9V 

 

      Unfortunately, we aren't able to Highlight Linked Model Elements. This feature is not available in Revit API :(. 

 

Highlight Linked Elements discussion threat

https://forums.autodesk.com/t5/revit-api-forum/highlight-and-tag-linked-elements/m-p/5294217#M7339 

 

A small suggestion in your code

 

  // Prompt user to select a linked Revit model
  // You can directly select Linked Model itself, don't need to select Linked Element
                Reference linkedRef = uiDoc.Selection.PickObject(ObjectType.Element, "Select a linked Revit model");
                Element linkedModel = doc.GetElement(linkedRef);
                RevitLinkInstance linkedInstance = linkedModel as RevitLinkInstance;
                Document linkedDoc = linkedInstance.GetLinkDocument();

 

 

Hope this will helps 🙂


Mohamed Arshad K
Software Developer (CAD & BIM)

Message 4 of 7

DanielKP2Z9V
Advocate
Advocate
Accepted solution

@scgq425 by select I mean to select them in the Revit UI - the same way the user selects objects in a linked model by pressing TAB and left mouse button

0 Likes
Message 5 of 7

DanielKP2Z9V
Advocate
Advocate
Accepted solution

thanks @Mohamed_Arshad, do you know where users can vote up this feature to be added to Revit API?

0 Likes
Message 6 of 7

Mohamed_Arshad
Advisor
Advisor
Accepted solution

HI @DanielKP2Z9V 

     Already a threat has been raised in Idea Station and it is also accepted by the Autodesk Team. But I don't why they are not implemented still 😞  You can post your vote in the below link with a comment. Let's see 🙂

 

Voting URL: https://forums.autodesk.com/t5/revit-ideas/highlight-element-selection-in-linked-files/idi-p/7619701 

 

Hope this will Help 🙂


Mohamed Arshad K
Software Developer (CAD & BIM)

0 Likes
Message 7 of 7

DanielKP2Z9V
Advocate
Advocate

Threats won't help us convince autodesk to implementing users' ideas 🙂 but thanks for sharing the link - I've upvoted it as well

 

By the way this is not a solution - I've accidentally pressed that button and there doesn't seem to be a way to uncheck it now