Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Can't select elements in a linked model

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
DanielKP2Z9V
464 Views, 6 Replies

Can't select elements in a linked model

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;
        }
    }
6 REPLIES 6
Message 2 of 7
scgq425
in reply to: DanielKP2Z9V

Message 3 of 7

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 🙂

Thanks & Regards,
Mohamed Arshad K
Message 4 of 7
DanielKP2Z9V
in reply to: scgq425

@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

Message 5 of 7

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

Message 6 of 7

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 🙂

Thanks & Regards,
Mohamed Arshad K
Message 7 of 7

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report