I am trying to follow the "Retrieve Filter Elements" sample file from the API Developer Guide. Basically it is a copy what is on the page exercise, but there is enough left out (which I am sure any programmer would know) to leave me in the dust. If someone could explain what is missing from this code to make it functional, I would appreciate it. I know at least part of the problem is in identifying the active document, but I just don't know what is missing. The build error says the name 'uiDoc' does not exist in the current context. The sample file is simply finding and displaying all the door ids in an open file.
Code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Autodesk.Revit.UI; using Autodesk.Revit.DB; using Autodesk.Revit.Attributes; using Autodesk.Revit.UI.Selection; namespace FilteredElements { [Autodesk.Revit.Attributes.Transaction(TransactionMode.Automatic)] public class Class1 : IExternalCommand { public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { { UIDocument uidoc = commandData.Application.ActiveUIDocument; ElementClassFilter familyInstanceFilter = new ElementClassFilter(typeof(FamilyInstance)); ElementCategoryFilter doorsCategoryFilter = new ElementCategoryFilter(BuiltInCategory.OST_Doors); LogicalAndFilter doorInstancesFilter = new LogicalAndFilter(familyInstanceFilter, doorsCategoryFilter); FilteredElementCollector collector = new FilteredElementCollector(uiDoc); ICollection<ElementId> doors = collector.WherePasses(doorInstancesFilter).ToElementIds(); String prompt = "The ids of the doors in the current document are: "; foreach (ElementId id in doors) { prompt += "n\t" + id.IntegerValue; } TaskDialog.Show("Revit", prompt); } } } }
Comment