标签:cto manual int clu tca 获取元素 show 二次 count
图中计算过滤出所有型号为1200*1500mm,且标记为小于5的窗数量。识别并计算门窗总和。
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Autodesk.Revit.UI; using Autodesk.Revit.DB; using Autodesk.Revit.ApplicationServices; using Autodesk.Revit.Attributes; using System.Windows.Forms; namespace RevitDevTV { /// <summary> /// 获取元素属性 /// </summary> [TransactionAttribute(TransactionMode.Manual)] [RegenerationAttribute(RegenerationOption.Manual)] public class FiltersPractise : IExternalCommand { public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { //FilteredElementCollector的使用 UIDocument uiDoc = commandData.Application.ActiveUIDocument; //将UIDocument变为Document Document doc = uiDoc.Document; //收集document FilteredElementCollector collector = new FilteredElementCollector(doc); //QuickFilter过滤所有出窗 collector=collector.OfCategory(BuiltInCategory.OST_Windows).OfClass(typeof(FamilySymbol)); //FamilyInstanceFilter找1200*1500mm的窗 var query = from element in collector where element.Name == "1200 * 1500 mm" select element; List<Autodesk.Revit.DB.Element> famSyms = query.ToList<Autodesk.Revit.DB.Element>(); ElementId symbolId = famSyms[0].Id; FamilyInstanceFilter fiFilter = new FamilyInstanceFilter(doc,symbolId); FilteredElementCollector cl = new FilteredElementCollector(doc); ICollection<Element> found = cl.WherePasses(fiFilter).ToElements(); // ElementParameterFilter找到标记小于5的窗 ElementId ruleValId = new ElementId(-1001203); FilterRule fr = ParameterFilterRuleFactory.CreateLessRule(ruleValId,"5",true); ElementParameterFilter pFilter = new ElementParameterFilter(fr); FilteredElementCollector c2 = new FilteredElementCollector(doc); c2 = c2.OfCategory(BuiltInCategory.OST_Windows).WherePasses(fiFilter).WherePasses(pFilter); //LogicalOrFilter计算门窗总和 ElementCategoryFilter doorFilter = new ElementCategoryFilter(BuiltInCategory.OST_Doors); ElementCategoryFilter windowFilter = new ElementCategoryFilter(BuiltInCategory.OST_Windows); LogicalOrFilter lFilter = new LogicalOrFilter(doorFilter, windowFilter); FilteredElementCollector c3 = new FilteredElementCollector(doc); ICollection<Element> fds = c3.OfClass(typeof(FamilyInstance)).WherePasses(lFilter).ToElements(); // taskdialog输出结果 TaskDialog.Show("查找","已找到型号为 1200*1500mm的推拉窗"+found.Count.ToString()+"个,"+"\n"+"其中标记小于5的有"+c2.ToList().Count.ToString()+"个"+"\n"+"门窗总和为:"+fds.Count.ToString()); return Result.Succeeded; } } }
使用ElementIntersectFilter进行冲突检查
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Autodesk.Revit.UI; using Autodesk.Revit.DB; using Autodesk.Revit.ApplicationServices; using Autodesk.Revit.Attributes; using System.Windows.Forms; using Autodesk.Revit.UI.Selection; namespace RevitDevTV { /// <summary> /// 冲突检查 /// </summary> [TransactionAttribute(TransactionMode.Manual)] [RegenerationAttribute(RegenerationOption.Manual)] public class Collision : IExternalCommand { public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uiDoc = commandData.Application.ActiveUIDocument; Document doc = uiDoc.Document; Transaction trans = new Transaction(doc,"ExtComm"); trans.Start(); Selection select = uiDoc.Selection; Reference r = select.PickObject(ObjectType.Element,"选择需要检查的墙"); Element column = doc.GetElement(r); FilteredElementCollector collector = new FilteredElementCollector(doc); //ElementIntersectFilter冲突检查 ElementIntersectsElementFilter iFilter = new ElementIntersectsElementFilter(column,false); collector.WherePasses(iFilter); List<ElementId> excludes = new List<ElementId>(); excludes.Add(column.Id); collector.Excluding(excludes); List<ElementId> ids = new List<ElementId>(); select.SetElementIds(ids); foreach (Element elem in collector) { ids.Add(elem.Id); } select.SetElementIds(ids); trans.Commit(); return Result.Succeeded; } } }
标签:cto manual int clu tca 获取元素 show 二次 count
原文地址:https://www.cnblogs.com/chenyanbin/p/13281867.html