public Updater() { DB.UpdaterRegistry.RegisterUpdater(this); var filter = new DB.ElementCategoryFilter(DB.BuiltInCategory.INVALID, true); DB.UpdaterRegistry.AddTrigger(UpdaterId, filter, DB.Element.GetChangeTypeAny()); DB.UpdaterRegistry.AddTrigger(UpdaterId, filter, DB.Element.GetChangeTypeElementDeletion()); }
/// <summary> /// Gets all DesignOptionSets in the document /// </summary> /// <param name="document">A Autodesk.Revit.DB.Document object. This does not work with Dynamo document objects.</param> /// <returns name="DesignOptionSets">The design option sets in the document</returns> public static IList <revitElem> DesignOptionSets([DefaultArgument("Synthetic.Revit.Document.Current()")] revitDoc document) { revitDB.ElementCategoryFilter catFilter = new revitDB.ElementCategoryFilter(revitDB.BuiltInCategory.OST_DesignOptionSets); revitDB.FilteredElementCollector collectSets = new revitDB.FilteredElementCollector(document); return(collectSets .WherePasses(catFilter) .Cast <revitDB.Element>() .ToList()); }
/// <summary> /// Given the name of the design option set, returns a list of set's design options. /// </summary> /// <param name="DesignOptionSetName">The name of the Design Option Set</param> /// <param name="document">A Autodesk.Revit.DB.Document object. This does not work with Dynamo document objects.</param> /// <returns name="DesignOptions">A list of design options that belong to the DesignOptionSet</returns> public static IList <dynElem> GetDesignOptionsBySet(string DesignOptionSetName, [DefaultArgument("Synthetic.Revit.Document.Current()")] revitDoc document) { revitDB.ElementCategoryFilter catFilter = new revitDB.ElementCategoryFilter(revitDB.BuiltInCategory.OST_DesignOptionSets); revitDB.FilteredElementCollector collectSets = new revitDB.FilteredElementCollector(document); IList <revitElem> sets = collectSets .WherePasses(catFilter) .Cast <revitDB.Element>() .Where(elem => elem.Name == DesignOptionSetName) .ToList(); IList <revitDB.ElementFilter> paramFilters = new List <revitDB.ElementFilter>(); foreach (revitElem set in sets) { revitDB.ElementId id = set.Id; revitDB.FilterNumericRuleEvaluator eval = new revitDB.FilterNumericEquals(); revitDB.ParameterValueProvider provider = new revitDB.ParameterValueProvider(new revitDB.ElementId(revitDB.BuiltInParameter.OPTION_SET_ID)); revitDB.FilterRule filterRule = new revitDB.FilterElementIdRule(provider, eval, id); paramFilters.Add(new revitDB.ElementParameterFilter(filterRule)); } revitDB.ElementFilter orFilter = new revitDB.LogicalOrFilter(paramFilters); catFilter = new revitDB.ElementCategoryFilter(revitDB.BuiltInCategory.OST_DesignOptions); revitDB.LogicalAndFilter filter = new revitDB.LogicalAndFilter(new List <revitDB.ElementFilter> { orFilter, catFilter }); revitDB.FilteredElementCollector collectOptions = new revitDB.FilteredElementCollector(document); IList <revitDB.Element> elements = collectOptions.WherePasses(filter).ToElements(); IList <dynElem> dynamoElements = new List <dynElem>(); foreach (revitDB.Element elem in elements) { try { dynamoElements.Add(elem.ToDSType(true)); } catch { } } return(dynamoElements); }
public static IList <Element> OfCategory(Category category, Revit.Elements.Views.View view = null) { if (category == null) { return(null); } var catFilter = new Autodesk.Revit.DB.ElementCategoryFilter(category.InternalCategory.Id); var fec = (view == null) ? new Autodesk.Revit.DB.FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument) : new Autodesk.Revit.DB.FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument, view.InternalView.Id); var instances = fec.WherePasses(catFilter) .WhereElementIsNotElementType() .ToElementIds() .Select(id => ElementSelector.ByElementId(id.IntegerValue)) .ToList(); return(instances); }
//----------------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); }
/// <summary> /// Retrive family instance hosted in boundary elements /// This is the base function for Windows and Doors /// </summary> /// <param name="cat">The category of hosted elements</param> /// <returns></returns> private List<FamilyInstance> BoundaryFamilyInstance(DB.BuiltInCategory cat) { List<FamilyInstance> output = new List<FamilyInstance>(); //the document of the room DB.Document doc = InternalElement.Document; // DocumentManager.Instance.CurrentDBDocument; //Find boundary elements and their associated document List<DB.ElementId> boundaryElements = new List<DB.ElementId>(); List<DB.Document> boundaryDocuments = new List<DB.Document>(); foreach (DB.BoundarySegment segment in InternalBoundarySegments) { DB.Element boundaryElement = doc.GetElement(segment.ElementId); if (boundaryElement.GetType() == typeof(DB.RevitLinkInstance)) { DB.RevitLinkInstance linkInstance = boundaryElement as DB.RevitLinkInstance; boundaryDocuments.Add(linkInstance.GetLinkDocument()); boundaryElements.Add(segment.LinkElementId); } else { boundaryDocuments.Add(doc); boundaryElements.Add(segment.ElementId); } } // Create a category filter DB.ElementCategoryFilter filter = new DB.ElementCategoryFilter(cat); // Apply the filter to the elements in these documents, // Use shortcut WhereElementIsNotElementType() to find family instances in all boundary documents boundaryDocuments = boundaryDocuments.Distinct().ToList(); List<DB.FamilyInstance> familyInstances = new List<DB.FamilyInstance>(); foreach (DB.Document boundaryDocument in boundaryDocuments) { DB.FilteredElementCollector collector = new DB.FilteredElementCollector(boundaryDocument); familyInstances.AddRange(collector.WherePasses(filter).WhereElementIsNotElementType().ToElements().Cast<DB.FamilyInstance>().ToList()); } //Find all family instance hosted on a boundary element IEnumerable<DB.FamilyInstance> boundaryFamilyInstances = familyInstances.Where(s => boundaryElements.Contains(s.Host.Id)); //loop on these boundary family instance to find to and from room foreach (DB.FamilyInstance boundaryFamilyInstance in boundaryFamilyInstances) { DB.Phase familyInstancePhase = boundaryFamilyInstance.Document.GetElement(boundaryFamilyInstance.CreatedPhaseId) as DB.Phase; if (boundaryFamilyInstance.get_FromRoom(familyInstancePhase) != null) { if (boundaryFamilyInstance.get_FromRoom(familyInstancePhase).Id == InternalRoom.Id) { output.Add(ElementWrapper.ToDSType(boundaryFamilyInstance, true) as FamilyInstance); continue; } } if (boundaryFamilyInstance.get_ToRoom(familyInstancePhase) != null) { if (boundaryFamilyInstance.get_ToRoom(familyInstancePhase).Id == InternalRoom.Id) { output.Add(ElementWrapper.ToDSType(boundaryFamilyInstance, true) as FamilyInstance); } } } output = output.Distinct().ToList(); return output; }
/// <summary> /// Retrive family instance hosted in boundary elements /// This is the base function for Windows and Doors /// </summary> /// <param name="cat">The category of hosted elements</param> /// <returns></returns> private List <FamilyInstance> BoundaryFamilyInstance(DB.BuiltInCategory cat) { List <FamilyInstance> output = new List <FamilyInstance>(); //the document of the room DB.Document doc = InternalElement.Document; // DocumentManager.Instance.CurrentDBDocument; //Find boundary elements and their associated document List <DB.ElementId> boundaryElements = new List <DB.ElementId>(); List <DB.Document> boundaryDocuments = new List <DB.Document>(); foreach (DB.BoundarySegment segment in InternalBoundarySegments) { DB.Element boundaryElement = doc.GetElement(segment.ElementId); if (boundaryElement.GetType() == typeof(DB.RevitLinkInstance)) { DB.RevitLinkInstance linkInstance = boundaryElement as DB.RevitLinkInstance; boundaryDocuments.Add(linkInstance.GetLinkDocument()); boundaryElements.Add(segment.LinkElementId); } else { boundaryDocuments.Add(doc); boundaryElements.Add(segment.ElementId); } } // Create a category filter DB.ElementCategoryFilter filter = new DB.ElementCategoryFilter(cat); // Apply the filter to the elements in these documents, // Use shortcut WhereElementIsNotElementType() to find family instances in all boundary documents boundaryDocuments = boundaryDocuments.Distinct().ToList(); List <DB.FamilyInstance> familyInstances = new List <DB.FamilyInstance>(); foreach (DB.Document boundaryDocument in boundaryDocuments) { DB.FilteredElementCollector collector = new DB.FilteredElementCollector(boundaryDocument); familyInstances.AddRange(collector.WherePasses(filter).WhereElementIsNotElementType().ToElements().Cast <DB.FamilyInstance>().ToList()); } //Find all family instance hosted on a boundary element IEnumerable <DB.FamilyInstance> boundaryFamilyInstances = familyInstances.Where(s => boundaryElements.Contains(s.Host.Id)); //loop on these boundary family instance to find to and from room foreach (DB.FamilyInstance boundaryFamilyInstance in boundaryFamilyInstances) { DB.Phase familyInstancePhase = boundaryFamilyInstance.Document.GetElement(boundaryFamilyInstance.CreatedPhaseId) as DB.Phase; if (boundaryFamilyInstance.get_FromRoom(familyInstancePhase) != null) { if (boundaryFamilyInstance.get_FromRoom(familyInstancePhase).Id == InternalRoom.Id) { output.Add(ElementWrapper.ToDSType(boundaryFamilyInstance, true) as FamilyInstance); continue; } } if (boundaryFamilyInstance.get_ToRoom(familyInstancePhase) != null) { if (boundaryFamilyInstance.get_ToRoom(familyInstancePhase).Id == InternalRoom.Id) { output.Add(ElementWrapper.ToDSType(boundaryFamilyInstance, true) as FamilyInstance); } } } output = output.Distinct().ToList(); return(output); }
public static List <Model.Entity.Pile> GetIntersectEttPiles(this Model.Entity.Element ettElem) { var setting = ModelData.Instance.Setting; var settingCate = setting.Category.Id; var verOrHorFraming = setting.VerOrHor; var distanceFromPile2Path = setting.DistanceFromPile2Path; List <Model.Entity.Pile> intersectEttPiles = new List <Model.Entity.Pile>(); //var foundationCate = new Autodesk.Revit.DB.ElementCategoryFilter(BuiltInCategory.OST_StructuralFoundation); var cateFilter = new Autodesk.Revit.DB.ElementCategoryFilter(settingCate); var revitElem = ettElem.RevitElement; var bbRevitElem = revitElem.get_BoundingBox(null); var ol = new Autodesk.Revit.DB.Outline(bbRevitElem.Min, bbRevitElem.Max); var bbIntersectFilter = new Autodesk.Revit.DB.BoundingBoxIntersectsFilter(ol); var intersectPiles = new FilteredElementCollector(revitData.Document).WherePasses(cateFilter) .WherePasses(bbIntersectFilter).ToList(); var curvePath = (revitElem.Location as LocationCurve).Curve; XYZ itemPoint = null; Curve curveFraming = null; //revitData.Selection.SetElementIds(intersectPiles.Select(x => x.Id).ToList()); // Test Intersected Pile foreach (var item in intersectPiles) { if (settingCate.IntegerValue == (int)BuiltInCategory.OST_StructuralFoundation) { itemPoint = (item.Location as LocationPoint).Point; } else if (settingCate.IntegerValue == (int)BuiltInCategory.OST_StructuralFraming) { curveFraming = (item.Location as LocationCurve).Curve; itemPoint = (curveFraming.GetEndPoint(0) + curveFraming.GetEndPoint(1)) / 2; } var intersectionResult = curvePath.Project(itemPoint); var projection2curve = intersectionResult.XYZPoint; double distance2P = itemPoint.Distance2P(projection2curve); if (distance2P < distanceFromPile2Path.milimeter2Feet()) { switch (verOrHorFraming) { case Model.Entity.VerOrHor.HorizontalX: { if ((curveFraming as Line).Direction.IsXOrY()) { intersectEttPiles.Add(new Model.Entity.Pile { RevitElement = item }); } break; } case Model.Entity.VerOrHor.VerticalY: { if (!(curveFraming as Line).Direction.IsXOrY()) { intersectEttPiles.Add(new Model.Entity.Pile { RevitElement = item }); } break; } default: { intersectEttPiles.Add(new Model.Entity.Pile { RevitElement = item }); break; } } //intersectEttPiles.Add(new Model.Entity.Pile { RevitElement = item }); //revitData.Document.Create.NewDetailCurve(revitData.ActiveView, Line.CreateBound(projection2curve, itemPoint)); } } //ettElem.IntersectEttPiles.ForEach(x => x.HostEttElement = ettElem); return(intersectEttPiles); }