bool IGH_PersistentElementComponent.NeedsToBeExpired(Autodesk.Revit.DB.Events.DocumentChangedEventArgs e) { var filter = new Autodesk.Revit.DB.ElementClassFilter(typeof(Level)); var added = e.GetAddedElementIds(filter); if (added.Count > 0) { return(true); } var deleted = e.GetDeletedElementIds(); if (deleted.Count > 0) { var document = e.GetDocument(); var empty = new ElementId[0]; foreach (var param in Params.Output.OfType <Parameters.IGH_PersistentElementParam>()) { if (param.NeedsToBeExpired(document, empty, deleted, empty)) { return(true); } } } return(false); }
public static IList <Element> OfElementType(Type elementType) { if (elementType == null) { return(null); } /* * (Konrad) According to RevitAPI documentation the quick filter * ElementClassFilter() has certain limitations that prevent it * from working on certain derived classes. In that case we need * to collect elements from base class and then perform additional * filtering to get our intended element set. */ if (ClassFilterExceptions.Contains(elementType)) { var type = GetClassFilterExceptionsValidType(elementType); return(new Autodesk.Revit.DB.FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument) .OfClass(type) .Where(x => x.GetType() == elementType) .Select(x => ElementSelector.ByElementId(x.Id.IntegerValue)) .ToList()); } var classFilter = new Autodesk.Revit.DB.ElementClassFilter(elementType); return(new Autodesk.Revit.DB.FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument) .WherePasses(classFilter) .ToElementIds() .Select(x => ElementSelector.ByElementId(x.IntegerValue)) .ToList()); }
protected override void TrySolveInstance(IGH_DataAccess DA) { // get input DB.CurtainGridLine gridLine = default; if (!DA.GetData("Curtain Grid Line", ref gridLine)) { return; } DA.SetData("Curve", gridLine.FullCurve.ToCurve()); DA.SetDataList("Segments", gridLine.AllSegmentCurves.ToCurves()); DA.SetDataList("Existing Segments", gridLine.ExistingSegmentCurves.ToCurves()); DA.SetDataList("Skipped Segments", gridLine.SkippedSegmentCurves.ToCurves()); // find attached mullions const double EPSILON = 0.1; var attachedMullions = new List <Types.Element>(); var famInstFilter = new DB.ElementClassFilter(typeof(DB.FamilyInstance)); // collect familyinstances and filter for DB.Mullion var dependentMullions = gridLine.GetDependentElements(famInstFilter).Select(x => gridLine.Document.GetElement(x)).OfType <DB.Mullion>(); // for each DB.Mullion that is dependent on this DB.CurtainGridLine foreach (DB.Mullion mullion in dependentMullions) { if (mullion.LocationCurve != null) { // check the distance of the DB.Mullion curve start and end, to the DB.CurtainGridLine axis curve var mcurve = mullion.LocationCurve; var mstart = mcurve.GetEndPoint(0); var mend = mcurve.GetEndPoint(1); // if the distance is less than EPSILON, the DB.Mullion axis and DB.CurtainGridLine axis are almost overlapping if (gridLine.FullCurve.Distance(mstart) < EPSILON && gridLine.FullCurve.Distance(mend) < EPSILON) { attachedMullions.Add(Types.CurtainGridMullion.FromElement(mullion)); } } } DA.SetDataList("Attached Mullions", attachedMullions); // filter attached panels // panels can be a mix of DB.Panel and DB.FamilyInstance // no need to filter for .OfType<DB.Panel>() like with DB.Mullion // but make sure to remove all the DB.FamilyInstance that are actually DB.Mullion var dependentPanels = gridLine.GetDependentElements(famInstFilter).Select(x => gridLine.Document.GetElement(x)).Where(x => x as DB.Mullion is null); DA.SetDataList("Attached Panels", dependentPanels.Select(x => Types.Element.FromElement(x))); }
protected override void TrySolveInstance(IGH_DataAccess DA) { DB.HostObject host = null; if (!DA.GetData("Host", ref host) || host is null) { return; } using (var filter = new DB.ElementClassFilter(typeof(DB.Sketch))) { var sketckIds = host.GetDependentElements(filter); if (sketckIds.Select(x => host.Document.GetElement(x)).FirstOrDefault() is DB.Sketch sketch) { DA.SetData("Plane", sketch.SketchPlane.GetPlane().ToPlane()); DA.SetDataList("Profile", sketch.Profile.ToPolyCurves()); } } }
//----------------Miscellaneous -------------------------- //return list of all generic family instances in the current model public static List <FamilyInstance> getAllGenericFamilies(Document curDoc) { //create filters Autodesk.Revit.DB.ElementClassFilter familyfilter = new Autodesk.Revit.DB.ElementClassFilter(typeof(Autodesk.Revit.DB.FamilyInstance)); Autodesk.Revit.DB.ElementCategoryFilter typeFilter = new Autodesk.Revit.DB.ElementCategoryFilter(BuiltInCategory.OST_GenericModel); Autodesk.Revit.DB.LogicalAndFilter andFilter = new Autodesk.Revit.DB.LogicalAndFilter(familyfilter, typeFilter); //create collector and filter Autodesk.Revit.DB.FilteredElementCollector collector = new Autodesk.Revit.DB.FilteredElementCollector(curDoc); collector.WherePasses(andFilter); //create list for family instances List <FamilyInstance> famList = new List <FamilyInstance>(); //loop through collector and add to list foreach (FamilyInstance curFam in collector) { famList.Add(curFam); } return(famList); }
public static IList <Element> OfFamilyType(FamilyType familyType) { if (familyType == null) { return(null); } var instanceFilter = new Autodesk.Revit.DB.ElementClassFilter(typeof(Autodesk.Revit.DB.FamilyInstance)); var fec = new Autodesk.Revit.DB.FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument); var familyInstances = fec.WherePasses(instanceFilter) .WhereElementIsNotElementType() .ToElements() .Cast <Autodesk.Revit.DB.FamilyInstance>(); var matches = familyInstances.Where(x => x.Symbol.Id == familyType.InternalFamilySymbol.Id); var instances = matches .Select(x => ElementSelector.ByElementId(x.Id.IntegerValue)).ToList(); return(instances); }
/// <summary> /// Populate Items in Dropdown menu /// </summary> public void PopulateDropDownItems() { if (this.ObjectType != null) { // Clear the dropdown list Items.Clear(); revitDoc doc = DocumentManager.Instance.CurrentDBDocument; revitDB.ElementFilter typeFilter = new revitDB.ElementClassFilter(ObjectType); revitDB.FilteredElementCollector collect = new revitDB.FilteredElementCollector(doc); collect.WherePasses(typeFilter); // Get all enumeration names and add them to the dropdown menu foreach (revitDB.Element elem in collect) { Items.Add(new CoreNodeModels.DynamoDropDownItem(elem.Name, elem)); } Items = Items.OrderBy(x => x.Name).ToObservableCollection(); } }
protected override void TrySolveInstance(IGH_DataAccess DA) { DB.Element element = null; if (!DA.GetData("Element", ref element) || element is null) { return; } // Special cases if (element is DB.FamilyInstance familyInstace) { DA.SetData("Host", Types.HostObject.FromElement(familyInstace.Host)); return; } else if (element is DB.Opening opening) { DA.SetData("Host", Types.HostObject.FromElement(opening.Host)); return; } else if (element.get_Parameter(DB.BuiltInParameter.HOST_ID_PARAM) is DB.Parameter hostId) { DA.SetData("Host", Types.HostObject.FromElementId(element.Document, hostId.AsElementId())); return; } // Search geometrically if (element.get_BoundingBox(null) is DB.BoundingBoxXYZ bbox) { using (var collector = new DB.FilteredElementCollector(element.Document)) { var elementCollector = collector.OfClass(typeof(DB.HostObject)); if (element.Category.Parent is DB.Category hostCategory) { elementCollector = elementCollector.OfCategoryId(hostCategory.Id); } var bboxFilter = new DB.BoundingBoxIntersectsFilter(new DB.Outline(bbox.Min, bbox.Max)); elementCollector = elementCollector.WherePasses(bboxFilter); var classFilter = default(DB.ElementFilter); if (element is DB.FamilyInstance instance) { classFilter = new DB.FamilyInstanceFilter(element.Document, instance.GetTypeId()); } else if (element is DB.Area) { classFilter = new DB.AreaFilter(); } else if (element is DB.AreaTag) { classFilter = new DB.AreaTagFilter(); } else if (element is DB.Architecture.Room) { classFilter = new DB.Architecture.RoomFilter(); } else if (element is DB.Architecture.RoomTag) { classFilter = new DB.Architecture.RoomTagFilter(); } else if (element is DB.Mechanical.Space) { classFilter = new DB.Mechanical.SpaceFilter(); } else if (element is DB.Mechanical.SpaceTag) { classFilter = new DB.Mechanical.SpaceTagFilter(); } else { if (element is DB.CurveElement) { classFilter = new DB.ElementClassFilter(typeof(DB.CurveElement)); } else { classFilter = new DB.ElementClassFilter(element.GetType()); } } foreach (var host in elementCollector.Cast <DB.HostObject>()) { if (host.Id == element.Id) { continue; } if (host.FindInserts(false, true, true, false).Contains(element.Id)) { DA.SetData("Host", Types.HostObject.FromElement(host)); break; } // Necessary to found Panel walls in a Curtain Wall else if (host.GetDependentElements(classFilter).Contains(element.Id)) { DA.SetData("Host", Types.HostObject.FromElement(host)); break; } } } } }