public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Document doc = commandData.Application.ActiveUIDocument.Document; ElementFilter door_Category = new ElementCategoryFilter(BuiltInCategory.OST_Doors); //获取门类别 ElementFilter door_FamilyInstance = new ElementClassFilter(typeof(FamilyInstance)); //获取族实例 LogicalAndFilter doorFamilyInstance = new LogicalAndFilter(door_Category, door_FamilyInstance); FilteredElementCollector doorFiltered = new FilteredElementCollector(doc).WherePasses(doorFamilyInstance); IList <Element> door_elements = doorFiltered.ToElements(); ParameterSet paras = null; foreach (Element elems in door_elements) { paras = elems.Parameters; } string paraName = ""; foreach (Parameter para in paras) { paraName += "\n\t" + para.Definition.Name; } File.WriteAllText(@"D:\door.txt", paraName); return(Result.Succeeded); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication app = commandData.Application; m_doc = app.ActiveUIDocument.Document; // filter for family instance and (door or window): ElementClassFilter fFamInstClass = new ElementClassFilter(typeof(FamilyInstance)); ElementCategoryFilter fDoorCat = new ElementCategoryFilter(BuiltInCategory.OST_Doors); ElementCategoryFilter fWindowCat = new ElementCategoryFilter(BuiltInCategory.OST_Windows); LogicalOrFilter fCat = new LogicalOrFilter(fDoorCat, fWindowCat); LogicalAndFilter f = new LogicalAndFilter(fCat, fFamInstClass); FilteredElementCollector openings = new FilteredElementCollector(m_doc); openings.WherePasses(f); // map with key = host element id and // value = list of hosted element ids: Dictionary <ElementId, List <ElementId> > ids = GetElementIds(openings); DumpHostedElements(ids); m_doc = null; return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var uiApp = commandData.Application; var uiDoc = uiApp.ActiveUIDocument; var app = uiApp.Application; var doc = uiDoc.Document; // Start code here // Lay nhung doi tuong dang chon try { var familyInstanceFilter = new ElementClassFilter(typeof(FamilyInstance)); var doorsCategoryFilter = new ElementCategoryFilter(BuiltInCategory.OST_Doors); var listFilter = new List <ElementFilter>() { new ElementCategoryFilter(BuiltInCategory.OST_Doors) }; //var doorInstancesFilters = new LogicalAndFilter(listFilter); var doorInstancesFilters = new LogicalAndFilter(familyInstanceFilter, doorsCategoryFilter); var collector = new FilteredElementCollector(doc); var doors = collector.WherePasses(doorInstancesFilters).ToElements(); TaskDialog.Show("Door Count", doors.Count().ToString()); return(Result.Succeeded); } catch (Exception e) { message = e.Message; return(Result.Failed); } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = commandData.Application.ActiveUIDocument.Document; FilteredElementCollector filteredElements = new FilteredElementCollector(doc); //创建一个收集器 ElementFilter wallCategory = new ElementCategoryFilter(BuiltInCategory.OST_Walls); ElementFilter wallClass = new ElementClassFilter(typeof(Wall)); LogicalAndFilter wallFitered = new LogicalAndFilter(wallCategory, wallClass); filteredElements.WherePasses(wallFitered); IList <Wall> walls = new List <Wall>(); foreach (Wall wal in filteredElements) { var functionParameter = wal.WallType.get_Parameter(BuiltInParameter.FUNCTION_PARAM); if ((functionParameter != null) && (functionParameter.StorageType == StorageType.Integer)) { IList <ElementId> walls_ids = new List <ElementId>(); if (functionParameter.AsInteger() == (int)WallFunction.Exterior) { walls.Add(wal); foreach (Wall wa in walls) { walls_ids.Add(wa.Id); } } uidoc.Selection.SetElementIds(walls_ids); //将图元设置为选中状态 } } return(Result.Succeeded); }
protected override Result ExecuteCommand(ExternalCommandData data, ref string message, ElementSet elements) { _app = data.Application; _doc = data.Application.ActiveUIDocument.Document; Selection selection = data.Application.ActiveUIDocument.Selection; List <ElementId> elementIds = selection.GetElementIds().ToList(); if (elementIds.Count == 0) { TaskDialog.Show("提示", "您未选择任何图元"); } else { string info = "您选择的图元ID列表:"; foreach (var item in elementIds) { info += "\n\t" + item.IntegerValue; } TaskDialog.Show("提示", info); } ElementClassFilter familyInstanceFilter = new ElementClassFilter(typeof(FamilyInstance)); ElementCategoryFilter doorCategoryFilter = new ElementCategoryFilter(BuiltInCategory.OST_Doors); LogicalAndFilter logicalAndFilter = new LogicalAndFilter(familyInstanceFilter, doorCategoryFilter); FilteredElementCollector collector = new FilteredElementCollector(_doc); List <ElementId> doors = collector.WherePasses(logicalAndFilter).ToElementIds().ToList(); string info2 = "文档中的门ID列表:"; foreach (var item in doors) { info2 += "\n\t" + item.IntegerValue; } TaskDialog.Show("提示", info2); return(Result.Succeeded); }
//***********************************GetFamilySymbols*********************************** public List <FamilyInstance> GetFamilyInstance(Document doc, string name, BuiltInCategory category) { List <FamilyInstance> List_FamilyInstance = new List <FamilyInstance>(); ElementClassFilter familyInstanceFilter = new ElementClassFilter(typeof(FamilyInstance)); // Category filter ElementCategoryFilter Categoryfilter = new ElementCategoryFilter(category); // Instance filter LogicalAndFilter InstancesFilter = new LogicalAndFilter(familyInstanceFilter, Categoryfilter); FilteredElementCollector collector = new FilteredElementCollector(doc); // Colletion Array of Elements ICollection <Element> Elements = collector.WherePasses(InstancesFilter).ToElements(); foreach (Element e in Elements) { FamilyInstance familyInstance = e as FamilyInstance; if (null != familyInstance) { try { if (familyInstance.Name.Contains(name)) { List_FamilyInstance.Add(familyInstance); } } catch (Exception ex) { string x = ex.Message; } } } return(List_FamilyInstance); }
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements) { UIApplication uiapp = commandData.Application; Autodesk.Revit.ApplicationServices.Application app = uiapp.Application; Document doc = uiapp.ActiveUIDocument.Document; //获得所有窗户 FilteredElementCollector collector = new FilteredElementCollector(doc); collector.OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_Windows); IList <Element> lists = collector.ToElements(); string strNsg = string.Format("there are {0} windows in current models", lists.Count); MessageBox.Show(strNsg); //过滤器获得所有的门 FilteredElementCollector collector2 = new FilteredElementCollector(doc); ElementClassFilter classFilter = new ElementClassFilter(typeof(FamilyInstance)); ElementCategoryFilter catfilter = new ElementCategoryFilter(BuiltInCategory.OST_Doors); LogicalAndFilter logicalfilter = new LogicalAndFilter(classFilter, catfilter); collector2.WherePasses(logicalfilter); IList <Element> list2 = collector2.ToElements(); strNsg = string.Format("there Area {0} doors in current mode", list2.Count); MessageBox.Show(strNsg); return(Result.Succeeded); }
public void DeleteDoorsOfRoom(Document doc, ElementId dangerRoom) { ElementClassFilter familyInstancefilter = new ElementClassFilter(typeof(FamilyInstance)); ElementCategoryFilter doorfilter = new ElementCategoryFilter(BuiltInCategory.OST_Doors); LogicalAndFilter doorInstancefilter = new LogicalAndFilter(familyInstancefilter, doorfilter); FilteredElementCollector col = new FilteredElementCollector(doc); ICollection <ElementId> doors = col.WherePasses(doorInstancefilter).ToElementIds(); var rel = new List <ElementId>(); string debug = ""; foreach (ElementId id in doors) { Element door = doc.GetElement(id); FamilyInstance doorfam = door as FamilyInstance; Room temp1 = doorfam.FromRoom; Room temp2 = doorfam.ToRoom; if (temp1 != null && temp1.Id == dangerRoom) { DeleteEle(doc, door); continue; } if (temp2 != null && temp2.Id == dangerRoom) { DeleteEle(doc, door); continue; } } //TaskDialog.Show("Revit", debug); }
public static List<LevelData> GetLevelsFromDocument(Document doc) { if (doc == null) return null; var classFilter = new ElementClassFilter(typeof(Level)); var levelCategoryFilter = new ElementCategoryFilter(BuiltInCategory.OST_Levels); var logicalFilter = new LogicalAndFilter(classFilter, levelCategoryFilter); var collector = new FilteredElementCollector(doc); var levElems = collector.WherePasses(logicalFilter).ToElements(); var res = new List<LevelData>(); foreach (var elem in levElems) { var level = elem as Level; res.Add(new LevelData { Name = level.Name, Height = level.Elevation }); } res.Sort((a, b) => a.Height.CompareTo(b.Height)); return res; }
public static List <Category> GetNotEmptyCategories(List <Document> documents, Categories categories) { ElementCategoryFilter f1 = new ElementCategoryFilter(BuiltInCategory.OST_Rooms, true); ElementCategoryFilter f2 = new ElementCategoryFilter(BuiltInCategory.OST_PipeSegments, true); ElementCategoryFilter f3 = new ElementCategoryFilter(BuiltInCategory.OST_Materials, true); List <ElementFilter> filters = new List <ElementFilter>() { f1, f2, f3 }; LogicalAndFilter filter = new LogicalAndFilter(filters); List <Category> categoryList = new List <Category>(); foreach (Document d in documents) { foreach (Category c in categories) { BuiltInCategory bCat = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), c.Id.ToString()); if (c.CategoryType == CategoryType.Model) { FilteredElementCollector coll = new FilteredElementCollector(d).OfCategoryId(c.Id).WhereElementIsNotElementType().WherePasses(filter); if (coll.Count() > 1) { categoryList.Add(c); } } } } return(categoryList.Distinct(new DistinctItemComparer()).ToList()); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication app = commandData.Application; m_doc = app.ActiveUIDocument.Document; // filter for family instance and (door or window): ElementClassFilter fFamInstClass = new ElementClassFilter( typeof( FamilyInstance ) ); ElementCategoryFilter fDoorCat = new ElementCategoryFilter( BuiltInCategory.OST_Doors ); ElementCategoryFilter fWindowCat = new ElementCategoryFilter( BuiltInCategory.OST_Windows ); LogicalOrFilter fCat = new LogicalOrFilter( fDoorCat, fWindowCat ); LogicalAndFilter f = new LogicalAndFilter( fCat, fFamInstClass ); FilteredElementCollector openings = new FilteredElementCollector( m_doc ); openings.WherePasses( f ); // map with key = host element id and // value = list of hosted element ids: Dictionary<ElementId, List<ElementId>> ids = GetElementIds( openings ); DumpHostedElements( ids ); m_doc = null; return Result.Succeeded; }
private ElementId FindTemplateByViewNameEnding(string viewNameEnding) { const int PARTITION_PARAMETER_ID = 2698521; ElementId partitionParamId = new ElementId(PARTITION_PARAMETER_ID); ElementParameterFilter viewNameFilter = new ElementParameterFilter( ParameterFilterRuleFactory .CreateEndsWithRule( new ElementId(BuiltInParameter.VIEW_NAME), viewNameEnding, false)); ElementParameterFilter partitionFilter = new ElementParameterFilter( ParameterFilterRuleFactory .CreateBeginsWithRule(partitionParamId, "#Стандарт", false)); LogicalAndFilter andFilter = new LogicalAndFilter(viewNameFilter, partitionFilter); return (new FilteredElementCollector(m_doc) .OfCategory(BuiltInCategory.OST_Schedules) .WherePasses(andFilter) .ToElementIds() .FirstOrDefault()); }
public static LogicalOrFilter FamInstOfDetailComp() { BuiltInCategory[] bics = { BuiltInCategory.OST_DetailComponents, }; IList <ElementFilter> a = new List <ElementFilter>(bics.Length); foreach (BuiltInCategory bic in bics) { a.Add(new ElementCategoryFilter(bic)); } LogicalOrFilter categoryFilter = new LogicalOrFilter(a); LogicalAndFilter familySymbolFilter = new LogicalAndFilter(categoryFilter, new ElementClassFilter(typeof(FamilyInstance))); IList <ElementFilter> b = new List <ElementFilter> { familySymbolFilter }; LogicalOrFilter classFilter = new LogicalOrFilter(b); return(classFilter); }
/// <summary> /// Get the selected element as the host object, also check if the selected element is expected host object /// </summary> /// <returns>true if get the selected element, otherwise false.</returns> private bool GetHostObject() { List <ElementId> selectedIds = new List <ElementId>(); foreach (Autodesk.Revit.DB.Element elem in m_commandData.Application.ActiveUIDocument.Selection.Elements) { selectedIds.Add(elem.Id); } if (selectedIds.Count != 1) { return(false); } // // Construct filters to find expected host object: // . Host should be Beam/Column structural type. // . and it's material type should be Concrete // . and it should be FamilyInstance // // Structural type filters firstly LogicalOrFilter stFilter = new LogicalOrFilter( new ElementStructuralTypeFilter(StructuralType.Beam), new ElementStructuralTypeFilter(StructuralType.Column)); // StructuralMaterialType should be Concrete LogicalAndFilter hostFilter = new LogicalAndFilter(stFilter, new StructuralMaterialTypeFilter(StructuralMaterialType.Concrete)); // // Expected host object FilteredElementCollector collector = new FilteredElementCollector(m_commandData.Application.ActiveUIDocument.Document, selectedIds); m_hostObject = collector .OfClass(typeof(FamilyInstance)) // FamilyInstance .WherePasses(hostFilter) // Filters .FirstElement() as FamilyInstance; return(null != m_hostObject); }
public static LogicalOrFilter FamSymbolsAndPipeTypes() { BuiltInCategory[] bics = new BuiltInCategory[] { BuiltInCategory.OST_PipeAccessory, BuiltInCategory.OST_PipeCurves, BuiltInCategory.OST_PipeFitting, }; IList <ElementFilter> a = new List <ElementFilter>(bics.Count()); foreach (BuiltInCategory bic in bics) { a.Add(new ElementCategoryFilter(bic)); } LogicalOrFilter categoryFilter = new LogicalOrFilter(a); LogicalAndFilter familySymbolFilter = new LogicalAndFilter(categoryFilter, new ElementClassFilter(typeof(FamilySymbol))); IList <ElementFilter> b = new List <ElementFilter>(); b.Add(new ElementClassFilter(typeof(PipeType))); b.Add(familySymbolFilter); LogicalOrFilter classFilter = new LogicalOrFilter(b); return(classFilter); }
public void ClearMarks() { Document doc = this.ActiveUIDocument.Document; FilteredElementCollector collector = new FilteredElementCollector(doc); ElementClassFilter f1 = new ElementClassFilter(typeof(FamilyInstance)); StructuralMaterialTypeFilter f2 = new StructuralMaterialTypeFilter(StructuralMaterialType.Concrete); ElementClassFilter f3 = new ElementClassFilter(typeof(Floor)); ElementClassFilter f4 = new ElementClassFilter(typeof(Wall)); LogicalAndFilter f5 = new LogicalAndFilter(f1, f2); LogicalOrFilter f6 = new LogicalOrFilter(f3, f4); LogicalOrFilter f7 = new LogicalOrFilter(f5, f6); ICollection <Element> collection = collector.WherePasses(f7).ToElements(); using (Transaction tx = new Transaction(doc, "CopyMarkToSN")) { tx.Start(); foreach (Element e in collection) { Parameter pSN = e.LookupParameter("編號"); if (null != pSN) { // Parameter pMark = e.LookupParameter("標註"); Parameter pMark = e.get_Parameter(BuiltInParameter.DOOR_NUMBER); pMark.Set(""); } } tx.Commit(); } }
/// <summary> /// Get Element from document using the Build In Category /// </summary> /// <param name="doc">Document</param> /// <param name="category">BuiltInCategory</param> /// <returns>Element</returns> public List <Element> GetFamilyElement(Document doc, BuiltInCategory category) { List <Element> List_Element = new List <Element>(); ElementClassFilter familyInstanceFilter = new ElementClassFilter(typeof(FamilyInstance)); // Category filter ElementCategoryFilter Categoryfilter = new ElementCategoryFilter(category); // Instance filter LogicalAndFilter InstancesFilter = new LogicalAndFilter(familyInstanceFilter, Categoryfilter); FilteredElementCollector collector = new FilteredElementCollector(doc); // Colletion Array of Elements ICollection <Element> Elements = collector.WherePasses(InstancesFilter).ToElements(); foreach (Element e in Elements) { if (null != Elements) { try { List_Element.Add(e); } catch (Exception ex) { string x = ex.Message; } } } return(List_Element); }
/// <summary> /// Read all Revit model phases. /// </summary> private void ReadPhases() { var collector = new FilteredElementCollector(a_doc); var filterCategory = new ElementCategoryFilter(BuiltInCategory.OST_Phases); var filterNotSymbol = new ElementClassFilter(typeof(FamilySymbol), true); var filter = new LogicalAndFilter(filterCategory, filterNotSymbol); var elements = collector.WherePasses(filter).ToElements(); foreach (var element in elements) { try { if (element is Phase) { bool export = false; if (element.Name.ToUpper().Contains("NEW")) { export = true; } this.a_revitPhases.Add(new RevitPhase(element.Name, export)); } } catch (Exception e) { ShowElementErrorMessage(element, e); } } }
/// <summary> /// Read all Revit model levels. /// </summary> private void ReadLevels() { var collector = new FilteredElementCollector(a_doc); var filterCategory = new ElementCategoryFilter(BuiltInCategory.OST_Levels); var filterNotSymbol = new ElementClassFilter(typeof(FamilySymbol), true); var filter = new LogicalAndFilter(filterCategory, filterNotSymbol); var elements = collector.WherePasses(filter).ToElements(); var unSortedLevels = new List <Tuple <double, string> >(); foreach (var element in elements) { try { if (element is Level) { var level = element as Level; var levelWork = new Tuple <double, string>(level.ProjectElevation, level.Name); unSortedLevels.Add(levelWork); } } catch (Exception e) { ShowElementErrorMessage(element, e); } } // Sort level data by elevation, bottom to top a_levelData = unSortedLevels.OrderBy(el => el.Item1).ToList(); a_unknownLevelElevation = a_levelData.Count > 0 ? a_levelData[0].Item1 - 100 : 0.0; }
public void MarkUntagedFrame() { UIDocument uidoc = ActiveUIDocument; Document doc = uidoc.Document; ElementClassFilter f1 = new ElementClassFilter(typeof(FamilyInstance)); StructuralMaterialTypeFilter f2 = new StructuralMaterialTypeFilter(StructuralMaterialType.Concrete); ElementClassFilter f3 = new ElementClassFilter(typeof(Floor)); ElementClassFilter f4 = new ElementClassFilter(typeof(Wall)); LogicalAndFilter f5 = new LogicalAndFilter(f1, f2); LogicalOrFilter f6 = new LogicalOrFilter(f3, f4); LogicalOrFilter memberFilter = new LogicalOrFilter(f5, f6); FilteredElementCollector collector = new FilteredElementCollector(doc); collector.WherePasses(memberFilter); List <Element> members = collector.ToList(); String Tag = null; foreach (Element e in members) { Tag = e.get_Parameter(BuiltInParameter.DOOR_NUMBER).AsString(); if (Tag == "" || Tag == null) { HiLighted(e.Id, uidoc, doc); } else { UnHiLighted(e.Id, uidoc, doc); } Tag = null; } }
public void MarkFrames() { UIDocument uidoc = ActiveUIDocument; Document doc = uidoc.Document; ElementClassFilter f1 = new ElementClassFilter(typeof(FamilyInstance)); StructuralMaterialTypeFilter f2 = new StructuralMaterialTypeFilter(StructuralMaterialType.Concrete); ElementClassFilter f3 = new ElementClassFilter(typeof(Floor)); ElementClassFilter f4 = new ElementClassFilter(typeof(Wall)); LogicalAndFilter f5 = new LogicalAndFilter(f1, f2); LogicalOrFilter f6 = new LogicalOrFilter(f3, f4); LogicalOrFilter memberFilter = new LogicalOrFilter(f5, f6); FilteredElementCollector collector = new FilteredElementCollector(doc); collector.WherePasses(memberFilter); List <Element> members = collector.ToList(); int SN = 1; using (Transaction tx = new Transaction(doc, "MarkFrames")){ tx.Start(); foreach (Element e in members) { e.get_Parameter(BuiltInParameter.DOOR_NUMBER).Set("C" + SN.ToString("00")); SN++; } tx.Commit(); } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { Document doc = commandData.Application.ActiveUIDocument.Document; FilteredElementCollector filteredElementCollecter = new FilteredElementCollector(doc); ElementCategoryFilter elementCategoryFilter = new ElementCategoryFilter(BuiltInCategory.OST_Doors); ElementClassFilter elementClassFilter = new ElementClassFilter(typeof(FamilyInstance)); LogicalAndFilter logicAndFilter = new LogicalAndFilter(elementCategoryFilter, elementClassFilter); filteredElementCollecter.WherePasses(logicAndFilter); IList <Element> elementS = filteredElementCollecter.ToElements(); if (elementS.Count == 0) { TaskDialog.Show("Revit", "抱歉,没有符合要求的图元"); } else { string info = "符合条件的图元如下"; foreach (Element elem in elementS) { info += "\n\t" + elem.Name; } File.WriteAllText(@"D:\doors.txt", info + @"\n共计" + elementS.Count + "扇门。"); TaskDialog.Show("Revit", "写入成功"); } } catch (Exception e) { TaskDialog.Show("Revit", e.Message); } return(Result.Succeeded); }
//filter method for structural elements public static LogicalOrFilter GetStructuralFilter() { //columns, beams and foundations are family instances and not types unlike walls, floor, //ceiling, point load, continuoue footing, area load or line load. //so a logical filter is created to filter out all required structural elements BuiltInCategory[] builtInCategories = new BuiltInCategory[] { BuiltInCategory.OST_StructuralFraming }; IList <ElementFilter> listOfElementFilter = new List <ElementFilter>(builtInCategories.Count()); foreach (BuiltInCategory builtInCategory in builtInCategories) { listOfElementFilter.Add(new ElementCategoryFilter(builtInCategory)); } LogicalOrFilter categoryFilter = new LogicalOrFilter(listOfElementFilter); LogicalAndFilter familyInstanceFilter = new LogicalAndFilter(categoryFilter, new ElementClassFilter(typeof(FamilyInstance))); IList <ElementFilter> typeFilter = new List <ElementFilter>(); typeFilter.Add(new ElementClassFilter(typeof(Floor))); typeFilter.Add(new ElementClassFilter(typeof(Ceiling))); typeFilter.Add(familyInstanceFilter); LogicalOrFilter classFilter = new LogicalOrFilter(typeFilter); return(classFilter); }
/// <summary> /// Read all BuiltInCategory.OST_StructuralColumns elements from a Revit model. /// </summary> private void ReadColumns() { var collector = new FilteredElementCollector(a_doc); var filterCategory = new ElementCategoryFilter(BuiltInCategory.OST_StructuralColumns); var filterNotSymbol = new ElementClassFilter(typeof(FamilySymbol), true); var filter = new LogicalAndFilter(filterCategory, filterNotSymbol); var elements = collector.WherePasses(filter).ToElements(); foreach (var element in elements) { try { if (element is FamilyInstance && CheckElementPhase(element)) { var revitElement = new RevitElement(); revitElement.Category = RevitCategory.Column; revitElement.Id = element.Id.ToString(); revitElement.Name = element.Name; var baseLevelParam = element.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_PARAM); Level baseLevel = baseLevelParam != null?a_doc.GetElement(baseLevelParam.AsElementId()) as Level : null; revitElement.AssociatedLevel = baseLevel != null ? baseLevel.Name : a_unknownLevelName; revitElement.AssociatedElevation = baseLevel != null ? baseLevel.ProjectElevation : a_unknownLevelElevation; revitElement.AssociatedLevel = GetMappedLevel(revitElement.AssociatedLevel); var elementVolume = element.GetParameters("Volume"); revitElement.Volume = elementVolume.Count() > 0 ? UnitUtils.ConvertFromInternalUnits(elementVolume[0].AsDouble(), DisplayUnitType.DUT_CUBIC_FEET) : 0.0; var framingStructuralMaterial = this.GetStructuralMaterialFromElement(element, a_doc); revitElement.MaterialName = framingStructuralMaterial != null ? framingStructuralMaterial.Name : ""; revitElement.Material = framingStructuralMaterial != null?GetMaterialType(framingStructuralMaterial) : MaterialType.Unknown; double density = framingStructuralMaterial != null?GetDensity(framingStructuralMaterial) : 0.0; revitElement.Density = density; // Split Column by Levels var colCurve = CreateColumnCurve(element as FamilyInstance); if (colCurve != null && a_levelData.Count > 0) { var basePt = colCurve.GetEndPoint(0); var topPt = colCurve.GetEndPoint(1); var trueBel = basePt.Z; var trueTel = topPt.Z; var colHeight = trueTel - trueBel; SplitByLevels(revitElement, trueBel, trueTel, colHeight); } else { a_revitElementData.Add(revitElement); } } } catch (Exception e) { ShowElementErrorMessage(element, e); } } }
private ICollection <Element> getElementOrType(Autodesk.Revit.DB.BuiltInCategory categoryId, bool bElement) { FilteredElementCollector collector = new FilteredElementCollector(doc); ElementCategoryFilter categoryFilter = new ElementCategoryFilter(categoryId); LogicalAndFilter categoryTypeFilter = new LogicalAndFilter(categoryFilter, new ElementIsElementTypeFilter(bElement)); return(collector.WherePasses(categoryTypeFilter).ToElements()); }
public static FilteredElementCollector GetElementsWithConnectors(Document doc) { // what categories of family instances // are we interested in? // From here: http://thebuildingcoder.typepad.com/blog/2010/06/retrieve-mep-elements-and-connectors.html BuiltInCategory[] bics = new BuiltInCategory[] { //BuiltInCategory.OST_CableTray, //BuiltInCategory.OST_CableTrayFitting, //BuiltInCategory.OST_Conduit, //BuiltInCategory.OST_ConduitFitting, //BuiltInCategory.OST_DuctCurves, //BuiltInCategory.OST_DuctFitting, //BuiltInCategory.OST_DuctTerminal, //BuiltInCategory.OST_ElectricalEquipment, //BuiltInCategory.OST_ElectricalFixtures, //BuiltInCategory.OST_LightingDevices, //BuiltInCategory.OST_LightingFixtures, //BuiltInCategory.OST_MechanicalEquipment, BuiltInCategory.OST_PipeAccessory, BuiltInCategory.OST_PipeCurves, BuiltInCategory.OST_PipeFitting, //BuiltInCategory.OST_PlumbingFixtures, //BuiltInCategory.OST_SpecialityEquipment, //BuiltInCategory.OST_Sprinklers, //BuiltInCategory.OST_Wire }; IList <ElementFilter> a = new List <ElementFilter>(bics.Count()); foreach (BuiltInCategory bic in bics) { a.Add(new ElementCategoryFilter(bic)); } LogicalOrFilter categoryFilter = new LogicalOrFilter(a); LogicalAndFilter familyInstanceFilter = new LogicalAndFilter(categoryFilter, new ElementClassFilter(typeof(FamilyInstance))); //IList<ElementFilter> b = new List<ElementFilter>(6); IList <ElementFilter> b = new List <ElementFilter>(); //b.Add(new ElementClassFilter(typeof(CableTray))); //b.Add(new ElementClassFilter(typeof(Conduit))); //b.Add(new ElementClassFilter(typeof(Duct))); b.Add(new ElementClassFilter(typeof(Pipe))); b.Add(familyInstanceFilter); LogicalOrFilter classFilter = new LogicalOrFilter(b); FilteredElementCollector collector = new FilteredElementCollector(doc); collector.WherePasses(classFilter); return(collector); }
/// <summary> /// Gets element filter for family instance. /// </summary> /// <param name="exporter">The ExporterIFC object.</param> /// <returns>The element filter.</returns> private static ElementFilter GetFamilyInstanceFilter(ExporterIFC exporter) { List<ElementFilter> filters = new List<ElementFilter>(); filters.Add(new ElementOwnerViewFilter(ElementId.InvalidElementId)); filters.Add(new ElementClassFilter(typeof(FamilyInstance))); LogicalAndFilter andFilter = new LogicalAndFilter(filters); return andFilter; }
/// <summary> /// Get all of the egresses /// </summary> /// <returns>All egresses' set</returns> private ICollection <Element> getAllEgresses() { FilteredElementCollector collector = new FilteredElementCollector(m_doc); ElementClassFilter filterFamilyInstance = new ElementClassFilter(typeof(FamilyInstance)); ElementCategoryFilter filterDoorCategory = new ElementCategoryFilter(BuiltInCategory.OST_Doors); LogicalAndFilter filterDoorInstance = new LogicalAndFilter(filterDoorCategory, filterFamilyInstance); return(collector.WherePasses(filterDoorInstance).ToElements()); }
protected override void CollectElements() { FilteredElementCollector collector = new FilteredElementCollector(m_doc); ElementCategoryFilter filterCategory = new ElementCategoryFilter(BuiltInCategory.OST_Roofs); ElementClassFilter filterNotSymbol = new ElementClassFilter(typeof(FamilySymbol), true); LogicalAndFilter filter = new LogicalAndFilter(filterCategory, filterNotSymbol); m_elementsToProcess = collector.WherePasses(filter).ToElements(); }
public override void GlobalExecute(Document doc) { var filter = new LogicalAndFilter(new ElementCategoryFilter(BuiltInCategory.OST_DuctAccessory), new ElementIsElementTypeFilter(true)); var elementids = new FilteredElementCollector(doc).WherePasses(filter).ToElementIds(); foreach (var id in elementids) { UpdateMark(id); } }
protected override void CollectElements() { // filter for non-symbols that match the desired category so that inplace elements will also be found FilteredElementCollector collector = new FilteredElementCollector(m_doc); ElementCategoryFilter filterCategory = new ElementCategoryFilter(BuiltInCategory.OST_Walls); ElementClassFilter filterNotSymbol = new ElementClassFilter(typeof(FamilySymbol), true); LogicalAndFilter filter = new LogicalAndFilter(filterCategory, filterNotSymbol); m_elementsToProcess = collector.WherePasses(filter).ToElements(); }
/// <summary> /// Finds all windows in the active document. /// </summary> /// <returns>An enumerable containing all windows.</returns> protected IEnumerable<FamilyInstance> CollectWindows() { // Windows are family instances whose category is correctly set. ElementClassFilter familyInstanceFilter = new ElementClassFilter(typeof(FamilyInstance)); ElementCategoryFilter windowCategoryFilter = new ElementCategoryFilter(BuiltInCategory.OST_Windows); LogicalAndFilter andFilter = new LogicalAndFilter(familyInstanceFilter, windowCategoryFilter); FilteredElementCollector collector = new FilteredElementCollector(Document); ICollection<Element> elementsToProcess = collector.WherePasses(andFilter).ToElements(); // Convert to IEnumerable of FamilyInstance using LINQ IEnumerable<FamilyInstance> windows = from window in elementsToProcess.Cast<FamilyInstance>() select window; return windows; }
/// <summary> /// Gets element filter for specific views. /// </summary> /// <param name="exporter">The ExporterIFC object.</param> /// <returns>The element filter.</returns> private static ElementFilter GetViewSpecificTypesFilter(ExporterIFC exporter) { ElementFilter ownerViewFilter = GetOwnerViewFilter(exporter); List<Type> viewSpecificTypes = new List<Type>(); viewSpecificTypes.Add(typeof(TextNote)); viewSpecificTypes.Add(typeof(FilledRegion)); ElementMulticlassFilter classFilter = new ElementMulticlassFilter(viewSpecificTypes); LogicalAndFilter viewSpecificTypesFilter = new LogicalAndFilter(ownerViewFilter, classFilter); return viewSpecificTypesFilter; }
/// <summary> /// Gets element filter for family instance. /// </summary> /// <param name="exporter">The ExporterIFC object.</param> /// <returns>The element filter.</returns> private static ElementFilter GetFamilyInstanceFilter(ExporterIFC exporter) { List<ElementFilter> filters = new List<ElementFilter>(); filters.Add(new ElementOwnerViewFilter(ElementId.InvalidElementId)); filters.Add(new ElementClassFilter(typeof(FamilyInstance))); LogicalAndFilter andFilter = new LogicalAndFilter(filters); return andFilter; }
/// <summary> /// initialize list of column, beam and brace's type; /// initialize list of level /// </summary> private void Initialize() { Application app = m_commandData.Application.Application; Document doc = m_commandData.Application.ActiveUIDocument.Document; FilteredElementCollector collector1 = new FilteredElementCollector(doc); IList<Autodesk.Revit.DB.Element> a1 = collector1.OfClass(typeof(Level)).ToElements(); foreach (Level lev in a1) { m_levels.Add(lev.Elevation, lev); } a1.Clear(); Categories categories = doc.Settings.Categories; BuiltInCategory bipColumn = BuiltInCategory.OST_StructuralColumns; BuiltInCategory bipFraming = BuiltInCategory.OST_StructuralFraming; Autodesk.Revit.DB.ElementId idColumn = categories.get_Item(bipColumn).Id; Autodesk.Revit.DB.ElementId idFraming = categories.get_Item(bipFraming).Id; ElementCategoryFilter filterColumn = new ElementCategoryFilter(bipColumn); ElementCategoryFilter filterFraming = new ElementCategoryFilter(bipFraming); LogicalOrFilter orFilter = new LogicalOrFilter(filterColumn, filterFraming); ElementClassFilter filterSymbol = new ElementClassFilter(typeof(FamilySymbol)); LogicalAndFilter andFilter = new LogicalAndFilter(orFilter, filterSymbol); // // without filtering for the structural categories, // our sample project was returning over 500 family symbols; // adding the category filters reduced this number to 40: // FilteredElementCollector collector2 = new FilteredElementCollector(doc); IList<Element> a2 = collector2.WherePasses(andFilter).ToElements(); foreach (FamilySymbol symbol in a2) { Autodesk.Revit.DB.ElementId categoryId = symbol.Category.Id; if (idFraming.Equals(categoryId)) { m_beambracesSymbolsMgr.AddSymbol(symbol); } else if (idColumn.Equals(categoryId)) { m_columnSymbolsMgr.AddSymbol(symbol); } } }
/// <summary> /// Set value(uuid) to Unique ID parameter /// </summary> public void SetValueToUniqueIDParameter() { ElementClassFilter beamClassFilter = new ElementClassFilter(typeof(FamilyInstance)); ElementClassFilter slabClassFilter = new ElementClassFilter(typeof(Floor)); ElementCategoryFilter beamTypeFilter = new ElementCategoryFilter(BuiltInCategory.OST_StructuralFraming); ElementCategoryFilter slabTypeFilter = new ElementCategoryFilter(BuiltInCategory.OST_Floors); LogicalAndFilter beamFilter = new LogicalAndFilter(beamClassFilter,beamTypeFilter); LogicalAndFilter slabFilter = new LogicalAndFilter(slabClassFilter,slabTypeFilter); LogicalOrFilter beamandslabFilter = new LogicalOrFilter(beamFilter, slabFilter); IEnumerable<Element> elems = from elem in new FilteredElementCollector(m_revit.ActiveUIDocument.Document).WherePasses(beamandslabFilter).ToElements() let category = elem.Category where category!=null && (category.Name =="Structural Framing" || category.Name == "Floors") select elem; foreach (Element elem in elems) { // Find the parameter which is named "Unique ID" // belongs to a specifically beam or slab ParameterSet attributes = elem.Parameters; IEnumerator iter = attributes.GetEnumerator(); iter.Reset(); while (iter.MoveNext()) { Parameter attribute = iter.Current as Autodesk.Revit.DB.Parameter; Definition information = attribute.Definition; if ((null != information)&&("Unique ID" == information.Name) && (null == attribute.AsString()) ) { // The shared parameter "Unique ID" then be set to a UUID Guid uuid = Guid.NewGuid(); attribute.Set(uuid.ToString()); } } } }
public static void FilterDoors(Document document) { // Create a Filter to get all the doors in the document ElementClassFilter familyInstanceFilter = new ElementClassFilter(typeof(FamilyInstance)); ElementCategoryFilter doorsCategoryfilter = new ElementCategoryFilter(BuiltInCategory.OST_Walls); LogicalAndFilter doorInstancesFilter = new LogicalAndFilter(familyInstanceFilter, doorsCategoryfilter); FilteredElementCollector collector = new FilteredElementCollector(document); ICollection<ElementId> doors = collector.WherePasses(doorInstancesFilter).ToElementIds(); String prompt = "The ids of the doors in the current document are: "; String temp = ""; Element element; foreach (ElementId id in doors) { // Get the category instance from the Category property temp = ""; element = document.GetElement(id); Category category = element.Category; BuiltInCategory enumCategory = (BuiltInCategory)category.Id.IntegerValue; //temp += Enum.GetName(typeof(BuiltInCategory), enumCategory); // Get the level object to which the element is assigned. if (element.LevelId.Equals(ElementId.InvalidElementId)) { TaskDialog.Show("Revit", "The element isn't based on a level."); } else { Level level = element.Document.GetElement(element.LevelId) as Level; // Format the prompt information(Name and elevation) temp = "The element is based on a level."; temp += "\nThe level name is: " + level.Name; temp += "\nThe level elevation is: " + level.Elevation; // Show the information to the user. //TaskDialog.Show("Revit", prompt); } prompt += "\n\t" + id.IntegerValue + "(" + temp + ")"; } // Give the user some information TaskDialog.Show("Revit", prompt); // Get settings of current document Settings documentSettings = document.Settings; // Get all categories of current document Categories groups = documentSettings.Categories; // Show the number of all the categories to the user prompt = "Number of all categories in current Revit document:" + groups.Size; // get Floor category according to OST_Floors and show its name Category floorCategory = groups.get_Item(BuiltInCategory.OST_Walls); prompt += floorCategory.Name; // Give the user some information TaskDialog.Show("Revit", prompt); // foreach (var item in uidoc.Selection.GetElementIds()) // { // if (Units.) //} //if (0 == selectedIds.Count) //{ // // If no elements selected. // TaskDialog.Show("Revit", "You haven't selected any elements."); //} //else //{ // String info = "Ids of selected elements in the document are: "; // foreach (ElementId id in selectedIds) // { // info += "\n\t" + id.IntegerValue; // } // TaskDialog.Show("Revit", info); //} }
/// <summary> /// Do some check for the selection elements, includes geometry check. /// If the data doesn't meet our need, Exception will be thrown. /// </summary> private void Assert() { // Reserve all element ids for following iteration List<ElementId> selectedIds = new List<ElementId>(); foreach (Autodesk.Revit.DB.Element elem in m_rvtUIDoc.Selection.Elements) { selectedIds.Add(elem.Id); } if (selectedIds.Count == 0) throw new Exception("Please select a concrete beam or column to create rebar."); // // Construct filter to find expected rebar host // Structural type filters firstly LogicalOrFilter stFilter = new LogicalOrFilter( new ElementStructuralTypeFilter(StructuralType.Beam), new ElementStructuralTypeFilter(StructuralType.Column)); // + StructuralMaterial LogicalAndFilter hostFilter = new LogicalAndFilter(stFilter, new StructuralMaterialTypeFilter(StructuralMaterialType.Concrete)); // Expected rebar host: it should be family instance FilteredElementCollector collector = new FilteredElementCollector(m_rvtUIDoc.Document, selectedIds); FamilyInstance rebarHost = collector.OfClass(typeof(FamilyInstance)).WherePasses(hostFilter).FirstElement() as FamilyInstance; // Make sure the selected beam or column is rectangular. try { m_geometryData = new GeometrySupport(rebarHost); } catch { throw new Exception("Please select a beam or column in rectangular shape."); } m_rebarHost = rebarHost; // Judge the rebar host is a valid host. RebarHostData rebarHostData = RebarHostData.GetRebarHostData(rebarHost); if (rebarHostData == null || !rebarHostData.IsValidHost()) { throw new Exception("The selected element is not a valid rebar host."); } // Make sure the selected beam or column doesn't contain any rebar. if (rebarHostData.GetRebarsInHost().Count > 0) { throw new Exception("Please select a beam or a column which doesn't contain any rebar."); } }
/// <summary> /// Gets element filter that match certain types. /// </summary> /// <param name="forSpatialElements">True if to get filter for spatial element, false for other elements.</param> /// <returns>The element filter.</returns> private static ElementFilter GetClassFilter(bool forSpatialElements) { if (forSpatialElements) { return new ElementClassFilter(typeof(SpatialElement)); } else { List<Type> excludedTypes = new List<Type>(); // FamilyInstances are handled in separate filter. excludedTypes.Add(typeof(FamilyInstance)); excludedTypes.Add(typeof(SpatialElement)); if (!ExporterCacheManager.ExportOptionsCache.ExportAnnotations) excludedTypes.Add(typeof(CurveElement)); excludedTypes.Add(typeof(ElementType)); excludedTypes.Add(typeof(Group)); excludedTypes.Add(typeof(BaseArray)); excludedTypes.Add(typeof(FillPatternElement)); excludedTypes.Add(typeof(LinePatternElement)); excludedTypes.Add(typeof(Material)); excludedTypes.Add(typeof(GraphicsStyle)); excludedTypes.Add(typeof(Family)); excludedTypes.Add(typeof(SketchPlane)); excludedTypes.Add(typeof(View)); excludedTypes.Add(typeof(Autodesk.Revit.DB.Structure.LoadBase)); excludedTypes.Add(typeof(BeamSystem)); // curtain wall sub-types we are ignoring. excludedTypes.Add(typeof(CurtainGridLine)); // excludedTypes.Add(typeof(Mullion)); // this will be gotten from the element(s) it cuts. excludedTypes.Add(typeof(Opening)); // 2D types we are ignoring excludedTypes.Add(typeof(SketchBase)); excludedTypes.Add(typeof(FaceSplitter)); // 2D types covered by the element owner view filter excludedTypes.Add(typeof(TextNote)); excludedTypes.Add(typeof(FilledRegion)); // exclude levels that are covered in BeginExport excludedTypes.Add(typeof(Level)); // exclude analytical models excludedTypes.Add(typeof(Autodesk.Revit.DB.Structure.AnalyticalModel)); ElementFilter excludedClassFilter = new ElementMulticlassFilter(excludedTypes, true); List<BuiltInCategory> excludedCategories = new List<BuiltInCategory>(); // Native Revit types without match in API excludedCategories.Add(BuiltInCategory.OST_Property); excludedCategories.Add(BuiltInCategory.OST_SiteProperty); excludedCategories.Add(BuiltInCategory.OST_SitePropertyLineSegment); excludedCategories.Add(BuiltInCategory.OST_Viewports); excludedCategories.Add(BuiltInCategory.OST_Views); excludedCategories.Add(BuiltInCategory.OST_IOS_GeoLocations); excludedCategories.Add(BuiltInCategory.OST_RvtLinks); excludedCategories.Add(BuiltInCategory.OST_DecalElement); //excludedCategories.Add(BuiltInCategory.OST_Parts); excludedCategories.Add(BuiltInCategory.OST_DuctCurvesCenterLine); excludedCategories.Add(BuiltInCategory.OST_DuctFittingCenterLine); excludedCategories.Add(BuiltInCategory.OST_PipeCurvesCenterLine); excludedCategories.Add(BuiltInCategory.OST_PipeFittingCenterLine); excludedCategories.Add(BuiltInCategory.OST_ConduitCenterLine); excludedCategories.Add(BuiltInCategory.OST_ConduitFittingCenterLine); excludedCategories.Add(BuiltInCategory.OST_FlexDuctCurvesCenterLine); excludedCategories.Add(BuiltInCategory.OST_FlexPipeCurvesCenterLine); ElementMulticategoryFilter excludedCategoryFilter = new ElementMulticategoryFilter(excludedCategories, true); LogicalAndFilter exclusionFilter = new LogicalAndFilter(excludedClassFilter, excludedCategoryFilter); ElementOwnerViewFilter ownerViewFilter = new ElementOwnerViewFilter(ElementId.InvalidElementId); LogicalAndFilter returnedFilter = new LogicalAndFilter(exclusionFilter, ownerViewFilter); return returnedFilter; } }
/// <summary> /// Get all of the egresses /// </summary> /// <returns>All egresses' set</returns> private ICollection<Element> getAllEgresses() { FilteredElementCollector collector = new FilteredElementCollector(m_doc); ElementClassFilter filterFamilyInstance = new ElementClassFilter(typeof(FamilyInstance)); ElementCategoryFilter filterDoorCategory = new ElementCategoryFilter(BuiltInCategory.OST_Doors); LogicalAndFilter filterDoorInstance = new LogicalAndFilter(filterDoorCategory, filterFamilyInstance); return collector.WherePasses(filterDoorInstance).ToElements(); }
public ICollection<Element> getElementsOfCategory(Document doc, BuiltInCategory cat, Type ty) { //Select all elements of type Wall. Ignore walltypes for now. ElementCategoryFilter Categoryfilter = new ElementCategoryFilter(cat); ElementClassFilter classFilter = new ElementClassFilter(ty); LogicalAndFilter InstancesFilter = new LogicalAndFilter(Categoryfilter, classFilter); FilteredElementCollector collector = new FilteredElementCollector(doc); return collector.WherePasses(InstancesFilter).ToElements(); }
public Autodesk.Revit.UI.Result Execute(ExternalCommandData revit, ref string message, ElementSet elements) { try { Document document = revit.Application.ActiveUIDocument.Document; // 创建一个类过滤器来过滤出所有的FamilyInstance类的元素。 ElementClassFilter familyInstanceFilter = new ElementClassFilter(typeof(FamilyInstance)); // 创建一个类别过滤器来过滤出所有的内建类型为OST_Doors的元素。 ElementCategoryFilter doorsCategoryfilter = new ElementCategoryFilter(BuiltInCategory.OST_Doors); // 创建一个逻辑过滤器来组合前面两个过滤器,实现过滤出所有Door元素。 LogicalAndFilter doorInstancesFilter = new LogicalAndFilter(familyInstanceFilter, doorsCategoryfilter); FilteredElementCollector collector = new FilteredElementCollector(document); 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); } catch (Exception e) { message = e.Message; return Autodesk.Revit.UI.Result.Failed; } return Autodesk.Revit.UI.Result.Succeeded; }
/// <summary> /// Get the selected element as the host object, also check if the selected element is expected host object /// </summary> /// <returns>true if get the selected element, otherwise false.</returns> private bool GetHostObject() { List<ElementId> selectedIds = new List<ElementId>(); foreach (Autodesk.Revit.DB.Element elem in m_commandData.Application.ActiveUIDocument.Selection.Elements) { selectedIds.Add(elem.Id); } if (selectedIds.Count != 1) return false; // // Construct filters to find expected host object: // . Host should be Beam/Column structural type. // . and it's material type should be Concrete // . and it should be FamilyInstance // // Structural type filters firstly LogicalOrFilter stFilter = new LogicalOrFilter( new ElementStructuralTypeFilter(StructuralType.Beam), new ElementStructuralTypeFilter(StructuralType.Column)); // StructuralMaterialType should be Concrete LogicalAndFilter hostFilter = new LogicalAndFilter(stFilter, new StructuralMaterialTypeFilter(StructuralMaterialType.Concrete)); // // Expected host object FilteredElementCollector collector = new FilteredElementCollector(m_commandData.Application.ActiveUIDocument.Document, selectedIds); m_hostObject = collector .OfClass(typeof(FamilyInstance)) // FamilyInstance .WherePasses(hostFilter) // Filters .FirstElement() as FamilyInstance; return (null != m_hostObject); }
/// <summary> /// Doors related rooms: update doors' geometry according to its To/From room information. /// </summary> /// <param name="creFilter">One element filter utility object.</param> /// <param name="doc">Revit project.</param> /// <param name="onlyUpdateSelect"> /// true means only update selected doors' information else false. /// </param> public static void UpdateDoorsGeometry(Document doc, bool onlyUpdateSelect) { IEnumerator iter; int doorCount = 0; if (onlyUpdateSelect) // update doors in select elements { UIDocument newUIdoc = new UIDocument(doc); iter = newUIdoc.Selection.Elements.GetEnumerator(); } else // update all doors in current Revit document { ElementClassFilter familyInstanceFilter = new ElementClassFilter(typeof(FamilyInstance)); ElementCategoryFilter doorsCategoryfilter = new ElementCategoryFilter(BuiltInCategory.OST_Doors); LogicalAndFilter doorInstancesFilter = new LogicalAndFilter(familyInstanceFilter, doorsCategoryfilter); iter = new FilteredElementCollector(doc).WherePasses(doorInstancesFilter).GetElementIterator(); } iter.Reset(); while (iter.MoveNext()) { // find door instance FamilyInstance door = iter.Current as FamilyInstance; if (onlyUpdateSelect) { if (null == door) { continue; } if (null == door.Category) { continue; } if (!door.Category.Name.Equals("Doors")) { continue; } } // find one door. doorCount++; // update one door. UpdateFromToRoomofOneDoor(door, true); doc.Regenerate(); } if (onlyUpdateSelect) { System.Windows.Forms.MessageBox.Show("Updated all selected doors (" + doorCount + " doors).\r\n (Selection may include miscellaneous elements.)", "Door Swing"); } else { System.Windows.Forms.MessageBox.Show("Updated all doors of this project (" + doorCount + " doors).", "Door Swing"); } }
/// <summary> /// update door instances information: Left/Right information, related rooms information. /// </summary> /// <param name="creFilter">One element filter utility object.</param> /// <param name="doc">Revit project.</param> /// <param name="onlyUpdateSelect"> /// true means only update selected doors' information otherwise false. /// </param> /// <param name="showUpdateResultMessage"> /// this parameter is used for invoking this method in Application's events (document save and document saveAs). /// update door infos in Application level events should not show unnecessary messageBox. /// </param> public static Autodesk.Revit.UI.Result UpdateDoorsInfo(Document doc, bool onlyUpdateSelect, bool showUpdateResultMessage, ref string message) { if ((!AssignedAllRooms(doc)) && showUpdateResultMessage) { DialogResult dialogResult = MessageBox.Show("One or more eligible areas of this level " + "have no assigned room(s). Doors bounding these areas " + "will be designated as external doors. Proceed anyway?", "Door Swing", MessageBoxButtons.YesNo); if (DialogResult.No == dialogResult) { message = "Update cancelled. Please assign rooms for all eligible areas first."; return Autodesk.Revit.UI.Result.Cancelled; } } // begin update door parameters. IEnumerator iter; int doorCount = 0; bool checkSharedParameters = false; if (onlyUpdateSelect) // update doors in select elements { UIDocument newUIdoc = new UIDocument(doc); iter = newUIdoc.Selection.Elements.GetEnumerator(); } else // update all doors in current Revit project. { ElementClassFilter familyInstanceFilter = new ElementClassFilter(typeof(FamilyInstance)); ElementCategoryFilter doorsCategoryfilter = new ElementCategoryFilter(BuiltInCategory.OST_Doors); LogicalAndFilter doorInstancesFilter = new LogicalAndFilter(familyInstanceFilter, doorsCategoryfilter); iter = new FilteredElementCollector(doc).WherePasses(doorInstancesFilter).GetElementIterator(); } iter.Reset(); while (iter.MoveNext()) { // find door instance FamilyInstance door = iter.Current as FamilyInstance; if (onlyUpdateSelect) { if (null == door) { continue; } if (null == door.Category) { continue; } if (!door.Category.Name.Equals("Doors")) { continue; } } // check if has needed parameters. if (!checkSharedParameters) { checkSharedParameters = true; if (!(door.Symbol.ParametersMap.Contains("BasalOpening") && door.ParametersMap.Contains("InstanceOpening") && door.ParametersMap.Contains("Internal Door"))) { message = "Cannot update door parameters. Please customize door opening expression first."; return Autodesk.Revit.UI.Result.Failed; } } // get one door. doorCount++; // update one door's Opening parameter value. if (UpdateOpeningFeatureOfOneDoor(door) == Autodesk.Revit.UI.Result.Failed) { message = "Cannot update door parameters. Please customize door opening expression first."; return Autodesk.Revit.UI.Result.Failed; } // update one door's from/to room. UpdateFromToRoomofOneDoor(door, false); // update one door's internalDoor flag UpdateInternalDoorFlagFeatureofOneDoor(door); } if (showUpdateResultMessage) { if (onlyUpdateSelect) { System.Windows.Forms.MessageBox.Show("Updated all selected doors of " + doc.Title + " (" + doorCount + " doors).\r\n (Selection may " + "include miscellaneous elements.)","Door Swing"); } else { System.Windows.Forms.MessageBox.Show("Updated all doors of " + doc.Title + " (" + doorCount + " doors).", "Door Swing"); } } return Autodesk.Revit.UI.Result.Succeeded; }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { try { UIApplication uiApp = commandData.Application; UIDocument uidoc = uiApp.ActiveUIDocument; Application app = uiApp.Application; Document doc = uidoc.Document; Stopwatch sw = Stopwatch.StartNew(); // f5 = f1 && f4 // = f1 && (f2 || f3) // = family instance and (door or window) #region Filters and collector definitions ElementClassFilter f1 = new ElementClassFilter( typeof( FamilyInstance ) ); ElementCategoryFilter f2 = new ElementCategoryFilter( BuiltInCategory.OST_Doors ); ElementCategoryFilter f3 = new ElementCategoryFilter( BuiltInCategory.OST_Windows ); LogicalOrFilter f4 = new LogicalOrFilter( f2, f3 ); LogicalAndFilter f5 = new LogicalAndFilter( f1, f4 ); FilteredElementCollector collector = new FilteredElementCollector( doc ); #endregion //#region Filtering with a class filter //List<Element> openingInstances = // collector.WherePasses(f5).ToElements() // as List<Element>; //#endregion //#region Filtering with an anonymous method //List<Element> openings = collector // .WherePasses(f4) // .ToElements() as List<Element>; //List<Element> openingInstances // = openings.FindAll( // e => e is FamilyInstance ); //#endregion #region Filtering with LINQ List<Element> openings = collector .WherePasses( f4 ) .ToElements() as List<Element>; List<Element> openingInstances = ( from instances in openings where instances is FamilyInstance select instances ).ToList<Element>(); #endregion int n = openingInstances.Count; sw.Stop(); Debug.WriteLine( string.Format( "Time to get {0} elements: {1}ms", n, sw.ElapsedMilliseconds ) ); return Result.Succeeded; } catch( Exception ex ) { message = ex.Message + ex.StackTrace; return Result.Failed; } }
/** public void GetMaterial(Document document, FamilyInstance window) { Materials materials = document.Settings.Materials; FamilySymbol windowSymbol = window.Symbol; Category category = windowSymbol.Category; Autodesk.Revit.DB.Material frameExteriorMaterial = null; Autodesk.Revit.DB.Material frameInteriorMaterial = null; Autodesk.Revit.DB.Material sashMaterial = null; // Check the paramters first foreach (Parameter parameter in windowSymbol.Parameters) { switch (parameter.Definition.Name) { case "Frame Exterior Material": frameExteriorMaterial = materials.get_Item(parameter.AsElementId()); break; case "Frame Interior Material": frameInteriorMaterial = materials.get_Item(parameter.AsElementId()); break; case "Sash": sashMaterial = materials.get_Item(parameter.AsElementId()); break; default: break; } } // Try category if the material is set by category if (null == frameExteriorMaterial) frameExteriorMaterial = category.Material; if (null == frameInteriorMaterial) frameInteriorMaterial = category.Material; if (null == sashMaterial) sashMaterial = category.Material; // Show the result because the category may have a null Material, // the Material objects need to be checked. string materialsInfo = "Frame Exterior Material: " + (null != frameExteriorMaterial ? frameExteriorMaterial.Name : "null") + "\n"; materialsInfo += "Frame Interior Material: " + (null != frameInteriorMaterial ? frameInteriorMaterial.Name : "null") + "\n"; materialsInfo += "Sash: " + (null != sashMaterial ? sashMaterial.Name : "null") + "\n"; TaskDialog.Show("Revit", materialsInfo); }*/ public void ReadWallMaterials(Document doc) { ElementCategoryFilter wallsCategoryfilter = new ElementCategoryFilter(BuiltInCategory.OST_Walls); ElementClassFilter classFilter = new ElementClassFilter(typeof(Wall)); LogicalAndFilter wallInstancesFilter = new LogicalAndFilter(wallsCategoryfilter, classFilter); FilteredElementCollector collector = new FilteredElementCollector(doc); ICollection<Element> walls = collector.WherePasses(wallInstancesFilter).ToElements(); TextWriter writer = new StreamWriter("C:\\Documents and Settings\\fdot\\Desktop\\materials.txt"); foreach (Element e in walls) { Wall w = null; WallType wType = null; w = (Wall)e; writer.WriteLine("Wall - " + w.Name); wType = w.WallType; if (wType.Kind == WallKind.Basic) { //Write Assembly Name writer.Write("Assembly Description: "); Parameter assemName = wType.get_Parameter("Assembly Description"); writeValueByStorageType(assemName, writer, doc); writer.WriteLine(); //Write Assembly Code writer.Write("Assembly Code: "); Parameter assemCode = wType.get_Parameter("Assembly Code"); writeValueByStorageType(assemCode, writer, doc); writer.WriteLine(); foreach (Material m in w.Materials) { writer.WriteLine("Material: " + m.Name + " - Area:" + w.GetMaterialArea(m)); } //foreach (Parameter p in w.Parameters) //{ // if (p.Definition.Name.Equals("Area") || p.Definition.Name.Equals("Volume")) // { // writer.Write("\t" + p.Definition.Name + ": "); // if (p.HasValue) // { // writeValueByStorageType(p, writer, doc); // } // else // writer.Write("N/A"); // writer.WriteLine(); // } //} } //} writer.WriteLine(); } writer.Dispose(); }