Message 1 of 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.