/// <summary> /// Return the first wall type with the given name. /// </summary> static WallType GetFirstWallTypeNamed( Document doc, string name) { // built-in parameter storing this // wall type's name: BuiltInParameter bip = BuiltInParameter.SYMBOL_NAME_PARAM; ParameterValueProvider provider = new ParameterValueProvider( new ElementId(bip)); FilterStringRuleEvaluator evaluator = new FilterStringEquals(); FilterRule rule = new FilterStringRule( provider, evaluator, name, false); ElementParameterFilter filter = new ElementParameterFilter(rule); FilteredElementCollector collector = new FilteredElementCollector(doc) .OfClass(typeof(WallType)) .WherePasses(filter); return(collector.FirstElement() as WallType); }
public static FilteredElementCollector collectorFromTreeView(Document doc, ObservableCollection <Node> nodes) { IList <ElementFilter> familyAndTypeFilters = new List <ElementFilter>(); foreach (var category in nodes) { foreach (var family in category.Children) { foreach (var familyType in family.Children) { if (familyType.IsChecked == true) { ParameterValueProvider fvp = new ParameterValueProvider(new ElementId(BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM)); FilterStringRuleEvaluator fsre = new FilterStringEquals(); string ruleString = String.Format("{0}: {1}", family.Text, familyType.Text); FilterRule fRule = new FilterStringRule(fvp, fsre, ruleString, true); ElementParameterFilter filter = new ElementParameterFilter(fRule); familyAndTypeFilters.Add(filter); } } } } LogicalOrFilter familyAndTypeFilter = new LogicalOrFilter(familyAndTypeFilters); FilteredElementCollector collector = new FilteredElementCollector(doc).WherePasses(familyAndTypeFilter); return(collector); }
/// <summary> /// Retrieve all supply air terminals from given document. /// Select all family instance elements of BuiltInCategory /// OST_DuctTerminal with system type equal to suppy air. /// </summary> public static FilteredElementCollector GetSupplyAirTerminals(Document doc) { FilteredElementCollector collector = new FilteredElementCollector(doc); collector.OfCategory(BuiltInCategory.OST_DuctTerminal); collector.OfClass(typeof(FamilyInstance)); //int n1 = collector.ToElements().Count; // 61 in sample model // ensure that system type equals supply air: // // in Revit 2009 and 2010 API, this did it: // //ParameterFilter parameterFilter = a.Filter.NewParameterFilter( // Bip.SystemType, CriteriaFilterType.Equal, ParameterValue.SupplyAir ); // in Revit 2011, create an ElementParameter filter. // Create filter by provider and evaluator: ParameterValueProvider provider = new ParameterValueProvider(new ElementId(Bip.SystemType)); FilterStringRuleEvaluator evaluator = new FilterStringEquals(); string ruleString = ParameterValue.SupplyAir; FilterRule rule = new FilterStringRule(provider, evaluator, ruleString, false); ElementParameterFilter filter = new ElementParameterFilter(rule); collector.WherePasses(filter); //int n2 = collector.ToElements().Count; // 51 in sample model return(collector); }
/// <summary> /// Возвращает список всех чистых помещений /// </summary> public static List <Room> GetAllCleanRooms(Document doc) { FilteredElementCollector collector = new FilteredElementCollector(doc); RoomFilter roomFilter = new RoomFilter(); collector.WherePasses(roomFilter); // Настройка фильтра для комнат заданным параметром "BL_Класс чистоты", // равным "A", "B", "C" или "D" Guid spGuid = new Guid("02f7e9d4-f055-479e-a36f-5b8e098d40f5"); Room fRoom = collector.FirstElement() as Room; Parameter testSharedParam = fRoom.get_Parameter(spGuid); ElementId sharedParamId = testSharedParam.Id; ParameterValueProvider provider = new ParameterValueProvider(sharedParamId); FilterStringRuleEvaluator fsreEqual = new FilterStringEquals(); string testStrCNC = "CNC"; string testVoidStrCNC = ""; FilterRule fCNCRule = new FilterStringRule(provider, fsreEqual, testStrCNC, false); FilterRule fVoidStrRule = new FilterStringRule(provider, fsreEqual, testVoidStrCNC, false); ElementParameterFilter paramNoCNCFilter = new ElementParameterFilter(fCNCRule, true); ElementParameterFilter paramNoVoidFilter = new ElementParameterFilter(fVoidStrRule, true); collector.WherePasses(paramNoVoidFilter).WherePasses(paramNoCNCFilter); List <Room> cleanRooms = (from e in collector.ToElements() where e is Room select e as Room).ToList <Room>(); return(cleanRooms); }
//Check to see if a Sheet Number already exists in the project and create it if not private ViewSheet CheckSheet(string _sheetNumber, ElementId _vpTypeId) { try { ViewSheet sheet = null; ParameterValueProvider pvp = new ParameterValueProvider(new ElementId(BuiltInParameter.SHEET_NUMBER)); FilterStringRuleEvaluator fsr = new FilterStringEquals(); FilterRule fRule = new FilterStringRule(pvp, fsr, _sheetNumber, true); ElementParameterFilter filter = new ElementParameterFilter(fRule); if (new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Sheets).WherePasses(filter).FirstOrDefault() is ViewSheet vs) { sheet = vs; } else { sheet = ViewSheet.Create(doc, _vpTypeId); sheet.Name = "DO NOT PRINT"; sheet.SheetNumber = _sheetNumber; //Set additional View Parameters based on Firm standards and Project Broswer Sorting templates //sheet.LookupParameter("Sheet Sort").Set("PLANS"); //Set the Appears In Sheet List to False so duplicate sheets do not appear in Sheet Index Schedule sheet.get_Parameter(BuiltInParameter.SHEET_SCHEDULED).Set(0); } return(sheet); } catch { return(null); } }
public ViewSheet ReferenceSheet(Document doc, View view) { ViewSheet viewhseetrf = null; DateTime start = DateTime.Now; FilterableValueProvider provider = new ParameterValueProvider(new ElementId(BuiltInParameter.VIEW_SHEET_VIEWPORT_INFO)); FilterRule rule = new FilterStringRule(provider, new FilterStringGreater(), string.Empty, false); ElementParameterFilter epf = new ElementParameterFilter(rule, false); FilteredElementCollector viewCol = new FilteredElementCollector(doc).WherePasses(epf); viewCol.OfClass(typeof(ViewSheet)); StringBuilder sb = new StringBuilder(); foreach (ViewSheet v in viewCol) { try { ISet <ElementId> col = v.GetAllPlacedViews(); foreach (var fg in col) { if (fg == view.Id) { sb.AppendLine("View: " + v.Name); viewhseetrf = v; } } } catch { } } return(viewhseetrf); }
/// <summary> /// Convert FilterRule to our custom FilterRuleBuilder which will be displayed in form controls /// </summary> /// <param name="param">Parameter to which the FilterRule is applied.</param> /// <param name="rule">FilterRule to be converted.</param> /// <returns>Custom FilterRuleBuilder data converted from FilterRule</returns> public static FilterRuleBuilder CreateFilterRuleBuilder(BuiltInParameter param, FilterRule rule) { // Maybe FilterRule is inverse rule, we need to find its inner rule(FilterValueRule) // Note that the rule may be inversed more than once. bool inverted = false; FilterRule innerRule = ReflectToInnerRule(rule, out inverted); if (innerRule is FilterStringRule) { FilterStringRule strRule = innerRule as FilterStringRule; FilterStringRuleEvaluator evaluator = strRule.GetEvaluator(); return(new FilterRuleBuilder(param, GetEvaluatorCriteriaName(evaluator, inverted), strRule.RuleString, strRule.RuleString.ToLower() == strRule.RuleString ? false : true)); } else if (innerRule is FilterDoubleRule) { FilterDoubleRule dbRule = innerRule as FilterDoubleRule; FilterNumericRuleEvaluator evaluator = dbRule.GetEvaluator(); return(new FilterRuleBuilder(param, GetEvaluatorCriteriaName(evaluator, inverted), dbRule.RuleValue, dbRule.Epsilon)); } else if (innerRule is FilterIntegerRule) { FilterIntegerRule intRule = innerRule as FilterIntegerRule; FilterNumericRuleEvaluator evaluator = intRule.GetEvaluator(); return(new FilterRuleBuilder(param, GetEvaluatorCriteriaName(evaluator, inverted), intRule.RuleValue)); } else if (innerRule is FilterElementIdRule) { FilterElementIdRule idRule = innerRule as FilterElementIdRule; FilterNumericRuleEvaluator evaluator = idRule.GetEvaluator(); return(new FilterRuleBuilder(param, GetEvaluatorCriteriaName(evaluator, inverted), idRule.RuleValue)); } // // for other rule, not supported yet throw new System.NotImplementedException("The filter rule is not recognizable and supported yet!"); }
public static FilteredElementCollector GetElementsByShareParamValue( Document doc, BuiltInCategory bic, string sParaName, string sValue) { SharedParameterElement para = (from p in new FilteredElementCollector(doc) .OfClass(typeof(SharedParameterElement)) .Cast <SharedParameterElement>() where p.Name.Equals(sParaName) select p).First(); ParameterValueProvider provider = new ParameterValueProvider(para.Id); FilterStringRuleEvaluator evaluator = new FilterStringEquals(); string sType = sValue; FilterRule rule = new FilterStringRule( provider, evaluator, sType, false); ElementParameterFilter filter = new ElementParameterFilter(rule); FilteredElementCollector collector = new FilteredElementCollector(doc) .OfCategory(bic) .WherePasses(filter); return(collector); }
/// <summary> /// Return the viewport on the given /// sheet displaying the given view. /// </summary> Element GetViewport(ViewSheet sheet, View view) { Document doc = sheet.Document; // filter for view name: BuiltInParameter bip = BuiltInParameter.VIEW_NAME; ParameterValueProvider provider = new ParameterValueProvider( new ElementId(bip)); FilterStringRuleEvaluator evaluator = new FilterStringEquals(); //FilterRule rule = new FilterStringRule( // 2021 // provider, evaluator, view.Name, true ); FilterRule rule = new FilterStringRule( // 2022 provider, evaluator, view.Name); ElementParameterFilter name_filter = new ElementParameterFilter(rule); BuiltInCategory bic = BuiltInCategory.OST_Viewports; // retrieve the specific named viewport: //Element viewport // = new FilteredElementCollector( doc ) // .OfCategory( bic ) // .WherePasses( name_filter ) // .FirstElement(); //return viewport; // unfortunately, there are not just one, // but two candidate elements. apparently, // we can distibuish them using the // owner view id property: List <Element> viewports = new List <Element>( new FilteredElementCollector(doc) .OfCategory(bic) .WherePasses(name_filter) .ToElements()); Debug.Assert(viewports[0].OwnerViewId.Equals(ElementId.InvalidElementId), "expected the first viewport to have an invalid owner view id"); Debug.Assert(!viewports[1].OwnerViewId.Equals(ElementId.InvalidElementId), "expected the second viewport to have a valid owner view id"); int i = 1; return(viewports[i]); }
private void DocumentOpenedAction(object sender, DocumentOpenedEventArgs even) { settings = ExtensibleStorage.GetTooltipInfo(even.Document.ProjectInformation); this.mysql = new MysqlUtil(settings); this.sqlite = new SQLiteHelper(settings); m_previousDocPathName = even.Document.PathName; current_doc = even.Document; //过滤测点待使用 //打开文档就过滤一次 keyNameToElementMap = new Dictionary <string, Element>(); BuiltInParameter testParam = BuiltInParameter.ALL_MODEL_TYPE_NAME; ParameterValueProvider pvp = new ParameterValueProvider(new ElementId(testParam)); FilterStringEquals eq = new FilterStringEquals(); FilterRule rule = new FilterStringRule(pvp, eq, Res.String_ParameterSurveyType, false); ElementParameterFilter paramFilter = new ElementParameterFilter(rule); Document document = current_doc; FilteredElementCollector elementCollector = new FilteredElementCollector(document).OfClass(typeof(FamilyInstance)); IList <Element> elems = elementCollector.WherePasses(paramFilter).ToElements(); foreach (var elem in elems) { string param_value = string.Empty; Parameter param = elem.get_Parameter(Res.String_ParameterName); if (null != param && param.StorageType == StorageType.String) { param_value = param.AsString(); if (!string.IsNullOrWhiteSpace(param_value)) { keyNameToElementMap.Add(param_value, elem); } } } //准备Material IEnumerable <Material> allMaterial = new FilteredElementCollector(even.Document).OfClass(typeof(Material)).Cast <Material>(); foreach (Material elem in allMaterial) { if (elem.Name.Equals(Res.String_Color_Redline)) { color_red = elem; } if (elem.Name.Equals(Res.String_Color_Gray)) { color_gray = elem; } if (elem.Name.Equals(Res.String_Color_Blue)) { color_blue = elem; } if (color_gray != null && color_red != null && color_blue != null) { this.ColorMaterialIsReady = true; break; } } }
public static FilteredElementCollector WhereParameterEqualsTo(this FilteredElementCollector collector, BuiltInParameter paramId, string value, bool caseSensitive = true) { using (var provider = new ParameterValueProvider(new ElementId(paramId))) using (var evaluator = new FilterStringEquals()) using (var rule = new FilterStringRule(provider, evaluator, value, caseSensitive)) using (var filter = new ElementParameterFilter(rule)) return(collector.WherePasses(filter)); }
public static ElementParameterFilter ParameterValueFilter(string valueQualifier, BuiltInParameter parameterName) { BuiltInParameter testParam = parameterName; ParameterValueProvider pvp = new ParameterValueProvider(new ElementId((int)testParam)); FilterStringRuleEvaluator str = new FilterStringEquals(); FilterStringRule paramFr = new FilterStringRule(pvp, str, valueQualifier, false); ElementParameterFilter epf = new ElementParameterFilter(paramFr); return(epf); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { // Get application and document objects UIApplication uiApp = commandData.Application; Document doc = uiApp.ActiveUIDocument.Document; UIDocument uidoc = uiApp.ActiveUIDocument; try { using (Transaction trans = new Transaction(doc, "UpperCase Views on Sheets.")) { // Delete all unnamed Reference Planes in the project // Create Filter to check for Name BuiltInParameter bip = BuiltInParameter.DATUM_TEXT; ParameterValueProvider provider = new ParameterValueProvider(new ElementId(bip)); FilterStringEquals evaluator = new FilterStringEquals(); FilterStringRule rule = new FilterStringRule(provider, evaluator, "", false); ElementParameterFilter filter = new ElementParameterFilter(rule); ICollection <ElementId> refPlanes = new FilteredElementCollector(doc) .OfClass(typeof(ReferencePlane)) .WherePasses(filter) .ToElementIds(); int count = refPlanes.Count; try { trans.Start(); doc.Delete(refPlanes); trans.Commit(); } catch (Exception x) { message = x.Message; return(Result.Failed); } TaskDialog.Show("Delete Reference Planes", "You have successfully delete " + count.ToString() + " unnamed reference planes!"); return(Result.Succeeded); } } // Catch any Exceptions and display them. catch (Autodesk.Revit.Exceptions.OperationCanceledException) { return(Result.Cancelled); } catch (Exception x) { message = x.Message; return(Result.Failed); } }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { // Get application and document objects UIApplication uiApp = commandData.Application; Document doc = uiApp.ActiveUIDocument.Document; UIDocument uidoc = uiApp.ActiveUIDocument; try { using (Transaction trans = new Transaction(doc, "UpperCase Views on Sheets.")) { // Delete all unnamed Reference Planes in the project // Create Filter to check for Name BuiltInParameter bip = BuiltInParameter.DATUM_TEXT; ParameterValueProvider provider = new ParameterValueProvider(new ElementId(bip)); FilterStringEquals evaluator = new FilterStringEquals(); FilterStringRule rule = new FilterStringRule(provider, evaluator, "", false); ElementParameterFilter filter = new ElementParameterFilter(rule); ICollection<ElementId> refPlanes = new FilteredElementCollector(doc) .OfClass(typeof(ReferencePlane)) .WherePasses(filter) .ToElementIds(); int count = refPlanes.Count; try { trans.Start(); doc.Delete(refPlanes); trans.Commit(); } catch (Exception x) { message = x.Message; return Result.Failed; } TaskDialog.Show("Delete Reference Planes", "You have successfully delete " + count.ToString() + " unnamed reference planes!"); return Result.Succeeded; } } // Catch any Exceptions and display them. catch (Autodesk.Revit.Exceptions.OperationCanceledException) { return Result.Cancelled; } catch (Exception x) { message = x.Message; return Result.Failed; } }
/// <summary> /// Retrieve all circuit elements in current active document, /// which we identify as all family instance or electrical system /// elements with a non-empty RBS_ELEC_CIRCUIT_NUMBER or "Circuit Number" /// parameter. /// </summary> public static IList <Element> GetCircuitElements(Document doc) { // // prepend as many 'fast' filters as possible, because parameter access is 'slow': // ElementClassFilter f1 = new ElementClassFilter(typeof(FamilyInstance)); ElementClassFilter f2 = new ElementClassFilter(typeof(ElectricalSystem)); LogicalOrFilter f3 = new LogicalOrFilter(f1, f2); FilteredElementCollector collector = new FilteredElementCollector(doc).WherePasses(f3); BuiltInParameter bip = BuiltInParameter.RBS_ELEC_CIRCUIT_NUMBER; #if DEBUG int n1 = collector.ToElements().Count; List <Element> a = new List <Element>(); foreach (Element e in collector) { Parameter p = e.get_Parameter(BuiltInParameter.RBS_ELEC_CIRCUIT_NUMBER); if (null != p && 0 < p.AsString().Length) { a.Add(e); } } int n2 = a.Count; Debug.Assert(n1 > n2, "expected filter to eliminate something"); List <Element> b = ( from e in collector.ToElements() where (null != e.get_Parameter(bip)) && (0 < e.get_Parameter(bip).AsString().Length) select e).ToList <Element>(); int n3 = b.Count; Debug.Assert(n2 == n3, "expected to reproduce same result"); #endif // DEBUG // // this is unclear ... negating the rule that says the parameter // exists and is empty could mean that elements pass if the parameter // is non-empty, but also if the parameter does not exist ... // so maybe returning the collection b instead of c would be a safer bet? // ParameterValueProvider provider = new ParameterValueProvider(new ElementId(bip)); FilterStringRuleEvaluator evaluator = new FilterStringEquals(); FilterRule rule = new FilterStringRule(provider, evaluator, string.Empty, false); ElementParameterFilter filter = new ElementParameterFilter(rule, true); collector.WherePasses(filter); IList <Element> c = collector.ToElements(); int n4 = c.Count; Debug.Assert(n2 == n4, "expected to reproduce same result"); return(c); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uidoc = commandData.Application.ActiveUIDocument; try { int roomNum = 1; while (true) { Reference selRef = uidoc.Selection.PickObject(ObjectType.Element, new MySelectionFilter(), "Pick a room 2"); Room room = (Room)uidoc.Document.GetElement(selRef.ElementId); FilteredElementCollector collector = new FilteredElementCollector(uidoc.Document); collector.WherePasses(new RoomFilter()); ParameterValueProvider provider = new ParameterValueProvider(new ElementId(BuiltInParameter.ROOM_NUMBER)); FilterStringEquals evaluator = new FilterStringEquals(); FilterStringRule rule = new FilterStringRule(provider, evaluator, roomNum.ToString(), false); ElementParameterFilter filter = new ElementParameterFilter(rule); collector.WherePasses(filter); IList <Element> rooms = collector.ToElements(); if (rooms.Count > 0) { ((Room)(rooms[0])).Number = room.Number; } room.Number = roomNum.ToString(); uidoc.Document.Regenerate(); roomNum++; } } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { } return(Result.Succeeded); }
private static ElementFilter CreateFilter(string field) { var paramValue = field.Equals("mark") ? FindNamedParameter(field) : new ParameterValueProvider(new ElementId(BuiltInParameter.ALL_MODEL_MARK)); FilterRule filterRule = new FilterStringRule(paramValue, new FilterStringContains(), field, false); ElementFilter filter = new ElementParameterFilter(filterRule); return(filter); }
//returns a list of elements that have the same value for a specific parameter public static List <Element> GetElementsWithTheSameParameterValue(BuiltInParameter parameter, string value) { List <Element> elements = new List <Element>(); ParameterValueProvider provider = new ParameterValueProvider(new ElementId((int)parameter)); FilterStringRule rule1 = new FilterStringRule(provider, new FilterStringEquals(), value, false); ElementParameterFilter filter1 = new ElementParameterFilter(rule1, false); return ((new FilteredElementCollector(doc)) .WherePasses(filter1) .ToElements() as List <Element>); }
public IEnumerable <Element> Find() { var collector = new FilteredElementCollector(_document); var filterStringRule = new FilterStringRule( new ParameterValueProvider(new ElementId(10616104)), new FilterStringContains(), "Квартира", false); var parameterFilter = new ElementParameterFilter(filterStringRule); var list = collector.WherePasses(new RoomFilter()).WherePasses(parameterFilter).ToElements(); return(list); }
/// <summary> /// Generic Parameter value filter. An attempt to write a generic method, /// that returns an element filter consumed by FilteredElementCollector. /// </summary> /// <typeparam name="T1">Type of the parameter VALUE to filter by.</typeparam> /// <typeparam name="T2">Type of the PARAMETER to filter.</typeparam> /// <param name="value">Currently: string, bool.</param> /// <param name="parameterId">Currently: Guid, BuiltInCategory.</param> /// <returns>ElementParameterFilter consumed by FilteredElementCollector.</returns> public static ElementParameterFilter ParameterValueGenericFilter <T1, T2>(Document doc, T1 value, T2 parameterId) { //Initialize ParameterValueProvider ParameterValueProvider pvp = null; switch (parameterId) { case BuiltInParameter bip: pvp = new ParameterValueProvider(new ElementId((int)bip)); break; case Guid guid: SharedParameterElement spe = SharedParameterElement.Lookup(doc, guid); pvp = new ParameterValueProvider(spe.Id); break; default: throw new NotImplementedException("ParameterValueGenericFilter: T2 (parameter) type not implemented!"); } //Branch off to value types switch (value) { case string str: FilterStringRuleEvaluator fsrE = new FilterStringEquals(); FilterStringRule fsr = new FilterStringRule(pvp, fsrE, str, false); return(new ElementParameterFilter(fsr)); case bool bol: int _value; if (bol == true) { _value = 1; } else { _value = 0; } FilterNumericRuleEvaluator fnrE = new FilterNumericEquals(); FilterIntegerRule fir = new FilterIntegerRule(pvp, fnrE, _value); return(new ElementParameterFilter(fir)); default: throw new NotImplementedException("ParameterValueGenericFilter: T1 (value) type not implemented!"); } }
//Checks to see if a viewport with a specific detail number already exists private bool CheckViewport(string _detailNumber, ViewSheet _vs) { ParameterValueProvider pvp = new ParameterValueProvider(new ElementId(BuiltInParameter.VIEWPORT_DETAIL_NUMBER)); FilterStringRuleEvaluator fsr = new FilterStringEquals(); FilterRule fRule = new FilterStringRule(pvp, fsr, _detailNumber, true); ElementParameterFilter filter = new ElementParameterFilter(fRule); if (new FilteredElementCollector(doc, _vs.Id).OfCategory(BuiltInCategory.OST_Viewports).WherePasses(filter).FirstOrDefault() is Viewport vp) { return(false); } else { return(true); } }
//This method will check to see if there are any Schedules in the specified document with the same name internal static bool CheckSchedule(Document _doc, string _name) { ParameterValueProvider pvp = new ParameterValueProvider(new ElementId(BuiltInParameter.VIEW_NAME)); FilterStringRuleEvaluator fsr = new FilterStringEquals(); FilterRule fRule = new FilterStringRule(pvp, fsr, _name, true); ElementParameterFilter filter = new ElementParameterFilter(fRule); if (new FilteredElementCollector(_doc).OfCategory(BuiltInCategory.OST_Schedules).WherePasses(filter).FirstOrDefault() is ViewSchedule vs) { return(false); } else { return(true); } }
public View ReferenceViews() { View viewrf = null; View view = doc.ActiveView; FilteredElementCollector viewersCollector = new FilteredElementCollector(doc); viewersCollector.OfCategory(BuiltInCategory.OST_Viewers); Element elem = null; foreach (Element e in viewersCollector) { if (e.Name == view.Name) { elem = e; } } if (elem != null) { DateTime start = DateTime.Now; FilterableValueProvider provider = new ParameterValueProvider(new ElementId(BuiltInParameter.VIEWPORT_SHEET_NUMBER)); FilterRule rule = new FilterStringRule(provider, new FilterStringGreater(), string.Empty, false); ElementParameterFilter epf = new ElementParameterFilter(rule, false); FilteredElementCollector viewCol = new FilteredElementCollector(doc).WherePasses(epf); viewCol.OfClass(typeof(View)); StringBuilder sb = new StringBuilder(); foreach (View v in viewCol) { if (v.Id.IntegerValue == view.Id.IntegerValue || v.IsTemplate || v.ViewType == ViewType.DrawingSheet || v.ViewType == ViewType.ColumnSchedule) { continue; } try { ICollection <ElementId> col = new FilteredElementCollector(doc, v.Id).ToElementIds(); if (col.Contains(elem.Id)) { sb.AppendLine("View: " + v.Name); } viewrf = v; } catch { } } } return(viewrf); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { uiApp = commandData.Application; uiDoc = uiApp.ActiveUIDocument; app = uiApp.Application; doc = uiDoc.Document; FilteredElementCollector refPlaneCollector = new FilteredElementCollector(doc); IList<Element> refPlanes = refPlaneCollector.OfClass(typeof(ReferencePlane)).ToElements(); ElementId nameParamterId = new ElementId(BuiltInParameter.DATUM_TEXT); ParameterValueProvider pvp = new ParameterValueProvider(nameParamterId); FilterStringRuleEvaluator evaluator = new FilterStringEquals(); FilterRule rule = new FilterStringRule(pvp, evaluator, "", false); ElementFilter filter = new ElementParameterFilter(rule); FilteredElementCollector unnamedRefPlaneCollector = new FilteredElementCollector(doc); unnamedRefPlaneCollector.OfClass(typeof(ReferencePlane)); unnamedRefPlaneCollector.WherePasses(filter); IList<Element> unnamedRefPlanes = unnamedRefPlaneCollector.ToElements(); Transaction transaction = new Transaction(doc); transaction.Start("Purging unnamed reference planes"); foreach (Element refPlane in unnamedRefPlanes) doc.Delete(refPlane.Id); transaction.Commit(); TaskDialog.Show("Purge Unnamed Ref Planes", String.Format("{0} reference planes found.\n{1} unnamed reference planes deleted.", refPlanes.Count.ToString(), unnamedRefPlanes.Count.ToString())); return Result.Succeeded; } catch (Exception e) { TaskDialog.Show("Revit Quick Tools", e.Message); return Result.Failed; } }
private IList <Element> GetElementValueIntOrstring(RevitParameter valRevitParameter, List <ElementId> valCategoryElementId, string valValue) { IList <Element> vResult = new List <Element>(); IList <Element> vResultTemp = new List <Element>(); foreach (var vCategoryId in valCategoryElementId) { IList <ElementFilter> vList = new List <ElementFilter>(); BuiltInCategory vBuiltInCategory = (BuiltInCategory)vCategoryId.IntegerValue; ParameterValueProvider vPovider = new ParameterValueProvider(valRevitParameter.ElementId); string vRulestring = valValue; FilterStringRuleEvaluator vEvaluator = new FilterStringEquals(); FilteredElementCollector vCollector = new FilteredElementCollector(_Doc); vCollector.OfCategory(vBuiltInCategory); FilterRule vRuleRulestring = new FilterStringRule(vPovider, vEvaluator, vRulestring, false); ElementParameterFilter vFilterRulestring = new ElementParameterFilter(vRuleRulestring); LibNumeric insLibNumeric = new LibNumeric(); if (insLibNumeric.IsInt(valValue)) { int vNum = 0; int.TryParse(valValue, out vNum); FilterNumericEquals vEvaluatorNumeri = new FilterNumericEquals(); int vRuleIntVal = vNum; var vFilterIntRule = new FilterIntegerRule(vPovider, vEvaluatorNumeri, vRuleIntVal); var vElementParameterFilterIntRule = new ElementParameterFilter(vFilterIntRule); vList.Add(vElementParameterFilterIntRule); } vList.Add(vFilterRulestring); LogicalOrFilter vLogicalOrFilter = new LogicalOrFilter(vList); vCollector.WherePasses(vLogicalOrFilter); IList <Element> vElements = vCollector.ToElements(); if (vElements != null) { if (vElements.Count > 0) { foreach (var vElement in vElements) { vResult.Add(vElement); } } } } return(vResult); }
/// <summary> /// Collects all available Arrowhead Styles in the project. /// </summary> private void CollectArrowheads() { try { var eId = new ElementId(BuiltInParameter.ALL_MODEL_FAMILY_NAME); var provider = new ParameterValueProvider(eId); FilterStringRuleEvaluator evaluator = new FilterStringEquals(); FilterRule rule = new FilterStringRule(provider, evaluator, "Arrowhead", false); var filter = new ElementParameterFilter(rule); var leaders = new FilteredElementCollector(m_doc) .OfClass(typeof(ElementType)) .WherePasses(filter) .ToElements(); foreach (var element in leaders) { if (string.IsNullOrEmpty(element.Name)) { continue; } var arrowhead = new Arrowhead(element); arrowheadList.Add(arrowhead); } var sortedlist = from arrow in arrowheadList orderby arrow.ArrowName select arrow; arrowheadList = sortedlist.ToList(); comboBoxArrow.ItemsSource = arrowheadList; comboBoxArrow.DisplayMemberPath = "ArrowName"; comboBoxArrow.SelectedValuePath = "ArrowElementId"; if (arrowheadList.Count > 0) { comboBoxArrow.SelectedIndex = 0; } } catch (Exception ex) { Log.AppendLog(LogMessageType.EXCEPTION, ex.Message); } }
/// <summary> /// Find a specific family type for a wall, which is a system family. /// Most efficient way to find a named family symbol: use a parameter filter. /// </summary> public Element FindFamilyType_Wall_v3(string wallFamilyName, string wallTypeName) { ParameterValueProvider provider = new ParameterValueProvider( new ElementId(BuiltInParameter.DATUM_TEXT)); FilterStringRuleEvaluator evaluator = new FilterStringEquals(); FilterRule rule = new FilterStringRule( provider, evaluator, wallTypeName, true); ElementParameterFilter filter = new ElementParameterFilter(rule); return(new FilteredElementCollector(_doc) .OfClass(typeof(WallType)) .WherePasses(filter) .FirstElement()); }
//Check to see if Sheet exists using the unique Sheet Number private ViewSheet CheckSheet(string _sheetNumber, ViewSheet _vs) { try { //Create an Empty ViewSheet object to return if sheet is found ViewSheet sheet = null; //Use Parameter Value Provider, Filter Rules, and Element Filters to narrow the results of the Element Collector in the most efficient way ParameterValueProvider pvp = new ParameterValueProvider(new ElementId(BuiltInParameter.SHEET_NUMBER)); FilterStringRuleEvaluator fsr = new FilterStringEquals(); //Check that the PVP (Sheet Number) is equal to the Sheet Number passed to the Method FilterRule fRule = new FilterStringRule(pvp, fsr, _sheetNumber, true); //This is the total Filter to use on the Collector ElementParameterFilter filter = new ElementParameterFilter(fRule); //Use an Elemeent Collector to get the sheet with the Sheet Number passed to the Method if (new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Sheets).WherePasses(filter).FirstOrDefault() is ViewSheet vs) { //Return the ViewSheet Obeject if there is one that matches in the current document sheet = vs; } //If there is not a Sheet with the Sheet Number passed, create one else { //Get the Titleblock Type from the sheet it was on and use for the new Sheet FamilyInstance tb = new FilteredElementCollector(doc, _vs.Id).OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_TitleBlocks).FirstOrDefault() as FamilyInstance; //Create a new Sheet with the Titleblock sheet = ViewSheet.Create(doc, tb.Symbol.Id); //Set the Sheet Name, Number, and Appears In Sheet List parameters sheet.Name = "DO NOT PRINT"; sheet.SheetNumber = _sheetNumber; sheet.LookupParameter("Appears In Sheet List").Set(0); } //Return either the existing Sheet or the New Sheet return(sheet); } catch { //Return a null sheet if there is an error return(null); } }
public void RoomRenumbering() { UIDocument uidoc = ActiveUIDocument; Document doc = uidoc.Document; try { int roomNumber = 1; while (true) { Reference selRef = uidoc.Selection.PickObject(ObjectType.Element, new mySelectionFilter(), "Select a room"); Room room = (Room)doc.GetElement(selRef.ElementId); FilteredElementCollector collector = new FilteredElementCollector(doc); collector.OfClass(typeof(SpatialElement)); collector.WherePasses(new RoomFilter()); ParameterValueProvider provider = new ParameterValueProvider(new ElementId(BuiltInParameter.ROOM_NUMBER)); FilterStringEquals evaluator = new FilterStringEquals(); FilterStringRule rule = new FilterStringRule(provider, evaluator, roomNumber.ToString(), false); ElementParameterFilter filter = new ElementParameterFilter(rule); collector.WherePasses(filter); IList <Element> rooms = collector.ToElements(); using (Transaction t = new Transaction(doc, "Modify room number")) { t.Start(); if (rooms.Count > 0) { ((Room)rooms[0]).Number = room.Number; } room.Number = roomNumber.ToString(); doc.Regenerate(); t.Commit(); } roomNumber++; } } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { } }
//This Method will return the ViewSheet by Sheet Number if it exists private ViewSheet CheckSheet(string _sheetNumber) { try { //Create the variables needed for an Element Filter to search for ONLY the one sheet ParameterValueProvider pvp = new ParameterValueProvider(new ElementId(BuiltInParameter.SHEET_NUMBER)); FilterStringRuleEvaluator fsr = new FilterStringEquals(); FilterRule fRule = new FilterStringRule(pvp, fsr, _sheetNumber, true); ElementParameterFilter filter = new ElementParameterFilter(fRule); //Use a Collector to search for only the One sheet with the supplied sheet number and if a ViewSheet is found, return it if (new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Sheets).WherePasses(filter).FirstOrDefault() is ViewSheet Sheet) { return(Sheet); } //If no sheet is found, return null return(null); } catch { //If an exception is thrown in the Try block, return null return(null); } }
////////////////////////////////////////////////////////////////////////////////////////// /////////////////// Get collection of elements by name /////////////////////////////// public FilteredElementCollector GetElementofNameType(Document doc, string name) { FilteredElementCollector a = new FilteredElementCollector(doc) .OfClass(typeof(FamilyInstance)); BuiltInParameter bip = BuiltInParameter.ALL_MODEL_TYPE_NAME; ParameterValueProvider provider = new ParameterValueProvider( new ElementId(bip)); FilterStringRuleEvaluator evaluator = new FilterStringEquals(); FilterRule rule = new FilterStringRule( provider, evaluator, name, true); ElementParameterFilter filter = new ElementParameterFilter(rule); return(a.WherePasses(filter)); }
/// <summary> /// Find a specific family type for a wall, which is a system family. /// Most efficient way to find a named family symbol: use a parameter filter. /// </summary> public Element FindFamilyType_Wall_v3( string wallFamilyName, string wallTypeName) { ParameterValueProvider provider = new ParameterValueProvider( new ElementId(BuiltInParameter.DATUM_TEXT)); FilterStringRuleEvaluator evaluator = new FilterStringEquals(); FilterRule rule = new FilterStringRule( provider, evaluator, wallTypeName, true); ElementParameterFilter filter = new ElementParameterFilter(rule); return new FilteredElementCollector(_doc) .OfClass(typeof(WallType)) .WherePasses(filter) .FirstElement(); }
void f3( Document doc ) { FilteredElementCollector collector = new FilteredElementCollector( doc ); collector.OfClass( typeof( Level ) ); ElementId id = new ElementId( BuiltInParameter.DATUM_TEXT ); ParameterValueProvider provider = new ParameterValueProvider( id ); FilterStringRuleEvaluator evaluator = new FilterStringContains(); FilterRule rule = new FilterStringRule( provider, evaluator, "Level", false ); ElementParameterFilter filter = new ElementParameterFilter( rule ); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; // Construct a parameter filter to get only // unnamed reference planes, i.e. reference // planes whose name equals the empty string: BuiltInParameter bip = BuiltInParameter.DATUM_TEXT; ParameterValueProvider provider = new ParameterValueProvider( new ElementId(bip)); FilterStringRuleEvaluator evaluator = new FilterStringEquals(); FilterStringRule rule = new FilterStringRule( provider, evaluator, "", false); ElementParameterFilter filter = new ElementParameterFilter(rule); FilteredElementCollector col = new FilteredElementCollector(doc) .OfClass(typeof(ReferencePlane)) .WherePasses(filter); int n = 0; int nDeleted = 0; // No need to cast ... this is pretty nifty, // I find ... grab the elements as ReferencePlane // instances, since the filter guarantees that // only ReferencePlane instances are selected. // In Revit 2014, this attempt to delete the // reference planes while iterating over the // filtered element collector throws an exception: // Autodesk.Revit.Exceptions.InvalidOperationException: // HResult=-2146233088 // Message=The iterator cannot proceed due to // changes made to the Element table in Revit's // database (typically, This can be the result // of an Element deletion). // //foreach( ReferencePlane rp in col ) //{ // ++n; // nDeleted += DeleteIfNotHosting( rp ) ? 1 : 0; //} ICollection <ElementId> ids = col.ToElementIds(); n = ids.Count(); if (0 < n) { using (Transaction tx = new Transaction(doc)) { tx.Start(string.Format( "Delete {0} ReferencePlane{1}", n, Util.PluralSuffix(n))); // This also causes the exception "One or more of // the elementIds cannot be deleted. Parameter // name: elementIds // //ICollection<ElementId> ids2 = doc.Delete( // ids ); //nDeleted = ids2.Count(); List <ElementId> ids2 = new List <ElementId>( ids); foreach (ElementId id in ids2) { try { ICollection <ElementId> ids3 = doc.Delete( id); nDeleted += ids3.Count; } catch (Autodesk.Revit.Exceptions.ArgumentException) { } } tx.Commit(); } } Util.InfoMsg(string.Format( "{0} unnamed reference plane{1} examined, " + "{2} element{3} in total were deleted.", n, Util.PluralSuffix(n), nDeleted, Util.PluralSuffix(nDeleted))); return(Result.Succeeded); }
public Result Execute( ExternalCommandData commandData, ref string messages, ElementSet elements) { UIApplication app = commandData.Application; Document doc = app.ActiveUIDocument.Document; ElementId id = new ElementId( BuiltInParameter.ELEM_ROOM_NUMBER ); ParameterValueProvider provider = new ParameterValueProvider( id ); FilterStringRuleEvaluator evaluator = new FilterStringEquals(); string sRoomNumber = "1"; FilterRule rule = new FilterStringRule( provider, evaluator, sRoomNumber, false ); ElementParameterFilter filter = new ElementParameterFilter( rule ); FilteredElementCollector collector = new FilteredElementCollector( doc ); string s = string.Empty; foreach( Element e in collector ) { s += e.Name + e.Category.Name.ToString() + "\n"; } System.Windows.Forms.MessageBox.Show( s ); return Result.Succeeded; }
/// <summary> /// Return a list of all elements with the /// specified value in their shared parameter with /// the given name oand group. They are retrieved /// using a parameter filter, and the required /// parameter id is found by temporarily adding /// the shared parameter to the project info. /// </summary> static IList<Element> GetElementsMatchingParameter( Document doc, string paramName, string paramGroup, string paramValue) { IList<Element> elems = new List<Element>(); // Determine if definition for parameter binding exists Definition definition = null; BindingMap bm = doc.ParameterBindings; DefinitionBindingMapIterator it = bm.ForwardIterator(); while( it.MoveNext() ) { Definition def = it.Key; if( def.Name.Equals( paramName ) ) { definition = def; break; } } if( definition == null ) { return elems; // parameter binding not defined } using( Transaction tx = new Transaction( doc ) ) { tx.Start( "Set temporary parameter" ); // Temporarily set project information element // parameter in order to determine param.Id FilteredElementCollector collectorPI = new FilteredElementCollector( doc ); collectorPI.OfCategory( BuiltInCategory.OST_ProjectInformation ); Element projInfoElem = collectorPI.FirstElement(); // using http://thebuildingcoder.typepad.com/blog/2012/04/adding-a-category-to-a-shared-parameter-binding.html Parameter param = null; //param = HelperParams.GetOrCreateElemSharedParam( // projInfoElem, paramName, paramGroup, // ParameterType.Text, false, true ); if( param != null ) { ElementId paraId = param.Id; tx.RollBack(); // discard project element change ParameterValueProvider provider = new ParameterValueProvider( paraId ); FilterRule rule = new FilterStringRule( provider, new FilterStringEquals(), paramValue, true ); ElementParameterFilter filter = new ElementParameterFilter( rule ); FilteredElementCollector collector = new FilteredElementCollector( doc, doc.ActiveView.Id ); elems = collector.WherePasses( filter ) .ToElements(); } } return elems; }
/// <summary> /// Use a parameter filter to return the first element /// of the given type and with the specified string-valued /// built-in parameter matching the given name. /// </summary> Element GetFirstElementOfTypeWithBipString( Type type, BuiltInParameter bip, string name) { FilteredElementCollector a = GetElementsOfType( type ); ParameterValueProvider provider = new ParameterValueProvider( new ElementId( bip ) ); FilterStringRuleEvaluator evaluator = new FilterStringEquals(); FilterRule rule = new FilterStringRule( provider, evaluator, name, true ); ElementParameterFilter filter = new ElementParameterFilter( rule ); return a.WherePasses( filter ).FirstElement(); }
void f4( Document doc ) { // Use numeric evaluator and integer rule to test ElementId parameter // Filter levels whose id is greater than specified id value BuiltInParameter testParam = BuiltInParameter.ID_PARAM; ParameterValueProvider pvp = new ParameterValueProvider( new ElementId( (int) testParam ) ); FilterNumericRuleEvaluator fnrv = new FilterNumericGreater(); // filter elements whose Id is greater than 99 ElementId ruleValId = new ElementId( 99 ); FilterRule paramFr = new FilterElementIdRule( pvp, fnrv, ruleValId ); ElementParameterFilter epf = new ElementParameterFilter( paramFr ); FilteredElementCollector collector = new FilteredElementCollector( doc ); collector.OfClass( typeof( ViewPlan ) ) .WherePasses( epf ); // only deal with ViewPlan // Use numeric evaluator and integer rule to test bool parameter // Filter levels whose crop view is false int ruleValInt = 0; testParam = BuiltInParameter.VIEWER_CROP_REGION; pvp = new ParameterValueProvider( new ElementId( (int) testParam ) ); fnrv = new FilterNumericEquals(); paramFr = new FilterIntegerRule( pvp, fnrv, ruleValInt ); epf = new ElementParameterFilter( paramFr ); collector = new FilteredElementCollector( doc ); collector.OfClass( typeof( ViewPlan ) ) .WherePasses( epf ); // only deal with ViewPlan // Use numeric evaluator and double rule to test double parameter // Filter levels whose top offset is greater than specified value double ruleValDb = 10; testParam = BuiltInParameter.VIEWER_BOUND_OFFSET_TOP; pvp = new ParameterValueProvider( new ElementId( (int) testParam ) ); fnrv = new FilterNumericGreater(); paramFr = new FilterDoubleRule( pvp, fnrv, ruleValDb, double.Epsilon ); collector = new FilteredElementCollector( doc ); collector.OfClass( typeof( ViewPlan ) ) .WherePasses( epf ); // only deal with ViewPlan // Use string evaluator and string rule to test string parameter // Filter all elements whose view name contains level String ruleValStr = "Level"; testParam = BuiltInParameter.VIEW_NAME; pvp = new ParameterValueProvider( new ElementId( (int) testParam ) ); FilterStringRuleEvaluator fnrvStr = new FilterStringContains(); paramFr = new FilterStringRule( pvp, fnrvStr, ruleValStr, false ); collector = new FilteredElementCollector( doc ); collector.OfClass( typeof( ViewPlan ) ) .WherePasses( epf ); // only deal with ViewPlan }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; // Construct a parameter filter to get only // unnamed reference planes, i.e. reference // planes whose name equals the empty string: BuiltInParameter bip = BuiltInParameter.DATUM_TEXT; ParameterValueProvider provider = new ParameterValueProvider( new ElementId( bip ) ); FilterStringRuleEvaluator evaluator = new FilterStringEquals(); FilterStringRule rule = new FilterStringRule( provider, evaluator, "", false ); ElementParameterFilter filter = new ElementParameterFilter( rule ); FilteredElementCollector col = new FilteredElementCollector( doc ) .OfClass( typeof( ReferencePlane ) ) .WherePasses( filter ); int n = 0; int nDeleted = 0; // No need to cast ... this is pretty nifty, // I find ... grab the elements as ReferencePlane // instances, since the filter guarantees that // only ReferencePlane instances are selected. // In Revit 2014, this attempt to delete the // reference planes while iterating over the // filtered element collector throws an exception: // Autodesk.Revit.Exceptions.InvalidOperationException: // HResult=-2146233088 // Message=The iterator cannot proceed due to // changes made to the Element table in Revit's // database (typically, This can be the result // of an Element deletion). // //foreach( ReferencePlane rp in col ) //{ // ++n; // nDeleted += DeleteIfNotHosting( rp ) ? 1 : 0; //} ICollection<ElementId> ids = col.ToElementIds(); n = ids.Count(); if( 0 < n ) { using( Transaction tx = new Transaction( doc ) ) { tx.Start( string.Format( "Delete {0} ReferencePlane{1}", n, Util.PluralSuffix( n ) ) ); // This also causes the exception "One or more of // the elementIds cannot be deleted. Parameter // name: elementIds // //ICollection<ElementId> ids2 = doc.Delete( // ids ); //nDeleted = ids2.Count(); List<ElementId> ids2 = new List<ElementId>( ids ); foreach( ElementId id in ids2 ) { try { ICollection<ElementId> ids3 = doc.Delete( id ); nDeleted += ids3.Count; } catch( Autodesk.Revit.Exceptions.ArgumentException ) { } } tx.Commit(); } } Util.InfoMsg( string.Format( "{0} unnamed reference plane{1} examined, " + "{2} element{3} in total were deleted.", n, Util.PluralSuffix( n ), nDeleted, Util.PluralSuffix( nDeleted ) ) ); return Result.Succeeded; }
/// <summary> /// Return the viewport on the given /// sheet displaying the given view. /// </summary> Element GetViewport( ViewSheet sheet, View view ) { Document doc = sheet.Document; // filter for view name: BuiltInParameter bip = BuiltInParameter.VIEW_NAME; ParameterValueProvider provider = new ParameterValueProvider( new ElementId( bip ) ); FilterStringRuleEvaluator evaluator = new FilterStringEquals(); FilterRule rule = new FilterStringRule( provider, evaluator, view.Name, true ); ElementParameterFilter name_filter = new ElementParameterFilter( rule ); BuiltInCategory bic = BuiltInCategory.OST_Viewports; // retrieve the specific named viewport: //Element viewport // = new FilteredElementCollector( doc ) // .OfCategory( bic ) // .WherePasses( name_filter ) // .FirstElement(); //return viewport; // unfortunately, there are not just one, // but two candidate elements. apparently, // we can distibuish them using the // owner view id property: List<Element> viewports = new List<Element>( new FilteredElementCollector( doc ) .OfCategory( bic ) .WherePasses( name_filter ) .ToElements() ); Debug.Assert( viewports[0].OwnerViewId.Equals( ElementId.InvalidElementId ), "expected the first viewport to have an invalid owner view id" ); Debug.Assert( !viewports[1].OwnerViewId.Equals( ElementId.InvalidElementId ), "expected the second viewport to have a valid owner view id" ); int i = 1; return viewports[i]; }
/// <summary> /// Return the first wall type with the given name. /// </summary> static WallType GetFirstWallTypeNamed( Document doc, string name) { // built-in parameter storing this // wall type's name: BuiltInParameter bip = BuiltInParameter.SYMBOL_NAME_PARAM; ParameterValueProvider provider = new ParameterValueProvider( new ElementId( bip ) ); FilterStringRuleEvaluator evaluator = new FilterStringEquals(); FilterRule rule = new FilterStringRule( provider, evaluator, name, false ); ElementParameterFilter filter = new ElementParameterFilter( rule ); FilteredElementCollector collector = new FilteredElementCollector( doc ) .OfClass( typeof( WallType ) ) .WherePasses( filter ); return collector.FirstElement() as WallType; }