How to retrieve the final graphics style of an element?

How to retrieve the final graphics style of an element?

maisoui
Advocate Advocate
3,840 Views
6 Replies
Message 1 of 7

How to retrieve the final graphics style of an element?

maisoui
Advocate
Advocate

Hi,

 

I am developing a solution to export elements from a Revit view to another format and I like to retrieve the "final" Graphics Style of an element according to a specific view, details level, view template or overrides, materials, etc. I'm looking for a magic method in Revit API to give me line weight, line color and line pattern of an element.

 

view.ComputeFinalGraphicsStyle(element);

All suggestions are welcome.

Best regards,

Jonathan

 

--
Jonathan
0 Likes
3,841 Views
6 Replies
Replies (6)
Message 2 of 7

JimJia
Alumni
Alumni

Dear Jonathan,

 

If you want to get the info, you need to do it manually on your own codes.

Here are some thoughts may help you.

Firstly, get the graphics style from element's category, then, if the element in a specific view has override graphics settings, get from override graphics settings instead.

 

Hope the following codes can give you some idea

public void GetGraphicsStyleInView(Document doc, View view, Element e)
        {
            /*
             * first get graphics style from element's category, 
             * if override graphics setting setted, get from override
             */
            Color color = null;
            int? lineWeight = null;
            LinePattern linePattern = null;

            //get line weight& color from category
            lineWeight = e.Category.GetLineWeight(GraphicsStyleType.Projection);
            color = e.Category.LineColor;

            ElementId patternId = e.Category.GetLinePatternId(GraphicsStyleType.Projection);
            if(patternId != ElementId.InvalidElementId)
            {
                LinePatternElement patternElement = doc.GetElement(patternId) as LinePatternElement;
                if (patternElement != null)
                    linePattern = patternElement.GetLinePattern();
            }

            //if element has override, then get from override 
            OverrideGraphicSettings overrideGraphicSettings = doc.ActiveView.GetElementOverrides(e.Id);
            if (null != overrideGraphicSettings)
            {
                if(overrideGraphicSettings.CutLineColor.IsValid)
                    color = overrideGraphicSettings.CutLineColor;
                if(overrideGraphicSettings.CutLineWeight > 0)
                    lineWeight = overrideGraphicSettings.CutLineWeight;
                if (overrideGraphicSettings.CutLinePatternId != ElementId.InvalidElementId)
                {
                    LinePatternElement patternElement = doc.GetElement(overrideGraphicSettings.CutLinePatternId) as LinePatternElement;
                    if (patternElement.GetLinePattern() != null)
                        linePattern = patternElement.GetLinePattern();

                }
            }
        }

Jim Jia
Autodesk Forge Evangelist
https://forge.autodesk.com
Developer Technical Services
Autodesk Developer Network
Email: Jim.Jia@autodesk.com
Message 3 of 7

maisoui
Advocate
Advocate

Hi JimJia,

 

Thank your for your answer and your full sample.

Will that take care of the view template if exists?

There are so many different levels in the element visibility override hierarchy?

 

Best regards,

Jonathan

 

--
Jonathan
0 Likes
Message 4 of 7

jeremytammik
Autodesk
Autodesk
0 Likes
Message 5 of 7

maisoui
Advocate
Advocate

Yes, 10 levels, so can Revit (API) developers expose a method to retrieve the final graphics style of an element in a specific view ?

 

--
Jonathan
0 Likes
Message 6 of 7

jeremytammik
Autodesk
Autodesk

>>> Revit Idea Station



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 7 of 7

jeremytammik
Autodesk
Autodesk

Another idea:

 

To determine the material of a solid, checking out this 8 year old blog post:

 

http://thebuildingcoder.typepad.com/blog/2009/11/solid-material.html

 

To determine the graphics style, you should be able to use the GeometryObject.GraphicsStyleId property:

 

http://www.revitapidocs.com/2017/4103f148-957e-3f44-9ccd-a5ed6702c689.htm

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes