Пример #1
0
        public MyDialogResult CollectValues(Document doc, View v)
        {
            MyDialogResult result = new MyDialogResult(ResultType.ok, "");

            if (catsIds.Count > 1)
            {
                List <MyCategory> mycats = new List <MyCategory>();
                foreach (ElementId catid in catsIds)
                {
                    mycats.Add(new MyCategory(doc, catid));
                }
                FormSelectCategories formSelCats = new FormSelectCategories(doc, mycats);
                if (formSelCats.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    result.ResultType = ResultType.cancel;
                    return(result);
                }

                catsIds = formSelCats.checkedCategoriesIds;

                //перефильтрую элементы после того как перевыбрал категории
                elems = elems.Where(e => catsIds.Contains(e.Category.Id)).ToList();
            }

            catsName = ViewUtils.GetCategoriesName(doc, catsIds);

            valuesList = DocumentGetter.GetParameterValues(doc, elems, paramName, startSymbols);

            return(result);
        }
Пример #2
0
        public static ParameterFilterElement CreateConstrFilter(Document doc, List <ElementId> catsIds, Parameter markParam, string mark, string filterNamePrefix)
        {
            string filterName = filterNamePrefix + "_Конструкция " + mark;

            ParameterFilterElement filter = DocumentGetter.GetFilterByName(doc, filterName);

            if (filter != null)
            {
                return(filter);
            }

            FilterRule markEquals = ParameterFilterRuleFactory.CreateEqualsRule(markParam.Id, mark, true);

#if R2017 || R2018
            filter = ParameterFilterElement.Create(doc, filterName, catsIds);
            filter.SetRules(new List <FilterRule> {
                markEquals
            });
#else
            ElementParameterFilter epf = new ElementParameterFilter(markEquals);
            filter = ParameterFilterElement.Create(doc, filterName, catsIds, epf);
#endif
            return(filter);
        }
