public static ElementParameterFilter ParameterValueFilter(string valueQualifier, BuiltInParameter parameterName) { BuiltInParameter testParam = parameterName; ParameterValueProvider pvp = new ParameterValueProvider(new ElementId((int)testParam)); FilterStringRuleEvaluator str = new FilterStringContains(); FilterStringRule paramFr = new FilterStringRule(pvp, str, valueQualifier, false); ElementParameterFilter epf = new ElementParameterFilter(paramFr); return(epf); }
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 ); }
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 }
private void btnPreview_Click(object sender, EventArgs e) { //Use a Try block to keep any errors from crashing Revit try { //Get the parameter value of any element passed to be used in the Filtered Element Collector ParameterValueProvider pvp; //Based on the Radio buttons for Name or Number to determine which parameter to use if (rdoSheetNumber.Checked) { //Set the parameter to the ElementId of BuiltInParameter for the Sheet Number pvp = new ParameterValueProvider(new ElementId(BuiltInParameter.SHEET_NUMBER)); } else { //Set the parameter to the ElementId of BuiltInParameter for the Sheet Name pvp = new ParameterValueProvider(new ElementId(BuiltInParameter.SHEET_NAME)); } //Set how to compare the Sheet Name or Number. This will check to see if it Contains the value passed FilterStringRuleEvaluator fsr = new FilterStringContains(); //Set the value from the "Find" text box. The "true" at the end is for case sensativity FilterRule fRule = new FilterStringRule(pvp, fsr, txtFind.Text, true); //Create a filter based on the Filter String Rule and the Filter rule to use int he Filtered Element Collector ElementParameterFilter filter = new ElementParameterFilter(fRule); //Create a new DataTable to store the sheet information gathered from the Filtered Element Collector DataTable dt = new DataTable(); //Add a new columns to the Data Table with Name and the type of Column dt.Columns.Add(new DataColumn("Sheet Number", typeof(string))); dt.Columns.Add(new DataColumn("Sheet Name", typeof(string))); dt.Columns.Add(new DataColumn("Preview", typeof(string))); dt.Columns.Add(new DataColumn("Sheet Id", typeof(ElementId))); //The Filtered Element Collector will get all Sheets in the model that contains the "Find" value based on the Prameter Value Provider above using (FilteredElementCollector fec = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Sheets).WherePasses(filter)) { //Loop through each sheet that is returned from the Collector foreach (ViewSheet sheet in fec.ToElements()) { //Based on the Radio buttons for Name or Number to determine which parameter to replace the values for the Preview if (rdoSheetNumber.Checked) { //Create a new row in the Data Table and add the sheet information to it when replacing the Sheet Number dt.Rows.Add(sheet.SheetNumber, sheet.Name, sheet.SheetNumber.Replace(txtFind.Text, txtReplace.Text), sheet.Id); } else { //Create a new row in the Data Table and add the sheet information to it when replacing the Sheet Name dt.Rows.Add(sheet.SheetNumber, sheet.Name, sheet.Name.Replace(txtFind.Text, txtReplace.Text), sheet.Id); } } } //Check tome sure there is at least one Sheet (row) in the DataTable if (dt.Rows.Count > 0) { //Enable the Replace button btnReplace.Enabled = true; //Use the Data Table to set the Data Source of the Data Grid View to display the sheet information dgvSheets.DataSource = dt; //Set the Sheet Name column to fill the extra space in the Data Grid View dgvSheets.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } //Display a message that no Sheets were found based on the critera and set the Data Source to null for the Data Grid View else { TaskDialog.Show("Preview", "No Sheets match the search criteria."); dgvSheets.DataSource = null; //Disable the Replace button btnReplace.Enabled = false; } } //Catch any errors and display a Dialog with the informaiton catch (Exception ex) { TaskDialog.Show("Error", ex.ToString() + " : " + ex.InnerException); } }
public static ElementFilter createParameterFilter(Document doc, ParameterData parameter, string operation, string ruleString) { ElementId parameterId = parameter.Id; ParameterValueProvider fvp = new ParameterValueProvider(parameterId); StorageType storageType = parameter.StorageType; FilterRule fRule = null; FilterInverseRule fInvRule = null; ElementParameterFilter filter = null; switch (storageType) { case StorageType.String: case StorageType.Integer: FilterStringRuleEvaluator fsre = null; switch (operation) { case "равно": fsre = new FilterStringEquals(); fRule = new FilterStringRule(fvp, fsre, ruleString, true); filter = new ElementParameterFilter(fRule); break; case "не равно": fsre = new FilterStringEquals(); fRule = new FilterStringRule(fvp, fsre, ruleString, true); fInvRule = new FilterInverseRule(fRule); filter = new ElementParameterFilter(fInvRule); break; case "содержит": fsre = new FilterStringContains(); fRule = new FilterStringRule(fvp, fsre, ruleString, true); filter = new ElementParameterFilter(fRule); break; case "не содержит": fsre = new FilterStringContains(); fRule = new FilterStringRule(fvp, fsre, ruleString, true); fInvRule = new FilterInverseRule(fRule); filter = new ElementParameterFilter(fInvRule); break; case "начинается с": fsre = new FilterStringBeginsWith(); fRule = new FilterStringRule(fvp, fsre, ruleString, true); filter = new ElementParameterFilter(fRule); break; case "не начинается с": fsre = new FilterStringBeginsWith(); fRule = new FilterStringRule(fvp, fsre, ruleString, true); fInvRule = new FilterInverseRule(fRule); filter = new ElementParameterFilter(fInvRule); break; case "заканчивается на": fsre = new FilterStringEndsWith(); fRule = new FilterStringRule(fvp, fsre, ruleString, true); filter = new ElementParameterFilter(fRule); break; case "не заканчивается на": fsre = new FilterStringEndsWith(); fRule = new FilterStringRule(fvp, fsre, ruleString, true); fInvRule = new FilterInverseRule(fRule); filter = new ElementParameterFilter(fInvRule); break; } break; case StorageType.Double: FilterNumericRuleEvaluator fnre = null; double ruleValue = Convert.ToDouble(ruleString); switch (operation) { case "равно": fnre = new FilterNumericEquals(); fRule = new FilterDoubleRule(fvp, fnre, ruleValue, 0.0); filter = new ElementParameterFilter(fRule); break; case "не равно": fnre = new FilterNumericEquals(); fRule = new FilterDoubleRule(fvp, fnre, ruleValue, 0.0); fInvRule = new FilterInverseRule(fRule); filter = new ElementParameterFilter(fInvRule); break; case "больше": fnre = new FilterNumericGreater(); fRule = new FilterDoubleRule(fvp, fnre, ruleValue, 0.0); filter = new ElementParameterFilter(fRule); break; case "больше или равно": fnre = new FilterNumericGreaterOrEqual(); fRule = new FilterDoubleRule(fvp, fnre, ruleValue, 0.0); filter = new ElementParameterFilter(fRule); break; case "меньше": fnre = new FilterNumericLess(); fRule = new FilterDoubleRule(fvp, fnre, ruleValue, 0.0); filter = new ElementParameterFilter(fRule); break; case "меньше или равно": fnre = new FilterNumericLessOrEqual(); fRule = new FilterDoubleRule(fvp, fnre, ruleValue, 0.0); filter = new ElementParameterFilter(fRule); break; } break; case StorageType.ElementId: var levels = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Levels).ToElements(); var level = levels.Where(i => i.Name == ruleString).FirstOrDefault(); ElementId ruleId = level.Id; fnre = null; switch (operation) { case "равно": fnre = new FilterNumericEquals(); fRule = new FilterElementIdRule(fvp, fnre, ruleId); filter = new ElementParameterFilter(fRule); break; case "не равно": fnre = new FilterNumericEquals(); fRule = new FilterElementIdRule(fvp, fnre, ruleId); fInvRule = new FilterInverseRule(fRule); filter = new ElementParameterFilter(fInvRule); break; case "выше": fnre = new FilterNumericGreater(); fRule = new FilterElementIdRule(fvp, fnre, ruleId); filter = new ElementParameterFilter(fRule); break; case "ровно или выше": fnre = new FilterNumericGreaterOrEqual(); fRule = new FilterElementIdRule(fvp, fnre, ruleId); filter = new ElementParameterFilter(fRule); break; case "ниже": fnre = new FilterNumericLess(); fRule = new FilterElementIdRule(fvp, fnre, ruleId); filter = new ElementParameterFilter(fRule); break; case "ровно или ниже": fnre = new FilterNumericLessOrEqual(); fRule = new FilterElementIdRule(fvp, fnre, ruleId); filter = new ElementParameterFilter(fRule); break; } break; } return(filter); }
private void BtnPreview_Click(object sender, RoutedEventArgs e) { //Use a Try block to keep any errors from crashing Revit try { //Clear the data in the Data Table for each search ViewTable.Clear(); //Get the parameter value of any element passed to be used in the Filtered Element Collector ParameterValueProvider pvp; //Based on the Radio buttons for Name or Number to determine which parameter to use if (rdoViewName.IsChecked == true) { //Set the parameter to the ElementId of BuiltInParameter for the View Name pvp = new ParameterValueProvider(new ElementId(BuiltInParameter.VIEW_NAME)); } else { //Title On Sheet does not have a Built in Paramter enumeration, so we have to get a single view and retrive the paramter //Use a Filtered Collector to get the first view that is not a template of Floor Plan Type View tempView = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Views).Cast <View>().Where(v => v.IsTemplate == false && v.ViewType == ViewType.FloorPlan).First(); //Get the paramter associated with the Title On Sheet Parameter param = tempView.LookupParameter("Title on Sheet"); //Set the parameter to the ElementId of BuiltInParameter for the Title On Sheet pvp = new ParameterValueProvider(param.Id); } //Set how to compare the View Name or Title. This will check to see if it Contains the value passed FilterStringRuleEvaluator fsr = new FilterStringContains(); //Set the value from the "Find" text box. The "true" at the end is for case sensativity FilterRule fRule = new FilterStringRule(pvp, fsr, txtFind.Text, true); //Create a filter based on the Filter String Rule and the Filter rule to use int he Filtered Element Collector ElementParameterFilter filter = new ElementParameterFilter(fRule); //Check to see if the Data Table already has columns so we don't need to add them again. if (ViewTable.Columns.Count == 0) { //Add a new columns to the Data Table with Name and the type of Column ViewTable.Columns.Add(new DataColumn("ViewId", typeof(ElementId))); ViewTable.Columns.Add(new DataColumn("ViewName", typeof(string))); ViewTable.Columns.Add(new DataColumn("TitleOnSheet", typeof(string))); ViewTable.Columns.Add(new DataColumn("Preview", typeof(string))); } //The Filtered Element Collector will get all Views in the model that contains the "Find" value based on the Prameter Value Provider above using (FilteredElementCollector fec = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Views).WherePasses(filter)) { //Loop through each sheet that is returned from the Collector foreach (View view in fec.ToElements()) { Parameter viewTitle = view.LookupParameter("Title on Sheet"); //Based on the Radio buttons for Name or Number to determine which parameter to replace the values for the Preview if (rdoViewName.IsChecked == true) { //Create a new row in the Data Table and add the sheet information to it when replacing the View Name ViewTable.Rows.Add(view.Id, view.Name, viewTitle.AsString(), view.Name.Replace(txtFind.Text, txtReplace.Text)); } else { //Create a new row in the Data Table and add the sheet information to it when replacing the VIew Title On Sheet ViewTable.Rows.Add(view.Id, view.Name, viewTitle.AsString(), viewTitle.AsString().Replace(txtFind.Text, txtReplace.Text)); } } } //Check to make sure there is at least one View (row) in the DataTable if (ViewTable.Rows.Count > 0) { //Enable the Replace button btnReplace.IsEnabled = true; //Use the Data Table to set the Data Source of the Data Grid View to display the sheet information DataGridViews.ItemsSource = ViewTable.DefaultView; } //If no Views were found based on the critera them set the Data Source to null for the Data Grid View else { //Clear the data from the Data Grid DataGridViews.ItemsSource = null; //Disable the Replace button btnReplace.IsEnabled = false; } } //Catch any errors and display a Dialog with the informaiton catch (Exception ex) { TaskDialog.Show("Error", ex.ToString() + " : " + ex.InnerException); } }
private Dictionary <string, GraphSystem> ServiceTypeSystem(Document Doc) { Dictionary <string, GraphSystem> ServiceTypes = new Dictionary <string, GraphSystem>(); //get all cable tray element in de model FilteredElementCollector Collector = new FilteredElementCollector(doc); Collector = GetConnectorElements(doc, false); //filter service type //https://thebuildingcoder.typepad.com/blog/2010/06/parameter-filter.html#7 BuiltInParameter testParam = BuiltInParameter.RBS_CTC_SERVICE_TYPE; List <string> serviceTypeNames = new List <string>(); foreach (Element elem in Collector) { Parameter param = elem.get_Parameter(testParam); string paremeterValue = param.AsString(); if (paremeterValue != null) { if (!serviceTypeNames.Contains(paremeterValue)) { serviceTypeNames.Add(paremeterValue); } } } foreach (string key in serviceTypeNames) { //create Filter servicetype cable tray //https://thebuildingcoder.typepad.com/blog/2010/06/parameter-filter.html#7 ParameterValueProvider pvp = new ParameterValueProvider(new ElementId((int)testParam)); FilterStringRuleEvaluator fnrvStr = new FilterStringContains(); FilterStringRule paramFr = new FilterStringRule(pvp, fnrvStr, key, false); ElementParameterFilter epf = new ElementParameterFilter(paramFr); //Filter servicetype cable tray FilteredElementCollector CollectorKey = new FilteredElementCollector(doc); CollectorKey = GetConnectorElements(doc, false); CollectorKey.WherePasses(epf); //create graph to cable tray Graph connectorsSistem1 = new Graph(); connectorsSistem1.AddConnectorSetFromFilteredElementCollector(CollectorKey); //create floydWarshall to all cable tray FloydWarshall floydWarshall1 = new FloydWarshall(ref connectorsSistem1); floydWarshall1.PlayFloydWarshall(); //Add service type system GraphSystem graphSystem1 = new GraphSystem(connectorsSistem1, floydWarshall1); ServiceTypes.Add(key, graphSystem1); } //create graph to all cable tray Graph connectorsSistem = new Graph(); connectorsSistem = new Graph(); connectorsSistem.AddConnectorSetFromFilteredElementCollector(Collector); //create floydWarshall to all cable tray FloydWarshall floydWarshall; floydWarshall = new FloydWarshall(ref connectorsSistem); floydWarshall.PlayFloydWarshall(); //Add service type system GraphSystem graphSystem = new GraphSystem(connectorsSistem, floydWarshall); ServiceTypes.Add("None", graphSystem); return(ServiceTypes); }
public void Execute(UpdaterData data) { if (!Paused) { Document doc = data.GetDocument(); List <ElementId> list = data.GetAddedElementIds().ToList(); list.AddRange(data.GetModifiedElementIds()); IList <Element> list2 = (from ElementId id in list select doc.GetElement(id)).ToList(); Definition parameterDefinition = LODapp.GetParameterDefinition(doc, "Zone"); ElementId val = LODapp.GetLODparameter(doc, parameterDefinition).get_Id(); ParameterValueProvider val2 = new ParameterValueProvider(val); FilterStringRuleEvaluator val3 = new FilterStringContains(); FilterStringRuleEvaluator val4 = new FilterStringEquals(); FilterStringRuleEvaluator val5 = new FilterStringBeginsWith(); foreach (Element item in list2) { string text = item.LookupParameter("Name").AsString(); if (!string.IsNullOrWhiteSpace(text)) { FilterRule[] array = (FilterRule[])new FilterRule[3] { new FilterStringRule(val2, val4, text, true), new FilterStringRule(val2, val5, text + ", ", true), new FilterStringRule(val2, val3, ", " + text, true) }; ElementParameterFilter val6 = new ElementParameterFilter((IList <FilterRule>)array); IList <Element> list3 = new FilteredElementCollector(doc).WhereElementIsNotElementType().WherePasses(val6).ToElements(); BoundingBoxIntersectsFilter val7 = new BoundingBoxIntersectsFilter(ToOutline(item.get_BoundingBox(null))); IList <Element> list4 = new FilteredElementCollector(doc).WhereElementIsNotElementType().WherePasses(val7).ToElements(); IEnumerable <Element> enumerable = list3.Except(list4, new EqualUniqueId()); IEnumerable <Element> enumerable2 = list4.Except(list3, new EqualUniqueId()); foreach (Element item2 in enumerable) { Parameter val8 = item2.get_Parameter(parameterDefinition); if (val8 != null) { string text2 = val8.AsString() ?? string.Empty; string text3; if (text2.Length > text.Length) { int num = text2.IndexOf(text); text3 = ((num < 2 || text2[num - 2] != ',') ? text2.Remove(num, text.Length + 2) : text2.Remove(num - 2, text.Length + 2)); } else { text3 = string.Empty; } val8.Set(text3); } } foreach (Element item3 in enumerable2) { Parameter val9 = item3.get_Parameter(parameterDefinition); string text4 = (((int)val9 != 0) ? val9.AsString() : null) ?? string.Empty; string text5 = (text4.Length <= 0) ? text : (text4 + ", " + text); Parameter val10 = item3.get_Parameter(parameterDefinition); if ((int)val10 != 0) { val10.Set(text5); } } } } } }