The AnalysisDisplayStyle class can be used to control how the analysis results are displayed in the view. The static CreateAnalysisDisplayStyle() method can create either a colored surface display style, a markers with text style, a deformed shape style, diagram style or vector style. For any style, the color and legend settings can also be set.
Once a new AnalysisDisplayStyle is created, use the View.AnalysisDisplayStyleId to assign the style to a view. Although the analysis results are not saved with the document, analysis display styles and their assignment to a view are saved with the model.
"Colored surface" Display Style |
"Markers with text" Display Style |
The following example creates a new colored surface analysis display style (if not already found in the document) and then assigns it to the current view.
Code Region 27-2: Setting analysis display style for view |
Document doc = commandData.Application.ActiveUIDocument.Document; AnalysisDisplayStyle analysisDisplayStyle = null; // Look for an existing analysis display style with a specific name FilteredElementCollector collector1 = new FilteredElementCollector(doc); ICollection<Element> collection = collector1.OfClass(typeof(AnalysisDisplayStyle)).ToElements(); var displayStyle = from element in collection where element.Name == "Display Style 1" select element; // If display style does not already exist in the document, create it if (displayStyle.Count() == 0) { AnalysisDisplayColoredSurfaceSettings coloredSurfaceSettings = new AnalysisDisplayColoredSurfaceSettings(); coloredSurfaceSettings.ShowGridLines = true; AnalysisDisplayColorSettings colorSettings = new AnalysisDisplayColorSettings(); Color orange = new Color(255, 205, 0); Color purple = new Color(200, 0, 200); colorSettings.MaxColor = orange; colorSettings.MinColor = purple; AnalysisDisplayLegendSettings legendSettings = new AnalysisDisplayLegendSettings(); legendSettings.NumberOfSteps = 10; legendSettings.Rounding = 0.05; legendSettings.ShowDataDescription = false; legendSettings.ShowLegend = true; FilteredElementCollector collector2 = new FilteredElementCollector(doc); ICollection<Element> elementCollection = collector2.OfClass(typeof(TextNoteType)).ToElements(); var textElements = from element in collector2 where element.Name == "LegendText" select element; // if LegendText exists, use it for this Display Style if (textElements.Count() > 0) { TextNoteType textType = textElements.Cast<TextNoteType>().ElementAt<TextNoteType>(0); legendSettings.SetTextTypeId(textType.Id, doc); } analysisDisplayStyle = AnalysisDisplayStyle.CreateAnalysisDisplayStyle(doc, "Display Style 1", coloredSurfaceSettings, colorSettings, legendSettings); } else { analysisDisplayStyle = displayStyle.Cast<AnalysisDisplayStyle>().ElementAt<AnalysisDisplayStyle>(0); } // now assign the display style to the view doc.ActiveView.AnalysisDisplayStyleId = analysisDisplayStyle.Id; |