/// <summary> /// Paint a solid in a new named view /// </summary> /// <param name="s">solid</param> /// <param name="viewName">Given the name of view</param> public void PaintSolid(Solid s, String viewName) { View view; if (!viewNameList.Contains(viewName)) { view = m_doc.Create.NewView3D(new XYZ(1, 1, 1)); view.Name = viewName; viewNameList.Add(viewName); } else { view = (((new FilteredElementCollector(m_doc). OfClass(typeof(View))).Cast <View>()). Where(e => e.Name == viewName)).First <View>(); } SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(view); if (sfm == null) { sfm = SpatialFieldManager.CreateSpatialFieldManager(view, 1); } if (SchemaId != -1) { IList <int> results = sfm.GetRegisteredResults(); if (!results.Contains(SchemaId)) { SchemaId = -1; } } if (SchemaId == -1) { AnalysisResultSchema resultSchema1 = new AnalysisResultSchema("PaintedSolid" + viewName, "Description"); AnalysisDisplayStyle displayStyle = AnalysisDisplayStyle.CreateAnalysisDisplayStyle( m_doc, "Real_Color_Surface" + viewName, new AnalysisDisplayColoredSurfaceSettings(), new AnalysisDisplayColorSettings(), new AnalysisDisplayLegendSettings()); resultSchema1.AnalysisDisplayStyleId = displayStyle.Id; SchemaId = sfm.RegisterResult(resultSchema1); } FaceArray faces = s.Faces; Transform trf = Transform.Identity; foreach (Face face in faces) { int idx = sfm.AddSpatialFieldPrimitive(face, trf); IList <UV> uvPts = null; IList <ValueAtPoint> valList = null; ComputeValueAtPointForFace(face, out uvPts, out valList, 1); FieldDomainPointsByUV pnts = new FieldDomainPointsByUV(uvPts); FieldValues vals = new FieldValues(valList); sfm.UpdateSpatialFieldPrimitive(idx, pnts, vals, SchemaId); } }
/// <summary> /// We setup our preferred style for displaying the results /// </summary> /// <remarks> /// This is to make it easier to run this sample on any document. /// We create a gradient-like style (unless it already exists) /// and register it with the given view. Then we set it as the /// default analysis stile in that view. /// </remarks> /// private void SetupDisplayStyle(Autodesk.Revit.DB.View view) { const string styleName = "SDK2014-AL Style"; AnalysisDisplayStyle ourStyle = null; // check if we are already using our preferred display style if (ElementId.InvalidElementId != view.AnalysisDisplayStyleId) { ourStyle = view.Document.GetElement(view.AnalysisDisplayStyleId) as AnalysisDisplayStyle; if (ourStyle.Name == styleName) { return; } } // Look if the style exist at all in the document FilteredElementCollector collector = new FilteredElementCollector(view.Document); ICollection <Element> allStyles = collector.OfClass(typeof(AnalysisDisplayStyle)).ToElements(); foreach (Element elem in allStyles) { if (elem.Name == styleName) { using (Transaction trans = new Transaction(view.Document)) { trans.Start("Change Analysis Display Style"); view.AnalysisDisplayStyleId = elem.Id; trans.Commit(); return; } } } // we do not have out style yet - let's create it // a) grid lines AnalysisDisplayColoredSurfaceSettings surface = new AnalysisDisplayColoredSurfaceSettings(); surface.ShowGridLines = true; // b) colors AnalysisDisplayColorSettings colors = new AnalysisDisplayColorSettings(); Color orange = new Color(255, 205, 0); Color green = new Color(0, 255, 0); colors.MinColor = orange; colors.MaxColor = green; // c) the legend AnalysisDisplayLegendSettings legend = new AnalysisDisplayLegendSettings(); legend.NumberOfSteps = 10; legend.Rounding = 0.1; legend.ShowDataDescription = false; legend.ShowLegend = false; // creation of a style needs to be in a transaction using (Transaction trans = new Transaction(view.Document)) { trans.Start("Set Analysis Display Style"); ourStyle = AnalysisDisplayStyle.CreateAnalysisDisplayStyle(view.Document, styleName, surface, colors, legend); view.AnalysisDisplayStyleId = ourStyle.Id; trans.Commit(); } }
/// <summary> /// Set analysis display style to switch off grid lines /// and use greyscale values in active view. /// </summary> void SetAnalysisDisplayStyle(Document doc) { AnalysisDisplayStyle analysisDisplayStyle; const string styleName = "Revit Webcam Display Style"; // extract existing display styles with specific name FilteredElementCollector a = new FilteredElementCollector(doc); IList <Element> elements = a .OfClass(typeof(AnalysisDisplayStyle)) .Where(x => x.Name.Equals(styleName)) .Cast <Element>() .ToList(); if (0 < elements.Count) { // use the existing display style analysisDisplayStyle = elements[0] as AnalysisDisplayStyle; } else { // create new display style: // coloured surface settings: AnalysisDisplayColoredSurfaceSettings coloredSurfaceSettings = new AnalysisDisplayColoredSurfaceSettings(); coloredSurfaceSettings.ShowGridLines = false; // color settings: AnalysisDisplayColorSettings colorSettings = new AnalysisDisplayColorSettings(); colorSettings.MaxColor = new Color(255, 255, 255); colorSettings.MinColor = new Color(0, 0, 0); // legend settings: AnalysisDisplayLegendSettings legendSettings = new AnalysisDisplayLegendSettings(); legendSettings.NumberOfSteps = 10; legendSettings.Rounding = 0.05; legendSettings.ShowDataDescription = false; legendSettings.ShowLegend = true; //// extract legend text: //a = new FilteredElementCollector( doc ); //elements = a // .OfClass( typeof( TextNoteType ) ) // .Where( x => x.Name == "LegendText" ) // .Cast<Element>() // .ToList(); //if( 0 < elements.Count ) //{ // // if LegendText exists, use it for this display style // TextNoteType textType = elements[0] as TextNoteType; // // warning CS0618: // // SetTextTypeId(ElementId, Document) is obsolete: // // this method will be obsolete from 2012. // legendSettings.SetTextTypeId( textType.Id, doc ); //} // Create the analysis display style: var transaction = new Transaction(doc); transaction.Start("Create AnalysisDisplayStyle"); try { analysisDisplayStyle = AnalysisDisplayStyle .CreateAnalysisDisplayStyle( doc, styleName, coloredSurfaceSettings, colorSettings, legendSettings); // assign the display style to the active view doc.ActiveView.AnalysisDisplayStyleId = analysisDisplayStyle.Id; transaction.Commit(); } catch { transaction.RollBack(); throw; } } }
/// <summary> /// Set analysis display style to switch off grid lines /// and use greyscale values in active view. /// </summary> void SetAnalysisDisplayStyle(Document doc) { AnalysisDisplayStyle analysisDisplayStyle; const string styleName = "Revit Webcam Display Style"; // extract existing display styles with specific name FilteredElementCollector a = new FilteredElementCollector(doc); IList <Element> elements = a .OfClass(typeof(AnalysisDisplayStyle)) .Where(x => x.Name.Equals(styleName)) .Cast <Element>() .ToList(); if (0 < elements.Count) { // use the existing display style analysisDisplayStyle = elements[0] as AnalysisDisplayStyle; } else { // create new display style: // coloured surface settings: AnalysisDisplayColoredSurfaceSettings coloredSurfaceSettings = new AnalysisDisplayColoredSurfaceSettings(); coloredSurfaceSettings.ShowGridLines = false; // color settings: AnalysisDisplayColorSettings colorSettings = new AnalysisDisplayColorSettings(); colorSettings.MaxColor = new Color(255, 255, 255); colorSettings.MinColor = new Color(0, 0, 0); // legend settings: AnalysisDisplayLegendSettings legendSettings = new AnalysisDisplayLegendSettings(); legendSettings.NumberOfSteps = 10; legendSettings.Rounding = 0.05; legendSettings.ShowDataDescription = false; legendSettings.ShowLegend = true; // extract legend text: a = new FilteredElementCollector(doc); elements = a .OfClass(typeof(TextNoteType)) .Where(x => x.Name == "LegendText") .Cast <Element>() .ToList(); if (0 < elements.Count) { // if LegendText exists, use it for this display style TextNoteType textType = elements[0] as TextNoteType; legendSettings.SetTextTypeId(textType.Id, doc); } // create the analysis display style: analysisDisplayStyle = AnalysisDisplayStyle .CreateAnalysisDisplayStyle( doc, styleName, coloredSurfaceSettings, colorSettings, legendSettings); } // assign the display style to the active view doc.ActiveView.AnalysisDisplayStyleId = analysisDisplayStyle.Id; }
private bool IsViewForAnalysis(Autodesk.Revit.DB.View activeView) { var result = false; try { if (activeView.ViewType == ViewType.FloorPlan) { AnalysisDisplayStyle displayStyle = null; var collector = new FilteredElementCollector(m_doc); var displayStyles = collector.OfClass(typeof(AnalysisDisplayStyle)).ToElements().Cast <AnalysisDisplayStyle>().ToList(); var viewAnlysisStyle = from style in displayStyles where style.Name == "View Analysis" select style; if (viewAnlysisStyle.Any()) { displayStyle = viewAnlysisStyle.First(); } else { var coloredSurfaceSettings = new AnalysisDisplayColoredSurfaceSettings(); coloredSurfaceSettings.ShowGridLines = false; var colorSettings = new AnalysisDisplayColorSettings(); var yellow = new Color(255, 255, 0); var blue = new Color(0, 128, 255); var colorEntries = new List <AnalysisDisplayColorEntry> { new AnalysisDisplayColorEntry(blue) }; colorSettings.SetIntermediateColors(colorEntries); colorSettings.MinColor = blue; colorSettings.MaxColor = yellow; colorSettings.ColorSettingsType = AnalysisDisplayStyleColorSettingsType.SolidColorRanges; var legendSettings = new AnalysisDisplayLegendSettings { NumberOfSteps = 1, ShowDataDescription = false, ShowLegend = false }; using (var trans = new Transaction(m_doc)) { trans.Start("Create an Analysis Display Style"); try { displayStyle = AnalysisDisplayStyle.CreateAnalysisDisplayStyle(m_doc, "View Analysis", coloredSurfaceSettings, colorSettings, legendSettings); trans.Commit(); } catch (Exception ex) { Log.AppendLog(LogMessageType.EXCEPTION, ex.Message); trans.RollBack(); } } } if (null != displayStyle) { using (var trans = new Transaction(m_doc)) { trans.Start("Set Display Style"); try { m_doc.ActiveView.AnalysisDisplayStyleId = displayStyle.Id; trans.Commit(); result = true; } catch (Exception ex) { Log.AppendLog(LogMessageType.EXCEPTION, ex.Message); trans.RollBack(); result = false; } } } else { result = false; } } else { result = false; MessageBox.Show("A floor plan should be an active view for the view anlaysis.\n", "View Analysis - Active View", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show("Failed to get information of the active view.\n" + ex.Message, "View Analysis - Active View", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return(result); }
public void SetCO2eAnalysisDisplayStyle(View view) { var t = new Transaction(view.Document); t.Start("SetCO2eAnalysisDisplayStyle"); AnalysisDisplayStyle analysisDisplayStyle = null; // Look for an existing analysis display style with a specific name var collector1 = new FilteredElementCollector(view.Document); ICollection <Element> collection = collector1.OfClass(typeof(AnalysisDisplayStyle)).ToElements(); var displayStyle = from element in collection where element.Name == "CO2e Display Style 1" select element; // If display style does not already exist in the document, create it if (displayStyle.Count() == 0) { var coloredSurfaceSettings = new AnalysisDisplayColoredSurfaceSettings { ShowGridLines = false }; var colorSettings = new AnalysisDisplayColorSettings(); var deepRed = new Color(166, 0, 0); var red = new Color(255, 44, 01); var orange = new Color(255, 179, 0); var green = new Color(0, 253, 0); var lightGreen = new Color(128, 255, 12); colorSettings.MaxColor = deepRed; colorSettings.SetIntermediateColors(new List <AnalysisDisplayColorEntry> { new AnalysisDisplayColorEntry(green), new AnalysisDisplayColorEntry(orange), new AnalysisDisplayColorEntry(red) }); colorSettings.MinColor = lightGreen; var legendSettings = new AnalysisDisplayLegendSettings { NumberOfSteps = 10, Rounding = 0.05, ShowDataDescription = false, ShowLegend = true }; var collector2 = new FilteredElementCollector(view.Document); 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) { var textType = textElements.Cast <TextNoteType>().ElementAt(0); legendSettings.SetTextTypeId(textType.Id, view.Document); } analysisDisplayStyle = AnalysisDisplayStyle.CreateAnalysisDisplayStyle(view.Document, "CO2e Display Style 1", coloredSurfaceSettings, colorSettings, legendSettings); } else { analysisDisplayStyle = displayStyle.Cast <AnalysisDisplayStyle>().ElementAt(0); } // now assign the display style to the view view.AnalysisDisplayStyleId = analysisDisplayStyle.Id; t.Commit(); }