Example #1
0
        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 bool ApplyFilters(Document doc, View v, ElementId fillPatternId, bool colorLines, bool colorFill)
        {
            Debug.WriteLine("Start apply rebar filters for view: " + v.Name);
            for (int i = 0; i < values.Count; i++)
            {
                string val = values[i];
                Debug.WriteLine("Value: " + val);

                ParameterFilterElement filterConstr = FilterCreator.CreateConstrFilter(doc, catIdConstructions, markParam, val, _filterNamePrefix);
                ViewUtils.ApplyViewFilter(doc, v, filterConstr, fillPatternId, i, colorLines, colorFill);

                if (!_rebarIsFamilyParamExists)
                {
                    ParameterFilterElement filterRebarSingleMode = FilterCreator
                                                                   .CreateRebarHostFilter(doc, catIdRebar, rebarIsFamilyParam, rebarHostParam, rebarMrkParam, val, _filterNamePrefix, RebarFilterMode.SingleMode);
                    ViewUtils.ApplyViewFilter(doc, v, filterRebarSingleMode, fillPatternId, i, colorLines, colorFill);
                    continue;
                }

#if R2017 || R2018
                ParameterFilterElement filterRebarStandardRebar = FilterCreator
                                                                  .CreateRebarHostFilter(doc, catIdRebar, rebarIsFamilyParam, rebarHostParam, rebarMrkParam, val, _filterNamePrefix, RebarFilterMode.StandardRebarMode);
                ViewUtils.ApplyViewFilter(doc, v, filterRebarStandardRebar, fillPatternId, i, colorLines, colorFill);
                Debug.WriteLine("Filter created and applied to view: " + filterRebarStandardRebar.Name);

                ParameterFilterElement filterRebarIfcRebar = FilterCreator
                                                             .CreateRebarHostFilter(doc, new List <ElementId> {
                    new ElementId(BuiltInCategory.OST_Rebar)
                }, rebarIsFamilyParam, rebarHostParam, rebarMrkParam, val, _filterNamePrefix, RebarFilterMode.IfcMode);
                ViewUtils.ApplyViewFilter(doc, v, filterRebarIfcRebar, fillPatternId, i, colorLines, colorFill);
                Debug.WriteLine("Filter created and applied to view: " + filterRebarIfcRebar.Name);
#else
                ParameterFilterElement filterRebarOrStyle = FilterCreator
                                                            .CreateRebarHostFilter(doc, catIdRebar, rebarIsFamilyParam, rebarHostParam, rebarMrkParam, val, _filterNamePrefix, RebarFilterMode.DoubleMode);
                ViewUtils.ApplyViewFilter(doc, v, filterRebarOrStyle, fillPatternId, i, colorLines, colorFill);
                Debug.WriteLine("Filter created and applied to view: " + filterRebarOrStyle.Name);
#endif
            }
            Debug.WriteLine("All filters applied");
            return(true);
        }
Example #3
0
        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);
        }
Example #4
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Document doc = commandData.Application.ActiveUIDocument.Document;

            AppBatchFilterCreation.assemblyPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
            string dllPath = Path.GetDirectoryName(AppBatchFilterCreation.assemblyPath);

            OpenFileDialog openCsvDialog = new OpenFileDialog();

            openCsvDialog.Filter           = "CSV file|*.csv";
            openCsvDialog.Title            = "Выберите файл CSV (v2018.10.17)";
            openCsvDialog.Multiselect      = false;
            openCsvDialog.InitialDirectory = dllPath;

            if (openCsvDialog.ShowDialog() != DialogResult.OK)
            {
                return(Result.Cancelled);
            }
            ;

            //считываю файл
            string          path = openCsvDialog.FileName;
            List <string[]> data = ReadDataFromCSV.Read(path);

            string msg         = "";
            int    filterCount = 0;

            //одна строка в файле - один фильтр
            foreach (string[] line in data)
            {
                FilterSourceInfo filterSource = new FilterSourceInfo(line);
                string           filterName   = filterSource.FilterName;

                //Добавляю категории
                List <ElementId> catIds = new List <ElementId>();
                foreach (string stringCat in filterSource.Categories)
                {
                    BuiltInCategory cat = GetBuiltinCategory.GetCategoryByRussianName(stringCat);
                    catIds.Add(new ElementId(cat));
                }


                //добавляю критерии фильтрации
                List <FilterRule> filterRules = new List <FilterRule>();

                foreach (string[] sourceRule in filterSource.SourceRules)
                {
                    string paramName = sourceRule[0];
                    string function  = sourceRule[1];
                    string value     = sourceRule[2];


                    BuiltInCategory cat = GetBuiltinCategory.GetCategoryByRussianName(filterSource.Categories[0]);
                    if (cat == BuiltInCategory.OST_Sections || cat == BuiltInCategory.OST_Elev || cat == BuiltInCategory.OST_Callouts)
                    {
                        cat = BuiltInCategory.OST_Views;
                    }

                    FilteredElementCollector collector = new FilteredElementCollector(doc).OfCategory(cat);

                    Parameter param = null;
                    try
                    {
                        foreach (Element elem in collector)
                        {
                            param = elem.LookupParameter(paramName);
                            if (param == null)
                            {
                                continue;
                            }
                            break;
                        }
                    }
                    catch { }

                    if (collector.Count() == 0 || param == null)
                    {
                        message  = "Ошибка при создании фильтра: " + filterName;
                        message += "\nУстановите как минимум один элемент в категории: " + filterSource.Categories[0];
                        message += "\nТребуемый параметр: " + paramName;
                        return(Result.Failed);
                    }

                    FilterRule rule = FilterCreator.CreateRule2(param, function, value);
                    filterRules.Add(rule);
                }

                try
                {
                    using (Transaction t = new Transaction(doc))
                    {
                        t.Start("Создание фильтра" + filterName);
                        ParameterFilterElement filter = ParameterFilterElement.Create(doc, filterName, catIds);
#if R2017 || R2018
                        filter.SetRules(filterRules);
#else
                        ElementParameterFilter epf = new ElementParameterFilter(filterRules);
                        filter.SetElementFilter(epf);
#endif
                        filterCount++;
                        t.Commit();
                    }
                }
                catch
                {
                    msg += filterName + "\n";
                }
            }
            string finalMessage = "Создано фильтров: " + filterCount.ToString() + "\n";
            if (msg.Length != 0)
            {
                finalMessage += "Не удалось создать: \n" + msg;
            }

            TaskDialog.Show("Batch filter create", finalMessage);
            return(Result.Succeeded);
        }
Example #5
0
        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);
        }