AutoCAD Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.

AutoCAD Civil 3D Customization

Reply
Highlighted
Post 1 of 3

DisplayStyle Layers

220 Views, 2 Replies
12-27-2015 04:44 PM

@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

Re: DisplayStyle Layers

01-07-2016 06:23 AM in reply to: Jeff_M
Thanks @Jeff_M! Can I include it on the blog post?
Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
Post 3 of 3

Re: DisplayStyle Layers

01-07-2016 06:36 AM in reply to: augusto.goncalves

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

Jeff_M, also a frequent Swamper

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post

Civil 3D Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for AutoCAD Civil 3D helps you achieve greater speed, accuracy, and automation from concept to manufacturing.