public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { // get UIdocument UIDocument uidoc = commandData.Application.ActiveUIDocument; //get document Document doc = uidoc.Document; //create filter List <ElementId> cats = new List <ElementId>(); cats.Add(new ElementId(BuiltInCategory.OST_Sections)); ElementParameterFilter filter = new ElementParameterFilter(ParameterFilterRuleFactory.CreateContainsRule(new ElementId(BuiltInParameter.VIEW_NAME), "wip", false)); try { using (Transaction trans = new Transaction(doc, "create plan view")) { trans.Start(); //apply filter ParameterFilterElement filterElement = ParameterFilterElement.Create(doc, "My First Filter", cats, filter); doc.ActiveView.AddFilter(filterElement.Id); doc.ActiveView.SetFilterVisibility(filterElement.Id, false); trans.Commit(); } return(Result.Succeeded); } catch (Exception e) { message = e.Message; return(Result.Failed); } }
public static Element FindPanelSchedule(Document doc, string fieldName, string value) { var rule = ParameterFilterRuleFactory.CreateContainsRule(new ElementId(BuiltInParameter.PANEL_SCHEDULE_NAME), value, false); var filter = new ElementParameterFilter(rule); var items = new FilteredElementCollector(doc) .OfCategory(BuiltInCategory.OST_ElectricalEquipment) .ToElements() .Where(e => e.Name.ToLower().Equals(value.ToLower())) .ToArray(); //foreach (var e in items) //{ // var name = e.LookupParameter("Panel Schedule Name"); // var panelNameParameter = e.GetOrderedParameters().FirstOrDefault(p => p.Definition.Name.Equals("Panel Schedule Name")); //} //var items = new FilteredElementCollector(doc) // .OfCategory(BuiltInCategory.OST_ElectricalEquipment) // .WherePasses(filter) // .ToElements(); return(FilterElements(items, value, fieldName)); }
private static void SetReadonlyCosts(Document doc, Func <Element, int, double> valueGetter) { FilteredElementCollector collector = new FilteredElementCollector(doc); collector.WhereElementIsElementType(); FilterRule rule = ParameterFilterRuleFactory.CreateSharedParameterApplicableRule("ReadonlyCost"); ElementParameterFilter filter = new ElementParameterFilter(rule); collector.WherePasses(filter); int increment = 1; using (Transaction t = new Transaction(doc, "Apply ReadonlyCost")) { t.Start(); foreach (Element elem in collector) { Parameter p = elem.LookupParameter("ReadonlyCost"); if (p != null) { p.Set(valueGetter(elem, increment)); } increment++; } t.Commit(); } }
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()); }
internal static IList <FamilyInstance> GetAllRebarsInDoc(Document doc) { System.Func <Document, IList <FamilyInstance> > GetAllRebars = d => { ElementParameterFilter shpFamNameFilter = new ElementParameterFilter(ParameterFilterRuleFactory.CreateBeginsWithRule( new ElementId(BuiltInParameter.ELEM_FAMILY_PARAM), "R-SHP", false)); ElementParameterFilter empFamNameFilter = new ElementParameterFilter( ParameterFilterRuleFactory.CreateBeginsWithRule( new ElementId(BuiltInParameter.ELEM_FAMILY_PARAM), "R-EMP", false)); List <ElementFilter> filters = new List <ElementFilter>() { shpFamNameFilter, empFamNameFilter }; LogicalOrFilter shpEmpFilter = new LogicalOrFilter(filters); return(new FilteredElementCollector(d) .OfCategory(BuiltInCategory.OST_DetailComponents) .WhereElementIsNotElementType() .WherePasses(shpEmpFilter) .Cast <FamilyInstance>() .Where(fi => fi.LookupParameter(IS_SPECIFIABLE).AsInteger() == 1) .ToList()); }; return(GetAllRebars(doc)); }
public void CreateFilterRule3dGrid(Document doc, out ParameterFilterElement parameterFilterElement) { if (CheckFilter(doc, out parameterFilterElement)) { } else { List <ElementId> categories = new List <ElementId>(); categories.Add(new ElementId(BuiltInCategory.OST_GenericModel)); List <FilterRule> filterRules = new List <FilterRule>(); // Create filter element assocated to the input categories parameterFilterElement = ParameterFilterElement.Create(doc, "Grid 3D", categories); var collector = (from x in new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_GenericModel).OfClass(typeof(FamilyInstance)).Cast <FamilyInstance>() where x.Name.Contains("650mm Bubble - Single") select x).ToList(); FamilyInstance familyInstance = collector.First(); if (familyInstance != null) { ElementId sharedParamId = familyInstance.get_Parameter(BuiltInParameter.ALL_MODEL_FAMILY_NAME).Id; filterRules.Add(ParameterFilterRuleFactory.CreateContainsRule(sharedParamId, "3D Grid", true)); } parameterFilterElement.SetRules(filterRules); // Apply filter to view //doc.ActiveView.AddFilter(parameterFilterElement.Id); //doc.ActiveView.SetFilterVisibility(parameterFilterElement.Id, false); } }
private static FilterRule CreateRule(ElementId ParameterId, string Function, ElementId ValueId) { switch (Function) { case "Равно": return(ParameterFilterRuleFactory.CreateEqualsRule(ParameterId, ValueId)); case "Не равно": return(ParameterFilterRuleFactory.CreateNotEqualsRule(ParameterId, ValueId)); case "Больше": return(ParameterFilterRuleFactory.CreateGreaterRule(ParameterId, ValueId)); case "Больше или равно": return(ParameterFilterRuleFactory.CreateLessOrEqualRule(ParameterId, ValueId)); case "Меньше": return(ParameterFilterRuleFactory.CreateLessRule(ParameterId, ValueId)); case "Меньше или равно": return(ParameterFilterRuleFactory.CreateLessOrEqualRule(ParameterId, ValueId)); default: return(null); } }
public static IList <Element> GetWallsIntersectBoundingBox(Document doc, Element elem) { ExclusionFilter exclusionFilter = new ExclusionFilter(new List <ElementId> { elem.Id }); ElementParameterFilter elementParameterFilter = new ElementParameterFilter(ParameterFilterRuleFactory .CreateEqualsRule(new ElementId(BuiltInParameter.WALL_BASE_CONSTRAINT), elem.LevelId), true); BoundingBoxXYZ bndBx = elem.get_Geometry (new Options { IncludeNonVisibleObjects = true }).GetBoundingBox(); BoundingBoxIntersectsFilter bndBxFlt = new BoundingBoxIntersectsFilter(new Outline(bndBx.Min, bndBx.Max), 0.1); IList <Element> elements = new FilteredElementCollector(doc) .WherePasses(exclusionFilter) .OfClass(typeof(Wall)) .WherePasses(bndBxFlt) .WherePasses(elementParameterFilter) .ToElements() .ToList(); return(elements); }
private void CreateFilterForPipeSystem(Document doc, Element sysNameParam, string systemName) { using var tr = new Transaction(doc, "Создание фильтра для: " + systemName); tr.Start(); var view = _uiDoc.ActiveView; var categories = new List <ElementId> { new ElementId(BuiltInCategory.OST_PipeAccessory), new ElementId(BuiltInCategory.OST_PipeCurves), new ElementId(BuiltInCategory.OST_PipeFitting), new ElementId(BuiltInCategory.OST_PipeInsulations), new ElementId(BuiltInCategory.OST_PlumbingFixtures), new ElementId(BuiltInCategory.OST_FlexPipeCurves), new ElementId(BuiltInCategory.OST_PlaceHolderPipes), new ElementId(BuiltInCategory.OST_GenericModel), new ElementId(BuiltInCategory.OST_MechanicalEquipment), new ElementId(BuiltInCategory.OST_Sprinklers) }; var rule = ParameterFilterRuleFactory.CreateNotContainsRule(sysNameParam.Id, systemName, true); var epf = new ElementParameterFilter(rule); var ef = (ElementFilter)epf; ParameterFilterElement filter; try { filter = ParameterFilterElement.Create(doc, "ADSK_Трубопровод_" + systemName, categories, ef); } catch (ArgumentException) { var filter1 = new FilteredElementCollector(doc) .OfClass(typeof(ParameterFilterElement)) .FirstOrDefault(f => f.Name == "ADSK_Трубопровод_" + systemName); filter = filter1 as ParameterFilterElement; filter?.SetElementFilter(ef); } var eView = new FilteredElementCollector(doc) .OfClass(typeof(View)) .WhereElementIsNotElementType() .FirstOrDefault(v => v.Name == $"{view.Name}_{systemName}"); if (null == eView) { var copyViewId = view.Duplicate(ViewDuplicateOption.Duplicate); if (doc.GetElement(copyViewId) is View copiedView) { copiedView.Name = $"{view.Name}_{systemName}"; if (filter != null) { copiedView.AddFilter(filter.Id); copiedView.SetFilterVisibility(filter.Id, false); } } } tr.Commit(); }
private void BtnChange_Click(object sender, RoutedEventArgs e) { //Use a try so an exception doesn't crash revit try { //Case the Old and New views from the Combobox Selected Values View OldView = (View)ComboBoxOldReference.SelectedValue; View NewView = (View)ComboBoxNewReference.SelectedValue; //Use a Filter Rule to Collect ONLY views that have the View Name of the OldView FilterRule rule = ParameterFilterRuleFactory.CreateEqualsRule(new ElementId(BuiltInParameter.VIEW_NAME), OldView.Name, true); //Create a Filter from the Filter Rule ElementParameterFilter filter = new ElementParameterFilter(rule); //Use a Collecter with the Filter to get Viewers that are not ElementTypes if (OldView.ViewType == NewView.ViewType) { using (FilteredElementCollector fec = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Viewers).WherePasses(filter).WhereElementIsNotElementType()) { //Create a new Transaction to make make changes to the Document using (Transaction Trans = new Transaction(doc)) { //Start the Transaction and Name it for the Undo/rdo Menu Trans.Start("Change View Reference"); //Iterate each Viewer returned by the Collector foreach (Element viewer in fec.ToElements()) { //The Viewers do not contain the same parameters as the actual views, so we check for one of them if (viewer.GetParameters("Discipline").Count == 0) { ReferenceableViewUtils.ChangeReferencedView(doc, viewer.Id, NewView.Id); } } //Commit the Transaction to save the changes Trans.Commit(); } } //Set the Dialog result to true so the Command will keep the changes DialogResult = true; //Close the Form Close(); } else { TaskDialog.Show("View Type Mismatch", "Current View and New View are not of the Same View Type\n\nCurrent View Type: " + OldView.ViewType.ToString() + "\nNew View Type: " + NewView.ViewType.ToString()); } } //Catch and Display any Exeptions that are thrown catch (Exception ex) { TaskDialog.Show("Error", ex.ToString()); //Set the Dialog result to False so the Command will not keep any changes DialogResult = false; //Close the Form Close(); } }
public bool IsElementVisibleInView( View view, Element el) { if (view == null) { throw new ArgumentNullException(nameof(view)); } if (el == null) { throw new ArgumentNullException(nameof(el)); } // Obtain the element's document. Document doc = el.Document; ElementId elId = el.Id; // Create a FilterRule that searches // for an element matching the given Id. FilterRule idRule = ParameterFilterRuleFactory .CreateEqualsRule( new ElementId(BuiltInParameter.ID_PARAM), elId); var idFilter = new ElementParameterFilter(idRule); // Use an ElementCategoryFilter to speed up the // search, as ElementParameterFilter is a slow filter. Category cat = el.Category; var catFilter = new ElementCategoryFilter(cat.Id); // Use the constructor of FilteredElementCollector // that accepts a view id as a parameter to only // search that view. // Also use the WhereElementIsNotElementType filter // to eliminate element types. FilteredElementCollector collector = new FilteredElementCollector(doc, view.Id) .WhereElementIsNotElementType() .WherePasses(catFilter) .WherePasses(idFilter); // If the collector contains any items, then // we know that the element is visible in the // given view. return(collector.Any()); }
internal static IList <ElementType> ViewportTypes(Document doc) { FilterRule rule = ParameterFilterRuleFactory.CreateEqualsRule(new ElementId((int)BuiltInParameter.SYMBOL_FAMILY_NAME_PARAM), "Viewport", false); ElementParameterFilter filter = new ElementParameterFilter(rule); IList <ElementType> viewportTypes; using (FilteredElementCollector fec = new FilteredElementCollector(doc).OfClass(typeof(ElementType)).WherePasses(filter)) { viewportTypes = fec.Cast <ElementType>().ToList(); } return(viewportTypes); }
static IEnumerable <Element> Factory( Document doc, BuiltInCategory BultCat, string familyTypeName) { return(new FilteredElementCollector(doc) .OfCategory(BultCat) .OfClass(typeof(FamilyInstance)) .WherePasses( new ElementParameterFilter( ParameterFilterRuleFactory.CreateEqualsRule( new ElementId(BuiltInParameter.ELEM_FAMILY_PARAM), familyTypeName, true)))); }
private IList <ElementId> CreateFiltersIfMissing(Document doc) { bool[] array = new bool[4]; FilteredElementCollector val = new FilteredElementCollector(doc); val.OfClass(typeof(ParameterFilterElement)); ICollection <ElementId> collection = val.ToElementIds(); foreach (ElementId item2 in collection) { Element val2 = doc.GetElement(item2); for (int i = 0; i < filterNames.Length; i++) { if (val2.get_Name() == filterNames[i]) { array[i] = true; } } } if (array.Any((bool b) => !b)) { ElementId val3 = LODapp.GetLODparameter(doc, "Current_LOD").get_Id(); IList <ElementId> list = (from cat in LODapp.lodCatArray where (int)cat != -2000220 select new ElementId(cat)).ToList(); Transaction val4 = new Transaction(doc, "Create LOD filters"); try { val4.Start(); for (int j = 0; j < filterNames.Length; j++) { if (!array[j]) { ParameterFilterElement val5 = ParameterFilterElement.Create(doc, filterNames[j], (ICollection <ElementId>)list); FilterRule item = ParameterFilterRuleFactory.CreateEqualsRule(val3, lodValues[j]); val5.SetRules((IList <FilterRule>) new List <FilterRule>(1) { item }); } } val4.Commit(); } catch (Exception innerException) { val4.RollBack(); throw new Exception("Failed to create filters.", innerException); } } return(GetLODfilters(doc)); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Tracer.Listeners.Add(new System.Diagnostics.EventLogTraceListener("Application")); UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; try { IList <FamilyInstance> openings = new FilteredElementCollector(doc, doc.ActiveView.Id) .OfCategory(BuiltInCategory.OST_Windows) .WherePasses(new ElementParameterFilter (ParameterFilterRuleFactory.CreateEqualsRule (new ElementId(BuiltInParameter.ALL_MODEL_FAMILY_NAME), SO_FAMILY_NAME, false))) .WhereElementIsNotElementType() .Cast <FamilyInstance>() .ToList(); if (openings.Count == 0) { throw new Exception("No opening has been unearthed. Toodle-pip."); } using (Transaction t = new Transaction(doc, "Mark Openings")) { t.Start(); foreach (FamilyInstance fi in openings) { if (fi.LookupParameter(SO_BTM_ELEV) == null) { throw new Exception(string.Format("{0} is null", nameof(SO_BTM_ELEV))); } double elev = ((Level)doc.GetElement(fi.LevelId)).Elevation + fi.get_Parameter (BuiltInParameter.INSTANCE_SILL_HEIGHT_PARAM).AsDouble(); fi.LookupParameter(SO_BTM_ELEV) .Set(elev); } t.Commit(); } return(Result.Succeeded); } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { return(Result.Cancelled); } catch (Exception ex) { Tracer.Write(string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); return(Result.Failed); } }
/// <summary> /// Получение элементов ключевой спецификации по её имени /// </summary> public static Element ViewKeyElement(string nameTabl) { FilterRule rule = ParameterFilterRuleFactory.CreateEqualsRule(new ElementId(BuiltInParameter.VIEW_NAME), nameTabl, false); var filter = new ElementParameterFilter(rule); FilteredElementCollector keysp = new FilteredElementCollector(_doc); keysp.OfClass(typeof(ViewSchedule)).WherePasses(filter); if (keysp.Count() != 1) { return(null); } //var sd = filter.PassesFilter(keysp.FirstElement()); return(keysp.FirstElement()); }
// Создание фильтров IdentityDataAnalysis_Visibility и IdentityDataAnalysis_AnVisibility, // назначение им правил private void CreateFilters(UIDocument uiDoc, Parameter parameter, List <Element> elements) { IList <FilterRule> visibilityFilterRules = new List <FilterRule>(); visibilityFilterRules.Add(ParameterFilterRuleFactory.CreateEqualsRule(parameter.Id, "", true)); ElementParameterFilter visibilityFilter = new ElementParameterFilter(visibilityFilterRules); IList <FilterRule> anVisibilityFilterRules = new List <FilterRule>(); anVisibilityFilterRules.Add(ParameterFilterRuleFactory.CreateNotEqualsRule(parameter.Id, "", true)); ElementParameterFilter anVisibilityFilter = new ElementParameterFilter(anVisibilityFilterRules); List <ElementId> categorysIds = GetUniquCategorysIds(elements); ParameterFilterElement filterForVisibility = CreateFilterElement(uiDoc.Document, "IdentityDataAnalysis_Visibility", categorysIds, visibilityFilter); ParameterFilterElement filterForAnVisibility = CreateFilterElement(uiDoc.Document, "IdentityDataAnalysis_AnVisibility", categorysIds, anVisibilityFilter); }
private ElementId FindScheduleByName(string scheduleName) { ElementParameterFilter viewNameFilter = new ElementParameterFilter( ParameterFilterRuleFactory .CreateBeginsWithRule( new ElementId(BuiltInParameter.VIEW_NAME), scheduleName, false)); return (new FilteredElementCollector(m_doc) .OfCategory(BuiltInCategory.OST_Schedules) .WherePasses(viewNameFilter) .ToElementIds() .FirstOrDefault()); }
ViewSchedule FindScheduleByName(Document doc, string scheduleName) { ElementParameterFilter viewNameFilter = new ElementParameterFilter( ParameterFilterRuleFactory .CreateBeginsWithRule( new ElementId(BuiltInParameter.VIEW_NAME), scheduleName, false)); return (new FilteredElementCollector(doc) .OfClass(typeof(ViewSchedule)) .WherePasses(viewNameFilter) .Cast <ViewSchedule>() .FirstOrDefault()); }
private static IList <ViewSchedule> GetAllSchedules(Document doc) { ElementParameterFilter elemNameFilter = new ElementParameterFilter(ParameterFilterRuleFactory .CreateNotContainsRule(new ElementId(BuiltInParameter.VIEW_NAME), "<Revision Schedule>", false)); return(new FilteredElementCollector(doc) .OfClass(typeof(ViewSchedule)) .WhereElementIsNotElementType() .WherePasses(elemNameFilter) .Cast <ViewSchedule>() .ToList() .OrderBy(s => s.Name) .ToList()); }
private static FilterRule CreateRule(ElementId ParameterId, string Function, string Value) { switch (Function) { case "Равно": return(ParameterFilterRuleFactory.CreateEqualsRule(ParameterId, Value, true)); case "Не равно": return(ParameterFilterRuleFactory.CreateNotEqualsRule(ParameterId, Value, true)); case "Больше": return(ParameterFilterRuleFactory.CreateGreaterRule(ParameterId, Value, true)); case "Больше или равно": return(ParameterFilterRuleFactory.CreateLessOrEqualRule(ParameterId, Value, true)); case "Меньше": return(ParameterFilterRuleFactory.CreateLessRule(ParameterId, Value, true)); case "Меньше или равно": return(ParameterFilterRuleFactory.CreateLessOrEqualRule(ParameterId, Value, true)); case "Содержит": return(ParameterFilterRuleFactory.CreateContainsRule(ParameterId, Value, true)); case "Не содержит": return(ParameterFilterRuleFactory.CreateNotContainsRule(ParameterId, Value, true)); case "Начинается с": return(ParameterFilterRuleFactory.CreateBeginsWithRule(ParameterId, Value, true)); case "Не начинается с": return(ParameterFilterRuleFactory.CreateNotBeginsWithRule(ParameterId, Value, true)); case "Заканчивается на": return(ParameterFilterRuleFactory.CreateEndsWithRule(ParameterId, Value, true)); case "Не заканчивается на": return(ParameterFilterRuleFactory.CreateNotEndsWithRule(ParameterId, Value, true)); case "Поддерживает": return(ParameterFilterRuleFactory.CreateSharedParameterApplicableRule(Value)); default: return(null); } }
IList <ViewSchedule> GetNecessarySchedules(Document doc, string scheduleCode) { ElementParameterFilter viewNameFilter = new ElementParameterFilter( ParameterFilterRuleFactory .CreateBeginsWithRule( new ElementId(BuiltInParameter.VIEW_NAME), scheduleCode, false)); return (new FilteredElementCollector(doc) .OfClass(typeof(ViewSchedule)) .WherePasses(viewNameFilter) .Cast <ViewSchedule>() .OrderBy(vs => vs.ViewName) .ToList()); }
public static void CreateViewFilter(Document doc, View view) { List <ElementId> categories = new List <ElementId>(); categories.Add(new ElementId(BuiltInCategory.OST_Walls)); List <FilterRule> filterRules = new List <FilterRule>(); try { // Create filter element associated to the input categories ParameterFilterElement parameterFilterElement = ParameterFilterElement.Create(doc, "Example view filter", categories); // Criterion 1 - wall type Function is "Exterior" ElementId exteriorParamId = new ElementId(BuiltInParameter.FUNCTION_PARAM); filterRules.Add(ParameterFilterRuleFactory.CreateEqualsRule(exteriorParamId, (int)WallFunction.Exterior)); // Criterion 2 - wall height > some number ElementId lengthId = new ElementId(BuiltInParameter.CURVE_ELEM_LENGTH); filterRules.Add(ParameterFilterRuleFactory.CreateGreaterOrEqualRule(lengthId, 28.0, 0.0001)); // Criterion 3 - custom shared parameter value matches string pattern // Get the id for the shared parameter - the ElementId is not hardcoded, so we need to get an instance of this type to find it Guid spGuid = new Guid("96b00b61-7f5a-4f36-a828-5cd07890a02a"); FilteredElementCollector collector = new FilteredElementCollector(doc); collector.OfClass(typeof(Wall)); Wall wall = collector.FirstElement() as Wall; if (wall != null) { Parameter sharedParam = wall.get_Parameter(spGuid); ElementId sharedParamId = sharedParam.Id; filterRules.Add(ParameterFilterRuleFactory.CreateBeginsWithRule(sharedParamId, "15.", true)); } parameterFilterElement.SetRules(filterRules); // Apply filter to view view.AddFilter(parameterFilterElement.Id); view.SetFilterVisibility(parameterFilterElement.Id, false); } catch { } }
protected override Result ProcessCommand(ExternalCommandData commandData, ref string message, ElementSet elements) { // Create Category var cats = new List <ElementId>(); cats.Add(new ElementId(BuiltInCategory.OST_Sections)); var sectionFilter = ParameterFilterRuleFactory.CreateContainsRule(new ElementId(BuiltInParameter.VIEW_NAME), "Section 1", false); var elementFilter = new ElementParameterFilter(sectionFilter); using (Transaction trans = new Transaction(_activeDocument, "Create Filter")) { trans.Start(); var filter = ParameterFilterElement.Create(_activeDocument, "Wall Filter", cats, elementFilter); _activeDocument.ActiveView.AddFilter(filter.Id); _activeDocument.ActiveView.SetFilterVisibility(filter.Id, false); trans.Commit(); } return(Result.Succeeded); }
/// <summary> /// Find all instances matching category and "Reference Level", and add to the collection of groups of sorted ids. /// </summary> /// <param name="idGroupsInOrder">The collection of groups of ids, sorted.</param> /// <param name="level">The level to match.</param> /// <param name="category">The category to match.</param> private static void AddInstancesOnReferenceLevelToIdGroupList(List <ICollection <ElementId> > idGroupsInOrder, Level level, BuiltInCategory category) { FilteredElementCollector collector = new FilteredElementCollector(level.Document); collector.OfCategory(category); collector.WhereElementIsNotElementType(); // Use a parameter filter to match the Reference Level parameter FilterRule rule = ParameterFilterRuleFactory.CreateEqualsRule(new ElementId(BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM), level.Id); collector.WherePasses(new ElementParameterFilter(rule)); ICollection <ElementId> idGroup = collector.ToElementIds(); // Only add non-empty groups if (idGroup.Count > 0) { idGroupsInOrder.Add(idGroup); } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { //FilterElementCollect的使用 UIDocument uiDoc = commandData.Application.ActiveUIDocument; Document doc = uiDoc.Document; FilteredElementCollector collector = new FilteredElementCollector(doc); //QuickFilter过滤所有窗 collector = collector.OfCategory(BuiltInCategory.OST_Windows).OfClass(typeof(FamilySymbol)); //FamilyInstanceFilter找1200*1500mm的窗 IEnumerable <Element> query = from element in collector where element.Name == "1200*1500mm" select element; List <Element> famSyms = query.ToList <Element>(); ElementId symbolId = famSyms[1].Id; FamilyInstanceFilter fiFilter = new FamilyInstanceFilter(doc, symbolId); FilteredElementCollector c1 = new FilteredElementCollector(doc); ICollection <Element> found = c1.WherePasses(fiFilter).ToElements(); //ElementParameterFilter找到标记小于五的窗 ElementId ruleValId = new ElementId(-10010203); 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); }
private static void SetReadonlyIds(Document doc, Func <Element, string> idGetter) { FilteredElementCollector collector = new FilteredElementCollector(doc); FilterRule rule = ParameterFilterRuleFactory.CreateSharedParameterApplicableRule("ReadonlyId"); ElementParameterFilter filter = new ElementParameterFilter(rule); collector.WherePasses(filter); using (Transaction t = new Transaction(doc, "Apply ReadonlyId")) { t.Start(); foreach (Element elem in collector) { Parameter p = elem.LookupParameter("ReadonlyId"); if (p != null) { p.Set(idGetter(elem)); } } t.Commit(); } }
public static Autodesk.Revit.DB.FilterRule GetElementIdRule(ElementId paramId, CriteriaName selectedCriteria, ElementId ruleValue) { Autodesk.Revit.DB.FilterRule rule = null; try { switch (selectedCriteria) { case CriteriaName.equals: rule = ParameterFilterRuleFactory.CreateEqualsRule(paramId, ruleValue); break; case CriteriaName.isgreaterthan: rule = ParameterFilterRuleFactory.CreateGreaterRule(paramId, ruleValue); break; case CriteriaName.isgreaterthanorequalto: rule = ParameterFilterRuleFactory.CreateGreaterOrEqualRule(paramId, ruleValue); break; case CriteriaName.islessthan: rule = ParameterFilterRuleFactory.CreateLessRule(paramId, ruleValue); break; case CriteriaName.islessthanorequalto: rule = ParameterFilterRuleFactory.CreateLessOrEqualRule(paramId, ruleValue); break; case CriteriaName.doesnotequal: rule = ParameterFilterRuleFactory.CreateNotEqualsRule(paramId, ruleValue); break; } } catch (Exception ex) { System.Windows.MessageBox.Show("Failed to get integer filter rule.\n" + ex.Message, "Get Integer Filter Rule", MessageBoxButton.OK, MessageBoxImage.Warning); } return(rule); }
internal static IList <ElementId> GetAllRebarIdsInView(View view) { ElementParameterFilter shpFamNameFilter = new ElementParameterFilter( ParameterFilterRuleFactory.CreateBeginsWithRule( new ElementId(BuiltInParameter.ELEM_FAMILY_PARAM), "R-SHP", false)); ElementParameterFilter sumFamNameFilter = new ElementParameterFilter( ParameterFilterRuleFactory.CreateBeginsWithRule( new ElementId(BuiltInParameter.ELEM_FAMILY_PARAM), "R-SUM", false)); ElementParameterFilter empFamNameFilter = new ElementParameterFilter( ParameterFilterRuleFactory.CreateBeginsWithRule( new ElementId(BuiltInParameter.ELEM_FAMILY_PARAM), "R-EMP", false)); List <ElementFilter> filters = new List <ElementFilter>() { shpFamNameFilter, sumFamNameFilter, empFamNameFilter }; LogicalOrFilter shpSumEmpFilter = new LogicalOrFilter(filters); return(new FilteredElementCollector(view.Document, view.Id) .OfCategory(BuiltInCategory.OST_DetailComponents) .WhereElementIsNotElementType() .WherePasses(shpSumEmpFilter) .ToElementIds() .ToList()); }
public static ParameterFilterElement CreateConstrFilter(Document doc, List <ElementId> catsIds, Parameter markParam, string mark, string filterNamePrefix) { string filterName = filterNamePrefix + "_Конструкция " + mark; ParameterFilterElement filter = DocumentGetter.GetFilterByName(doc, filterName); if (filter != null) { return(filter); } FilterRule markEquals = ParameterFilterRuleFactory.CreateEqualsRule(markParam.Id, mark, true); #if R2017 || R2018 filter = ParameterFilterElement.Create(doc, filterName, catsIds); filter.SetRules(new List <FilterRule> { markEquals }); #else ElementParameterFilter epf = new ElementParameterFilter(markEquals); filter = ParameterFilterElement.Create(doc, filterName, catsIds, epf); #endif return(filter); }