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;
}
}
Solved! Go to Solution.
Solved by Mohamed_Arshad. Go to Solution.
Solved by DanielKP2Z9V. Go to Solution.
Solved by DanielKP2Z9V. Go to Solution.
Solved by Mohamed_Arshad. Go to Solution.
Solved by scgq425. Go to Solution.
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 @Mohamed_Arshad, do you know where users can vote up this feature to be added to Revit API?
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 🙂
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.