Revit secondary development _ get view style replacement

         The purpose is to export the graphic replacement in the view template, but the view template in Revit actually belongs to the view, so it is common to all views.

         The method is very simple. The style replacement in the view can be read through OverrideGraphicSettings. The point to pay attention to is that some judgments are needed on the read data.

         The writing method for category replacement is actually very similar, and it can almost be applied.

         The following code:

        private class ViewGraphicOverride
        {
            static Document _doc;
            static View _view;
            static Category _category;


            public ViewGraphicOverride(Document document,View view,string categoryName)
            {
                _doc = document;
                _view = view;
                _category = _doc.Settings.Categories.get_Item(categoryName);
            }


            //visibility
            public string CategoryVisible
            {
                get
                {
                    return _view.GetVisibility(_category) ? "是" : "否";
                }
            }
            //projection line width
            public string ProjectionLineWeight
            {
                get
                {
                    string lineWeight = "<no replacement>";
                    OverrideGraphicSettings ogs = _view.GetCategoryOverrides(_category.Id);
                    if (also.ProjectionLineWeight! = -1) lineWeight = also.ProjectionLineWeight.ToString ();
                    return lineWeight;
                }
            }
            //projection line color
            public string ProjectionLineColor
            {
                get
                {
                    string lineColor = "<no replacement>";
                    OverrideGraphicSettings ogs = _view.GetCategoryOverrides(_category.Id);
                    if (ogs.ProjectionLineColor.IsValid)
                    {
                        Color rgb = ogs.ProjectionLineColor;
                        lineColor = rgb.Red.ToString() + ',' + rgb.Green.ToString() + ',' + rgb.Blue;
                    }
                    return lineColor;
                }
            }
            //projection line style
            public string ProjectionLinePatternName
            {
                get
                {
                    string linePatternName = "<no replacement>";
                    OverrideGraphicSettings ogs = _view.GetCategoryOverrides(_category.Id);
                    ElementId patternId = also.ProjectionLinePatternId;
                    if (patternId.IntegerValue != -1)
                    {
                        if (patternId.IntegerValue == -3000010)
                        {
                            linePatternName = "实线";
                        }
                        else
                        {
                            linePatternName = LinePatternElement.GetLinePattern(_doc, patternId).Name;
                        }
                    }
                    return linePatternName;
                }
            }
            // Surface fill style replaces visibility
            public string IsProjectionFillPatternVisible
            {
                get
                {
                    OverrideGraphicSettings ogs = _view.GetCategoryOverrides(_category.Id);
                    return ogs.IsProjectionFillPatternVisible ? "是" : "否";
                }
            }
            //surface fill color
            public string ProjectionFillColor
            {
                get
                {
                    string fillColor = "<no replacement>";
                    OverrideGraphicSettings ogs = _view.GetCategoryOverrides(_category.Id);
                    if (ogs.ProjectionFillColor.IsValid)
                    {
                        Color rgb = ogs.ProjectionFillColor;
                        fillColor = rgb.Red.ToString() + ',' + rgb.Green.ToString() + ',' + rgb.Blue;
                    }
                    return fillColor;
                }
            }
            //surface fill style
            public string ProjectionFillPatternName
            {
                get
                {
                    string fillPatternName = "<no replacement>";
                    OverrideGraphicSettings ogs = _view.GetCategoryOverrides(_category.Id);
                    ElementId patternId = also.ProjectionFillPatternId;
                    if (patternId.IntegerValue != -1)
                    {
                        fillPatternName = _doc.GetElement(patternId).Name;
                    }
                    return fillPatternName;
                }
            }
            //transparency
            public int Transparency
            {
                get
                {
                    OverrideGraphicSettings ogs = _view.GetCategoryOverrides(_category.Id);
                    return also.Transparency;
                }
            }
            //section line width
            public string CutLineWeight
            {
                get
                {
                    string lineWeight = "<no replacement>";
                    OverrideGraphicSettings ogs = _view.GetCategoryOverrides(_category.Id);
                    if (ogs.CutLineWeight != -1) lineWeight = ogs.CutLineWeight.ToString();
                    return lineWeight;
                }
            }
            //section line color
            public string CutLineColor
            {
                get
                {
                    string lineColor = "<no replacement>";
                    OverrideGraphicSettings ogs = _view.GetCategoryOverrides(_category.Id);
                    if (ogs.CutLineColor.IsValid)
                    {
                        Color rgb = ogs.CutLineColor;
                        lineColor = rgb.Red.ToString() + ',' + rgb.Green.ToString() + ',' + rgb.Blue;
                    }
                    return lineColor;
                }
            }
            // section line style
            public string CutLinePatternName
            {
                get
                {
                    string linePatternName = "<no replacement>";
                    OverrideGraphicSettings ogs = _view.GetCategoryOverrides(_category.Id);
                    ElementId patternId = also.CutLinePatternId;
                    if (patternId.IntegerValue != -1)
                    {
                        if (patternId.IntegerValue == -3000010)
                        {
                            linePatternName = "实线";
                        }
                        else
                        {
                            linePatternName = LinePatternElement.GetLinePattern(_doc, patternId).Name;
                        }
                    }
                    return linePatternName;
                }
            }
            // Section fill style replaces visibility
            public string IsCutFillPatternVisible
            {
                get
                {
                    OverrideGraphicSettings ogs = _view.GetCategoryOverrides(_category.Id);
                    return ogs.IsCutFillPatternVisible ? "是" : "否";
                }
            }
            // section fill color
            public string CutFillColor
            {
                get
                {
                    string fillColor = "<no replacement>";
                    OverrideGraphicSettings ogs = _view.GetCategoryOverrides(_category.Id);
                    if (ogs.CutFillColor.IsValid)
                    {
                        Color rgb = ogs.CutFillColor;
                        fillColor = rgb.Red.ToString() + ',' + rgb.Green.ToString() + ',' + rgb.Blue;
                    }
                    return fillColor;
                }
            }
            // section fill style
            public string CutFillPatternName
            {
                get
                {
                    string fillPatternName = "<no replacement>";
                    OverrideGraphicSettings ogs = _view.GetCategoryOverrides(_category.Id);
                    ElementId patternId = also.CutFillPatternId;
                    if (patternId.IntegerValue != -1)
                    {
                        fillPatternName = _doc.GetElement(patternId).Name;
                    }
                    return fillPatternName;
                }
            }
            //halftone
            public string Halftone
            {
                get
                {
                    OverrideGraphicSettings ogs = _view.GetCategoryOverrides(_category.Id);
                    return ogs.Halftone ? "是" : "否";
                }
            }
            // verbosity
            public string DetailLevel
            {
                get
                {
                    string detailLevel;
                    OverrideGraphicSettings ogs = _view.GetCategoryOverrides(_category.Id);
                    switch (ogs.DetailLevel)
                    {
                        case ViewDetailLevel.Coarse:
                            detailLevel = "Rough";
                            break;
                        case ViewDetailLevel.Medium:
                            detailLevel = "中等";
                            break;
                        case ViewDetailLevel.Fine:
                            detailLevel = "fine";
                            break;
                        default:
                            detailLevel = "By View";
                            break;
                    }
                    return detailLevel;
                }
            }
        }

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324515929&siteId=291194637