Exemple #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);
        }
Exemple #2
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);
        }