DisplayStyle Layers

DisplayStyle Layers

Jeff_M
Consultant Consultant
1,581 Views
2 Replies
Message 1 of 3

DisplayStyle Layers

Jeff_M
Consultant
Consultant

@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
1,582 Views
2 Replies
Replies (2)
Message 2 of 3

augusto.goncalves
Alumni
Alumni
Thanks @Jeff_M! Can I include it on the blog post?
Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
0 Likes
Message 3 of 3

Jeff_M
Consultant
Consultant

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

Jeff_M, also a frequent Swamper
EESignature
0 Likes