private bool CreateFiltersIfMissing(Document doc) { if (curLODfilter != null && tarLODfilter != null) { return(false); } ElementId val = LODapp.GetLODparameter(doc, "Current_LOD").get_Id(); ElementId val2 = LODapp.GetLODparameter(doc, "Target_LOD").get_Id(); ParameterValueProvider val3 = new ParameterValueProvider(val); ParameterValueProvider val4 = new ParameterValueProvider(val2); FilterNumericRuleEvaluator val5 = new FilterNumericEquals(); ElementParameterFilter[] array = (ElementParameterFilter[])new ElementParameterFilter[VALID_CURRENT_LOD_VALUES.Length]; for (int i = 0; i < VALID_CURRENT_LOD_VALUES.Length; i++) { FilterIntegerRule val6 = new FilterIntegerRule(val3, val5, VALID_CURRENT_LOD_VALUES[i]); array[i] = new ElementParameterFilter(val6, true); } curLODfilter = new LogicalAndFilter((IList <ElementFilter>)array); ElementParameterFilter[] array2 = (ElementParameterFilter[])new ElementParameterFilter[VALID_TARGET_LOD_VALUES.Length]; for (int j = 0; j < VALID_TARGET_LOD_VALUES.Length; j++) { FilterIntegerRule val7 = new FilterIntegerRule(val4, val5, VALID_TARGET_LOD_VALUES[j]); array2[j] = new ElementParameterFilter(val7, true); } tarLODfilter = new LogicalAndFilter((IList <ElementFilter>)array2); return(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 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); } } } } } }