/// <summary> /// Count the element in each file /// </summary> /// <param name="revitDoc"></param> /// <param name="countItParams"></param> /// <param name="results"></param> internal static void CountElements(Document revitDoc, CountItParams countItParams, ref CountItResults results) { if (countItParams.walls) { FilteredElementCollector elemCollector = new FilteredElementCollector(revitDoc); elemCollector.OfClass(typeof(Wall)); int count = elemCollector.ToElementIds().Count; results.walls += count; results.total += count; } if (countItParams.floors) { FilteredElementCollector elemCollector = new FilteredElementCollector(revitDoc); elemCollector.OfClass(typeof(Floor)); int count = elemCollector.ToElementIds().Count; results.floors += count; results.total += count; } if (countItParams.doors) { FilteredElementCollector collector = new FilteredElementCollector(revitDoc); ICollection <Element> collection = collector.OfClass(typeof(FamilyInstance)) .OfCategory(BuiltInCategory.OST_Doors) .ToElements(); int count = collection.Count; results.doors += count; results.total += count; } if (countItParams.windows) { FilteredElementCollector collector = new FilteredElementCollector(revitDoc); ICollection <Element> collection = collector.OfClass(typeof(FamilyInstance)) .OfCategory(BuiltInCategory.OST_Windows) .ToElements(); int count = collection.Count; results.windows += count; results.total += count; } }
/// <summary> /// count the elements depends on the input parameter in params.json /// </summary> /// <param name="rvtApp"></param> /// <param name="inputModelPath"></param> /// <param name="doc"></param> /// <returns></returns> public static bool CountElementsInModel(Application rvtApp, string inputModelPath, Document doc) { if (rvtApp == null) { return(false); } if (!File.Exists(inputModelPath)) { return(false); } if (doc == null) { return(false); } // For CountIt workItem: If RvtParameters is null, count all types CountItParams countItParams = CountItParams.Parse("params.json"); //CountItResults results = new CountItResults(); List <Document> allDocs = GetHostAndLinkDocuments(doc); foreach (Document curDoc in allDocs) { CountElements(curDoc, countItParams); } //using (StreamWriter sw = File.CreateText("result.txt")) //{ // sw.WriteLine(JsonConvert.SerializeObject(results)); // sw.Close(); //} return(true); }
/// <summary> /// Count the element in each file /// </summary> /// <param name="revitDoc"></param> /// <param name="countItParams"></param> /// <param name="results"></param> internal static void CountElements(Document revitDoc, CountItParams countItParams) { //logic goes in here! FilteredElementCollector elemCollector = new FilteredElementCollector(revitDoc); elemCollector.OfClass(typeof(Wall)); List <Wall> wallElements = new List <Wall>(); List <RoofBase> roofElements = new List <RoofBase>(); ICollection <ElementId> userSelection = elemCollector.ToElementIds(); Element elmnt; foreach (var i in userSelection) { elmnt = revitDoc.GetElement(i); if (elmnt.Category.Name == "Walls") { wallElements.Add(elmnt as Wall); } else if (elmnt.Category.Name == "Roofs") { roofElements.Add(elmnt as RoofBase); } } //Collecting all types to be used in model string wcName; FilteredElementCollector wallTypeColl = new FilteredElementCollector(revitDoc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsElementType(); List <string> wallTypeNames = new List <string>(); foreach (var wc in wallTypeColl) { wcName = wc.LookupParameter("Type Name").AsString(); //TaskDialog.Show("WCNAME WALLTYPE", wcName); wallTypeNames.Add(wcName); } string wtName; FilteredElementCollector windowTypeColl = new FilteredElementCollector(revitDoc).OfCategory(BuiltInCategory.OST_Windows).WhereElementIsElementType(); List <string> windowTypeNames = new List <string>(); foreach (var wt in windowTypeColl) { wtName = wt.LookupParameter("Type Name").AsString(); //TaskDialog.Show("WTNAME WALLTYPE", wtName); windowTypeNames.Add(wtName); } string rcName; FilteredElementCollector roofTypeColl = new FilteredElementCollector(revitDoc).OfCategory(BuiltInCategory.OST_Roofs).WhereElementIsElementType(); List <string> roofTypeName = new List <string>(); foreach (var rc in roofTypeColl) { rcName = rc.LookupParameter("Type Name").AsString(); //TaskDialog.Show("RTYPE ROOF TYPE", rcName); roofTypeName.Add(rcName); } //Form1 new_form = new Form1(); //new_form.ShowDialog(); string extMaterials = countItParams.extMaterials; string materialColor = countItParams.materialColor; string roofMaterial = countItParams.roofMaterial; string fenestrationTrim = countItParams.fenestrationTrim; string columnStyle = countItParams.columnStyle; //TaskDialog.Show("ext material", extMaterials); //List<string> wallTypeColl_list = wallTypeColl.ToList(); var wtlist = wallTypeColl.ToList(); //TaskDialog.Show("walltypenamecount", wallTypeNames.Count.ToString()); Element insertElement; List <Element> ws = new List <Element>(); List <Element> ds = new List <Element>(); Transaction t = new Transaction(revitDoc, "Edit walls"); t.Start(); foreach (var wall in wallElements) { ws.Clear(); ds.Clear(); for (int i = 0; i < wallTypeNames.Count; i++) { if (wallTypeNames[i].Contains(extMaterials) & wallTypeNames[i].Contains(materialColor)) { wall.WallType = wallTypeColl.First <Element>(x => x.Name.Equals(wallTypeNames[i].ToString())) as WallType; } } IList <ElementId> allInserts = wall.FindInserts(true, false, false, false); foreach (var ai in allInserts) { insertElement = revitDoc.GetElement(ai); if (insertElement.Category != null) { if (insertElement.Category.Name == "Windows") { ws.Add(insertElement); } if (insertElement.Category.Name == "Doors") { ds.Add(insertElement); } } } foreach (Element window in ws) { for (int i = 0; i < windowTypeNames.Count; i++) { if (windowTypeNames[i].Contains(fenestrationTrim)) { // window. = windowTypeColl.First<Element>(x => x.Name.Equals(windowTypeNames[i].ToString())) as FamilySymbol; } } } } t.Commit(); t.Start(); foreach (var roof in roofElements) { for (int i = 0; i < roofTypeName.Count; i++) { if (roofTypeName[i].Contains(roofMaterial)) { roof.RoofType = roofTypeColl.First <Element>(x => x.Name.Equals(roofTypeName[i].ToString())) as RoofType; } } } t.Commit(); ModelPath path = ModelPathUtils.ConvertUserVisiblePathToModelPath("result.rvt"); revitDoc.SaveAs(path, new SaveAsOptions()); //TaskDialog.Show("End", "job done"); //return Result.Succeeded; }