Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

DisplayStyle Layers

2 REPLIES 2
Reply
Message 1 of 3
Jeff_M
779 Views, 2 Replies

DisplayStyle Layers

@augusto.goncalves - Augusto, thanks for this start for the Display Style Layers. There are a few issues that should be addressed, however. This does not work with Link, Marker, or Shape styles, and when iterating the entire StylesRoot it will crash when it gets to the HorizontalGeometryBandStyle's last 3 Enums (the ones with Curvature in their names). Here is what I found to work for all styles, at least I think it's getting all of them now.

 

 

        public static List<string> GetDisplayStylesLayer(StyleBase style)
        {
            List<string> layers = new List<string>();
            // get all methods that contains "DisplayStyle" on their names
            var methods = style.GetType().GetMethods()
              .Where(m => (m.Name.Contains("DisplayStyle") && !m.Name.Contains("_")));
            // run through the collection of methods
            foreach (MethodInfo method in methods)
            {
                var methodparams = method.GetParameters();
                if (methodparams.Length > 1)
                    continue; // if more than 1, then we don't know
                if (methodparams.Length == 0)//With no params, it's either a Link, Marker, or Shape style...possibly others.
                {
                    DisplayStyle dispStyle = method.Invoke(style, new object[] {}) as DisplayStyle;
                    if (dispStyle == null)
                        continue;
                    layers.Add(dispStyle.Layer);
                    continue;
                }
                ParameterInfo param = methodparams[0];
                if (!param.ParameterType.IsEnum)
                    continue; // not a enum, skip
                // check all values on the enum
                foreach (var enumValue in Enum.GetValues(
                  param.ParameterType))
                {
                    try
                    {
                        DisplayStyle dispStyle = method.Invoke(style, new object[] { enumValue }) as DisplayStyle;
                        if (dispStyle == null || enumValue.ToString().Contains("Curvature")) 
                            continue;// something went wrong
                         layers.Add(dispStyle.Layer);
                    }
                    catch { }//SectionViewMaterial Table type has a Profile property but it throws a error because it really doesn't apply, let's catch it.
                }
            }
            return layers;
        }

 

Jeff_M, also a frequent Swamper
EESignature
2 REPLIES 2
Message 2 of 3
augusto.goncalves
in reply to: Jeff_M

Thanks @Jeff_M! Can I include it on the blog post?
Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
Message 3 of 3
Jeff_M
in reply to: augusto.goncalves

@augusto.goncalves, yes, please do add it to the blog post.

Jeff_M, also a frequent Swamper
EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report