Пример #3
0
        public static ParameterFilterElement CreateRebarHostFilter(
            Document doc, List <ElementId> rebarCatsIds, Parameter rebarIsFamilyParam, Parameter rebarHostParam, Parameter rebarMrkParam,
            string hostMark, string filterNamePrefix, RebarFilterMode filterMode)
        {
            string filterName = filterNamePrefix + "_Арм Конструкции " + hostMark;

            if (filterMode == RebarFilterMode.IfcMode)
            {
                filterName += " IFC";
            }
            ParameterFilterElement filter = DocumentGetter.GetFilterByName(doc, filterName);

            if (filter != null)
            {
                return(filter);
            }

            FilterRule ruleHostEquals = ParameterFilterRuleFactory.CreateEqualsRule(rebarHostParam.Id, hostMark, true);

            if (filterMode == RebarFilterMode.SingleMode)
            {
#if R2017 || R2018
                filter = ParameterFilterElement.Create(doc, filterName, rebarCatsIds);
                filter.SetRules(new List <FilterRule> {
                    ruleHostEquals
                });
#else
                ElementParameterFilter epf = new ElementParameterFilter(ruleHostEquals);
                filter = ParameterFilterElement.Create(doc, filterName, rebarCatsIds, epf);
#endif
                return(filter);
            }

            FilterRule ruleIsNotFamily = ParameterFilterRuleFactory.CreateEqualsRule(rebarIsFamilyParam.Id, 0);
            FilterRule ruleIsFamily    = ParameterFilterRuleFactory.CreateEqualsRule(rebarIsFamilyParam.Id, 1);
            FilterRule ruleMrkEquals   = ParameterFilterRuleFactory.CreateEqualsRule(rebarMrkParam.Id, hostMark, true);


#if R2017 || R2018
            if (filterMode == RebarFilterMode.StandardRebarMode)
            {
                filter = ParameterFilterElement.Create(doc, filterName, rebarCatsIds);
                filter.SetRules(new List <FilterRule> {
                    ruleIsNotFamily, ruleHostEquals
                });
                return(filter);
            }
            else if (filterMode == RebarFilterMode.IfcMode)
            {
                filter = ParameterFilterElement.Create(doc, filterName, rebarCatsIds);
                filter.SetRules(new List <FilterRule> {
                    ruleIsFamily, ruleMrkEquals
                });
                return(filter);
            }
#else
            if (filterMode == RebarFilterMode.DoubleMode)
            {
                ElementParameterFilter filterByStandardArm = new ElementParameterFilter(new List <FilterRule> {
                    ruleIsNotFamily, ruleHostEquals
                });
                ElementParameterFilter filterForIfcArm = new ElementParameterFilter(new List <FilterRule> {
                    ruleIsFamily, ruleMrkEquals
                });
                LogicalOrFilter orfilter = new LogicalOrFilter(filterByStandardArm, filterForIfcArm);
                filter = ParameterFilterElement.Create(doc, filterName, rebarCatsIds, orfilter);
                return(filter);
            }
#endif
            return(null);
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Debug.Listeners.Clear();
            Debug.Listeners.Add(new RbsLogger.Logger("ViewColoring"));

            Document doc     = commandData.Application.ActiveUIDocument.Document;
            View     curView = doc.ActiveView;

            //проверю, можно ли менять фильтры у данного вида
            bool checkAllowFilters = ViewUtils.CheckIsChangeFiltersAvailable(doc, curView);

            if (!checkAllowFilters)
            {
                Debug.WriteLine("View is depended by view template");
                TaskDialog.Show("Ошибка", "Невозможно назначить фильтры, так как они определяются в шаблоне вида.");
                return(Result.Failed);
            }

            //список все параметров у элементов на виде
            List <Element> elems = new FilteredElementCollector(doc, curView.Id)
                                   .WhereElementIsNotElementType()
                                   .ToElements()
                                   .Where(e => e != null)
                                   .Where(e => e.IsValidObject)
                                   .Where(e => e.Category != null)
                                   .Where(e => e.Category.Id.IntegerValue != -2000500)
                                   .ToList();

            Debug.WriteLine("Elements on view: " + elems.Count);
            List <MyParameter> mparams = ViewUtils.GetAllFilterableParameters(doc, elems);

            Debug.WriteLine("Filterable parameters found: " + mparams.Count);

            FormSelectParameterForFilters form1 = new FormSelectParameterForFilters();

            form1.parameters = mparams;
            if (form1.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                Debug.WriteLine("Cancelled by user");
                return(Result.Cancelled);
            }

            IFilterData filterData = null;

            if (form1.colorizeMode == ColorizeMode.ResetColors)
            {
                using (Transaction t = new Transaction(doc))
                {
                    t.Start("Очистка фильтров");
                    ClearFilters(doc, curView);
                    t.Commit();
                }
                return(Result.Succeeded);
            }
            else if (form1.colorizeMode == ColorizeMode.ByParameter)
            {
                int startSymbols = 0;
                if (form1.criteriaType == CriteriaType.StartsWith)
                {
                    startSymbols = form1.startSymbols;
                    Debug.WriteLine("Filter criteria start symbols:" + startSymbols);
                }
                Debug.WriteLine("Colorize by parameter: " + form1.selectedParameter.Name);
                filterData = new FilterDataSimple(doc, elems, form1.selectedParameter, form1.startSymbols, form1.criteriaType);
            }
            else if (form1.colorizeMode == ColorizeMode.CheckHostmark)
            {
                Debug.WriteLine("Colorize for rebar host checking");
                filterData = new FilterDataForRebars(doc);
            }

            MyDialogResult collectResult = filterData.CollectValues(doc, curView);

            if (collectResult.ResultType == ResultType.cancel)
            {
                Debug.WriteLine("Cancelled by user");
                return(Result.Cancelled);
            }
            else if (collectResult.ResultType == ResultType.error)
            {
                message = collectResult.Message;
                Debug.WriteLine(message);
                return(Result.Failed);
            }
            else if (collectResult.ResultType == ResultType.warning)
            {
                Debug.WriteLine(collectResult.Message);
                TaskDialog.Show("Внимание", collectResult.Message);
            }

            Debug.WriteLine("Values:" + filterData.ValuesCount);
            if (filterData.ValuesCount > 64)
            {
                message = "Значений больше 64! Генерация цветов невозможна";
                return(Result.Failed);
            }

            //Получу id сплошной заливки
            ElementId solidFillPatternId = DocumentGetter.GetSolidFillPatternId(doc);


            using (Transaction t = new Transaction(doc))
            {
                t.Start("Колоризация вида");

                ClearFilters(doc, curView);

                filterData.ApplyFilters(doc, curView, solidFillPatternId, form1.colorLines, form1.colorFill);

                t.Commit();
            }
            Debug.WriteLine("Coloring completed");
            return(Result.Succeeded);
        }