Ejemplo n.º 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);
        }
        public MyDialogResult CollectValues(Document doc, View v)
        {
            Debug.WriteLine("Collect parameter values for view: " + v.Name);
            MyDialogResult result = new MyDialogResult(ResultType.ok, "");

            catIdRebar = new List <ElementId> {
                new ElementId(BuiltInCategory.OST_Rebar),
                new ElementId(BuiltInCategory.OST_AreaRein),
                new ElementId(BuiltInCategory.OST_PathRein)
            };

            catIdConstructions = new List <ElementId> {
                new ElementId(BuiltInCategory.OST_Walls),
                new ElementId(BuiltInCategory.OST_Floors),
                new ElementId(BuiltInCategory.OST_StructuralColumns),
                new ElementId(BuiltInCategory.OST_StructuralFraming),
                new ElementId(BuiltInCategory.OST_StructuralFoundation)
            };

            List <Element> rebars = new FilteredElementCollector(doc, v.Id)
                                    .WhereElementIsNotElementType()
                                    .OfCategory(BuiltInCategory.OST_Rebar)
                                    .ToElements()
                                    .ToList();

            Debug.WriteLine("Rebars count: " + rebars.Count);

            HashSet <string> hostMarksList = new HashSet <string>();

            foreach (Element e in rebars)
            {
                //для создания фильтров мне надо взять параметр Марки из любого элемента, можно даже из арматуры
                if (markParam == null)
                {
                    markParam = e.get_Parameter(BuiltInParameter.ALL_MODEL_MARK);
                }

                Parameter hostParam = e.LookupParameter(rebarHostParamName);
                if (hostParam == null)
                {
                    hostParam = e.LookupParameter(rebarMrkParamName);
                    if (hostParam == null)
                    {
                        continue;
                    }
                }

                string hostMarkVal = hostParam.AsString();
                if (!string.IsNullOrEmpty(hostMarkVal))
                {
                    hostMarksList.Add(hostMarkVal);
                }

                if (rebarHostParam == null)
                {
                    rebarHostParam = e.LookupParameter(rebarHostParamName);;
                }

                if (!_rebarIsFamilyParamExists)
                {
                    continue;
                }

                if (rebarMrkParam == null)
                {
                    rebarMrkParam = e.LookupParameter(rebarMrkParamName);
                }

                ElementType etype         = doc.GetElement(e.GetTypeId()) as ElementType;
                Parameter   armisfamparam = etype.LookupParameter(rebarIsFamilyParamName);
                if (armisfamparam == null)
                {
                    armisfamparam = e.LookupParameter(rebarIsFamilyParamName);
                    if (armisfamparam == null)
                    {
                        continue;
                    }
                }
                if (rebarIsFamilyParam == null)
                {
                    rebarIsFamilyParam = armisfamparam;
                }
            }

            if (rebarIsFamilyParam == null)
            {
                result.ResultType = ResultType.warning;
                result.Message   += "Не найден параметр Арм.ВыполненаСемейством. Фильтры будут созданы только по параметру Метка основы.";
            }

            values = hostMarksList.ToList();
            values.Sort();
            Debug.WriteLine("Collect values: " + values.Count);
            return(result);
        }
        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);
        }