2 Replies Latest reply on Apr 1, 2017 8:44 PM by Amen Allah Jlili

    How to get user readable error/warning code message

    Michael Caulton

      Does anyone have any tips on how to create a user readable error/warning code message?


      I have been struggling to try and figure out a way of doing this that is not a case statement that has to be created for each of the error definitions I need.


      After something similar to visual studio Exception.Message



        • Re: How to get user readable error/warning code message
          Amen Allah Jlili

          Hi Michael!
          I've been there


          Make a static helper method that converts the name of the enumrator to a string. Remove the "sw" and add a space after every capital letter. That's the easiest most convenient way to do it.



          Your second example: swFileNameEmpty -> File Name Empty. That should be enough to describe the error.

          If you really really want to get the enumrator's description off the help file. You can construct the api online help url from the name of the enumaration name:


          Then you'll need a html processing library to be able to retrieve the DOM element that contains the enumrator's description. I do feel that this can be an overkill though.



          • Re: How to get user readable error/warning code message
            Amen Allah Jlili

            Here's a working C# example I wrote:

                    /// Convert a SOLIDWORKS enum's enumarator to string
                    /// Required: using System.Text.RegularExpressions;
                    /// </summary>
                    public static string convertEnumratationEnumatorToString(Enum Enum)
                        string enumrator = Enum.ToString().Replace("sw", string.Empty);
                        var reg = new Regex("[A-Z]",RegexOptions.None);
                        MatchCollection matches = reg.Matches(enumrator);
                        foreach (Match match in matches)
                            string old = match.Value.ToString();
                            string New = " " + match.Value.ToString();
                            enumrator = enumrator.Replace(old,New);
                        return enumrator.TrimStart();