public bool ApplyFilters(Document doc, View v, ElementId fillPatternId, bool colorLines, bool colorFill) { for (int i = 0; i < valuesList.Count; i++) { MyParameter mp = valuesList[i]; Parameter param = mp.RevitParameter; string filterName = _filterNamePrefix + catsName + " " + paramName; if (_criteriaType == CriteriaType.Equals) { filterName = filterName + " равно "; } else if (_criteriaType == CriteriaType.StartsWith) { filterName = filterName + " нач.с "; } filterName += mp.AsValueString(); ParameterFilterElement filter = FilterCreator.createSimpleFilter(doc, catsIds, filterName, mp, _criteriaType); if (filter == null) { continue; } ViewUtils.ApplyViewFilter(doc, v, filter, fillPatternId, i, colorLines, colorFill); } return(true); }
public FilterDataSimple(Document doc, List <Element> Elems, MyParameter MyParam, int StartSymbols, CriteriaType CritType) { paramName = MyParam.Name; catsIds = MyParam.FilterableCategoriesIds; elems = Elems; _criteriaType = CritType; if (CritType == CriteriaType.Equals) { startSymbols = 0; } else { startSymbols = StartSymbols; } }
/// <summary> /// Полный список доступных для фильтрации параметров у каждой категории /// </summary> /// <param name="doc"></param> /// <param name="elements"></param> /// <returns></returns> public static List <MyParameter> GetAllFilterableParameters(Document doc, List <Element> elements) { HashSet <ElementId> catsIds = GetElementsCategories(elements); Dictionary <ElementId, HashSet <ElementId> > paramsAndCats = new Dictionary <ElementId, HashSet <ElementId> >(); foreach (ElementId catId in catsIds) { List <ElementId> curCatIds = new List <ElementId> { catId }; List <ElementId> paramsIds = ParameterFilterUtilities.GetFilterableParametersInCommon(doc, curCatIds).ToList(); foreach (ElementId paramId in paramsIds) { if (paramsAndCats.ContainsKey(paramId)) { paramsAndCats[paramId].Add(catId); } else { paramsAndCats.Add(paramId, new HashSet <ElementId> { catId }); } } } List <MyParameter> mparams = new List <MyParameter>(); foreach (KeyValuePair <ElementId, HashSet <ElementId> > kvp in paramsAndCats) { ElementId paramId = kvp.Key; string paramName = GetParamName(doc, paramId); MyParameter mp = new MyParameter(paramId, paramName, kvp.Value.ToList()); mparams.Add(mp); } mparams = mparams.OrderBy(i => i.Name).ToList(); return(mparams); }
private void buttonNext_Click(object sender, EventArgs e) { if (radioButtonCheckHostMark.Checked) { this.colorizeMode = ColorizeMode.CheckHostmark; } else if (radioButtonResetColors.Checked) { this.colorizeMode = ColorizeMode.ResetColors; } else if (radioButtonUserParameter.Checked) { this.colorizeMode = ColorizeMode.ByParameter; selectedParameter = comboBoxParameters.SelectedItem as MyParameter; if (selectedParameter == null) { throw new Exception("Выбран не MyParameter"); } if (radioButtonEquals.Checked) { criteriaType = CriteriaType.Equals; } if (radioButtonStartsWith.Checked) { criteriaType = CriteriaType.StartsWith; } startSymbols = (int)numericStartSymbols.Value; } this.colorLines = checkBoxColorLines.Checked; this.colorFill = checkBoxColorFill.Checked; this.DialogResult = DialogResult.OK; this.Close(); }
public static List <MyParameter> GetParameterValues(Document doc, List <Element> elems, string ParamName, int startSymbols) { bool isTypeParam = false; if (ParamName == "Имя типа" || ParamName == "Имя типа") { isTypeParam = true; } HashSet <MyParameter> values = new HashSet <MyParameter>(); //список значений параметра foreach (Element elem in elems) { Parameter curParam = elem.LookupParameter(ParamName); if (curParam == null) { ElementId typeElemId = elem.GetTypeId(); if (typeElemId == null) { continue; } if (typeElemId == ElementId.InvalidElementId) { continue; } Element typeElem = doc.GetElement(typeElemId); curParam = typeElem.LookupParameter(ParamName); if (curParam == null) { continue; } } MyParameter mp = new MyParameter(curParam); if (!mp.HasValue && !isTypeParam) { continue; } if (isTypeParam) { Parameter typeParam = elem.get_Parameter(BuiltInParameter.ELEM_TYPE_PARAM); if (!typeParam.HasValue) { continue; } string typeName = typeParam.AsValueString(); mp.Set(typeName); } if (startSymbols > 0) { if (mp.RevitStorageType != StorageType.String) { throw new Exception("Критерий \"Начинается с\" доступен только для текстовых параметров"); } string valTemp = mp.AsString(); string val = ""; if (valTemp.Length < startSymbols) { val = valTemp; } else { val = valTemp.Substring(0, startSymbols); } mp.Set(val); } values.Add(mp); } List <MyParameter> listParams = values.ToList(); listParams.Sort(); return(listParams); }
public static ParameterFilterElement createSimpleFilter(Document doc, List <ElementId> catsIds, string filterName, MyParameter mp, CriteriaType ctype) { List <ParameterFilterElement> filters = new FilteredElementCollector(doc) .OfClass(typeof(ParameterFilterElement)) .Cast <ParameterFilterElement>() .ToList(); FilterRule rule = null; List <ParameterFilterElement> checkFilters = filters.Where(f => f.Name == filterName).ToList(); ParameterFilterElement filter = null; if (checkFilters.Count != 0) { filter = checkFilters[0]; } else { rule = FilterCreator.CreateRule(mp, ctype); if (rule == null) { return(null); } List <FilterRule> filterRules = new List <FilterRule> { rule }; try { filter = ParameterFilterElement.Create(doc, filterName, catsIds); #if R2017 || R2018 filter.SetRules(filterRules); #else filter.SetElementFilter(new ElementParameterFilter(filterRules)); #endif } catch { } } return(filter); }
public static FilterRule CreateRule(MyParameter mp, CriteriaType ctype) { Parameter param = mp.RevitParameter; FilterRule rule = null; if (ctype == CriteriaType.Equals) { switch (param.StorageType) { case StorageType.None: break; case StorageType.Integer: rule = ParameterFilterRuleFactory.CreateEqualsRule(param.Id, mp.AsInteger()); break; case StorageType.Double: rule = ParameterFilterRuleFactory.CreateEqualsRule(param.Id, mp.AsDouble(), 0.0001); break; case StorageType.String: string val = mp.AsString(); if (val == null) { break; } rule = ParameterFilterRuleFactory.CreateEqualsRule(param.Id, val, true); break; case StorageType.ElementId: rule = ParameterFilterRuleFactory.CreateEqualsRule(param.Id, mp.AsElementId()); break; default: break; } } if (ctype == CriteriaType.StartsWith) { switch (param.StorageType) { case StorageType.None: break; case StorageType.String: string val = mp.AsString(); if (val == null) { break; } rule = ParameterFilterRuleFactory.CreateBeginsWithRule(param.Id, val, true); break; default: break; } } if (rule == null) { throw new Exception("Не удалось создать правило фильтра"); } return(rule); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Debug.Listeners.Clear(); Debug.Listeners.Add(new RbsLogger.Logger("WallHatch")); Document doc = commandData.Application.ActiveUIDocument.Document; View curView = doc.ActiveView; if (!(curView is ViewPlan)) { message = "Запуск команды возможен только на плане"; Debug.WriteLine(message); return(Result.Failed); } if (curView.ViewTemplateId != null && curView.ViewTemplateId != ElementId.InvalidElementId) { message = "Для вида применен шаблон. Отключите шаблон вида перед запуском"; Debug.WriteLine(message); return(Result.Failed); } Selection sel = commandData.Application.ActiveUIDocument.Selection; Debug.WriteLine("Selected elements: " + sel.GetElementIds().Count); if (sel.GetElementIds().Count == 0) { message = "Не выбраны стены."; return(Result.Failed); } List <Wall> walls = new List <Wall>(); foreach (ElementId id in sel.GetElementIds()) { Wall w = doc.GetElement(id) as Wall; if (w == null) { continue; } walls.Add(w); } Debug.WriteLine("Walls count: " + walls.Count); if (walls.Count == 0) { message = "Не выбраны стены."; return(Result.Failed); } SortedDictionary <double, List <Wall> > wallHeigthDict = new SortedDictionary <double, List <Wall> >(); if (wallHeigthDict.Count > 10) { message = "Слишком много типов стен! Должно быть не более 10"; Debug.WriteLine(message); return(Result.Failed); } foreach (Wall w in walls) { Debug.WriteLine("Current wall id:" + w.Id.IntegerValue); double topElev = GetWallTopElev(doc, w, true); Debug.WriteLine("Top elevation: " + topElev.ToString("F1")); if (wallHeigthDict.ContainsKey(topElev)) { wallHeigthDict[topElev].Add(w); } else { wallHeigthDict.Add(topElev, new List <Wall> { w }); } } List <ElementId> catsIds = new List <ElementId> { new ElementId(BuiltInCategory.OST_Walls) }; int i = 1; using (Transaction t = new Transaction(doc)) { t.Start("Отметки стен"); foreach (ElementId filterId in curView.GetFilters()) { ParameterFilterElement filter = doc.GetElement(filterId) as ParameterFilterElement; if (filter.Name.StartsWith("_cwh_")) { curView.RemoveFilter(filterId); } } Debug.WriteLine("Old filters deleted"); foreach (var kvp in wallHeigthDict) { Debug.WriteLine("Current key: " + kvp.Key.ToString("F1")); ElementId hatchId = GetHatchIdByNumber(doc, i); ImageType image = GetImageTypeByNumber(doc, i); double curHeigthMm = kvp.Key; double curHeigthFt = curHeigthMm / 304.8; List <Wall> curWalls = kvp.Value; foreach (Wall w in curWalls) { w.get_Parameter(BuiltInParameter.ALL_MODEL_IMAGE).Set(image.Id); w.LookupParameter("Рзм.ОтметкаВерха").Set(curHeigthFt); double bottomElev = GetWallTopElev(doc, w, false); double bottomElevFt = bottomElev / 304.8; w.LookupParameter("Рзм.ОтметкаНиза").Set(bottomElevFt); } string filterName = "_cwh_" + "Стены Рзм.ОтметкаВерха равно " + curHeigthMm.ToString("F0"); MyParameter mp = new MyParameter(curWalls.First().LookupParameter("Рзм.ОтметкаВерха")); ParameterFilterElement filter = FilterCreator.createSimpleFilter(doc, catsIds, filterName, mp, CriteriaType.Equals); curView.AddFilter(filter.Id); OverrideGraphicSettings ogs = new OverrideGraphicSettings(); #if R2017 || R2018 ogs.SetProjectionFillPatternId(hatchId); ogs.SetCutFillPatternId(hatchId); #else ogs.SetSurfaceForegroundPatternId(hatchId); ogs.SetCutForegroundPatternId(hatchId); #endif curView.SetFilterOverrides(filter.Id, ogs); i++; } t.Commit(); } return(Result.Succeeded); }