Example #1
0
        private Warning(Autodesk.Revit.DB.FailureMessage failure)
        {
            var elementIds = failure.GetFailingElements();

            if (!elementIds.Any())
            {
                return;
            }

            var doc             = DocumentManager.Instance.CurrentDBDocument;
            var warningElements = new List <WarningElement>();

            foreach (var id in elementIds)
            {
                var e = doc.GetElement(id);
                if (e == null)
                {
                    continue;
                }

                var we = new WarningElement {
                    Id = id.IntegerValue
                };
                warningElements.Add(we);
            }

            Elements     = warningElements;
            ErrorMessage = failure.GetDescriptionText();
        }
Example #2
0
        private static WarningElement CreateElement(int[] pointers, string[] contents)
        {
            var ew = new WarningElement();

            try { ew.Workset = contents[pointers[0]].Trim(); } catch { ew.Workset = ""; }
            try { ew.Category = contents[pointers[1]].Trim(); } catch { ew.Category = ""; }
            try { ew.Family = contents[pointers[2]].Trim(); } catch { ew.Family = ""; }
            try { ew.Type = contents[pointers[3]].Trim(); } catch { ew.Type = ""; }
            try { ew.Id = int.Parse(contents[pointers[4]].Trim().Remove(0, 3)); } catch { ew.Id = -1; }
            try { ew.DesignOptionSet = contents[pointers[5]].Trim().TrimStart('('); } catch { ew.DesignOptionSet = ""; }
            try { ew.DesignOption = contents[pointers[6]].Trim().TrimEnd(')'); } catch { ew.DesignOption = ""; }
            return(ew);
        }
Example #3
0
        /// <summary>
        /// Parse HTML Warning Report.
        /// </summary>
        /// <param name="filePath">File Path to HTML report.</param>
        /// <returns name="Warnings">List of Warning objects.</returns>
        public static List <Warning> ParseHtml(object filePath)
        {
            var cleanFilePath = Utilities.FilePathUtilities.VerifyFilePath(filePath);

            // read html string
            var html = File.ReadAllText(cleanFilePath);

            // create a doc
            var htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(html);

            var warnings = new List <Warning>();

            foreach (var row in htmlDoc.DocumentNode.SelectNodes("//table/tr"))
            {
                var w       = new Warning();
                var columns = row.SelectNodes("td");
                if (columns.Count > 1)
                {
                    // assign error message
                    w.ErrorMessage = columns[0].InnerText.Trim();

                    // generate elements
                    var elements     = new List <WarningElement>();
                    var elementLines = columns[1].InnerText.Trim().Replace("\\\"", "").Split(new[] { "   " }, StringSplitOptions.None);
                    foreach (var e in elementLines)
                    {
                        var toProcess = e.Replace(": :", ":");
                        var contents  = toProcess.Split(new[] { " : " }, StringSplitOptions.None);
                        var ew        = new WarningElement();
                        switch (contents.Count())
                        {
                        // model lines don't have category and family
                        // well they do but it gets swallowed by the html parser due to use of <>
                        case 3:
                            ew = CreateElement(new[] { 0, -1, -1, 1, 2, -1, -1 }, contents);
                            break;

                        // system elements that are hosted ex: Wall Opening
                        case 4:
                            ew = CreateElement(new[] { 0, -1, 1, 2, 3, -1, -1 }, contents);
                            break;

                        // typical elements
                        case 5:
                            ew = CreateElement(new[] { 0, 1, 2, 3, 4, -1, -1 }, contents);
                            break;

                        // rebar for example has a 5th argument that is "Shape 2A". I am not sure what that is yet.
                        case 6:
                            ew = CreateElement(new[] { 0, 1, 2, 3, 5, -1, -1 }, contents);
                            break;

                        // elements with design options
                        case 7:
                            ew = CreateElement(new[] { 2, 3, 4, 5, 6, 0, 1 }, contents);
                            break;
                        }
                        elements.Add(ew);
                    }
                    w.Elements = elements;
                }
                warnings.Add(w);
            }

            return(warnings);
        }