Esempio n. 1
0
        private static Element createVectorDisplayStyle(Document doc, string name)
        {
            AnalysisDisplayVectorSettings style = new AnalysisDisplayVectorSettings();

            style.VectorOrientation = AnalysisDisplayStyleVectorOrientation.Linear;
            style.VectorPosition    = AnalysisDisplayStyleVectorPosition.FromDataPoint;
            style.VectorTextType    = AnalysisDisplayStyleVectorTextType.ShowNone;


            AnalysisDisplayColorSettings colors = new AnalysisDisplayColorSettings();

            colors.ColorSettingsType = AnalysisDisplayStyleColorSettingsType.GradientColor;
            colors.MinColor          = new Color((byte)255, (byte)165, (byte)0);
            colors.MaxColor          = new Color((byte)0, (byte)0, (byte)255); // orange to blue

            // we need to create it
            Element pc =
                AnalysisDisplayStyle.CreateAnalysisDisplayStyle(doc, name,
                                                                style,
                                                                colors,
                                                                new AnalysisDisplayLegendSettings()
            {
                ShowLegend = false
            });

            return(pc);
        }
Esempio n. 2
0
        private static AnalysisDisplayStyle CreateDefaultSpaceSyntaxAnalysisDisplayStyle(Document doc)
        {
            AnalysisDisplayColoredSurfaceSettings coloredSurfaceSettings =
                new AnalysisDisplayColoredSurfaceSettings();

            coloredSurfaceSettings.ShowGridLines    = false;
            coloredSurfaceSettings.ShowContourLines = false;

            AnalysisDisplayColorSettings colorSettings = new AnalysisDisplayColorSettings();

            colorSettings.ColorSettingsType = AnalysisDisplayStyleColorSettingsType.GradientColor;
            colorSettings.MaxColor          = new Color(255, 0, 255); // Magenta
            colorSettings.MinColor          = new Color(255, 255, 0); // Yellow

            AnalysisDisplayLegendSettings legendSettings = new AnalysisDisplayLegendSettings();

            legendSettings.ShowLegend          = true;
            legendSettings.ShowUnits           = true;
            legendSettings.ShowDataDescription = false;

            var analysisDisplayStyle = AnalysisDisplayStyle.CreateAnalysisDisplayStyle(
                doc,
                _defaultSpaceSyntaxDisplayStyleName,
                coloredSurfaceSettings,
                colorSettings,
                legendSettings);

            return(analysisDisplayStyle);
        }
Esempio n. 3
0
        AnalysisDisplayStyle CreateDisplayStyle()
        {
            AnalysisDisplayStyle analysisDisplayStyle = null;

            Document doc = dynRevitSettings.Doc.Document;

            // 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_NAME
                               select element;

            // If display style does not already exist in the document, create it
            if (displayStyle.Count() == 0)
            {
                var coloredSurfaceSettings = new AnalysisDisplayColoredSurfaceSettings();
                coloredSurfaceSettings.ShowGridLines = false;

                var colorSettings = new AnalysisDisplayColorSettings();
                var orange        = new Color(255, 205, 0);
                var purple        = new Color(200, 0, 200);
                colorSettings.MaxColor = orange;
                colorSettings.MinColor = purple;

                var legendSettings = new AnalysisDisplayLegendSettings {
                    NumberOfSteps       = 10,
                    Rounding            = 0.05,
                    ShowDataDescription = false,
                    ShowLegend          = true
                };


                var collector2 = new FilteredElementCollector(doc);
                ICollection <Element> elementCollection = collector2.OfClass(typeof(TextNoteType)).ToElements();

                var textElements = from element in collector2
                                   select element;
                // if LegendText exists, use it for this Display Style
                if (textElements.Any())
                {
                    var textType =
                        textElements.Cast <TextNoteType>().ElementAt <TextNoteType>(0);
                    legendSettings.TextTypeId = textType.Id;
                }
                analysisDisplayStyle = AnalysisDisplayStyle.CreateAnalysisDisplayStyle(doc, DISPLAY_STYLE_NAME, coloredSurfaceSettings, colorSettings, legendSettings);
            }
            else
            {
                analysisDisplayStyle =
                    displayStyle.Cast <AnalysisDisplayStyle>().ElementAt <AnalysisDisplayStyle>(0);
            }

            return(analysisDisplayStyle);
        }
Esempio n. 4
0
        AnalysisDisplayStyle CreateDisplayStyle()
        {
            AnalysisDisplayStyle analysisDisplayStyle = null;

            Document doc = dynRevitSettings.Doc.Document;

            // 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_NAME
                               select element;

            // If display style does not already exist in the document, create it
            if (displayStyle.Count() == 0)
            {
                var coloredSurfaceSettings = new AnalysisDisplayColoredSurfaceSettings();
                coloredSurfaceSettings.ShowGridLines = false;

                var colorSettings = new AnalysisDisplayColorSettings();
                var orange = new Color(255, 205, 0);
                var purple = new Color(200, 0, 200);
                colorSettings.MaxColor = orange;
                colorSettings.MinColor = purple;

                var legendSettings = new AnalysisDisplayLegendSettings{
                    NumberOfSteps = 10,
                    Rounding = 0.05,
                    ShowDataDescription = false,
                    ShowLegend = true};

                var collector2 = new FilteredElementCollector(doc);
                ICollection<Element> elementCollection = collector2.OfClass(typeof(TextNoteType)).ToElements();

                var textElements = from element in collector2
                                   select element;
                // if LegendText exists, use it for this Display Style
                if (textElements.Any())
                {
                    var textType =
                        textElements.Cast<TextNoteType>().ElementAt<TextNoteType>(0);
                    legendSettings.TextTypeId = textType.Id;
                }
                analysisDisplayStyle = AnalysisDisplayStyle.CreateAnalysisDisplayStyle(doc, DISPLAY_STYLE_NAME, coloredSurfaceSettings, colorSettings, legendSettings);
            }
            else
            {
                analysisDisplayStyle =
                    displayStyle.Cast<AnalysisDisplayStyle>().ElementAt<AnalysisDisplayStyle>(0);
            }

            return analysisDisplayStyle;
        }
Esempio n. 5
0
        private AnalysisDisplayColorSettings CreateAnalysisDisplayColorSettings(List <Color> colors)
        {
            var colorSettings = new AnalysisDisplayColorSettings();

            colorSettings.MinColor = colors[0];
            var interColors = new List <AnalysisDisplayColorEntry>();

            for (var i = 1; i < colors.Count - 1; i++)
            {
                interColors.Add(new AnalysisDisplayColorEntry(colors[i]));
            }
            colorSettings.SetIntermediateColors(interColors);
            colorSettings.MaxColor = colors[colors.Count - 1];
            return(colorSettings);
        }
Esempio n. 6
0
        private void CreateAVFDisplayStyle(Document doc, View view)
        {
            AnalysisDisplayColoredSurfaceSettings coloredSurfaceSettings = new AnalysisDisplayColoredSurfaceSettings();

            coloredSurfaceSettings.ShowGridLines = true;

            AnalysisDisplayColorSettings  colorSettings  = new AnalysisDisplayColorSettings();
            AnalysisDisplayLegendSettings legendSettings = new AnalysisDisplayLegendSettings();

            legendSettings.ShowLegend = false;
            var rnd = new Random();
            AnalysisDisplayStyle analysisDisplayStyle = AnalysisDisplayStyle.CreateAnalysisDisplayStyle(doc, "Paint Solid-" + rnd.Next(), coloredSurfaceSettings, colorSettings, legendSettings);

            view.AnalysisDisplayStyleId = analysisDisplayStyle.Id;
        }
Esempio n. 7
0
        /// <summary>
        /// Retrieve or set up the attenuation
        /// display style for the given view.
        /// </summary>
        static void SetAvfDisplayStyle(View view)
        {
            Document doc = view.Document;

            ElementId id = AnalysisDisplayStyle.FindByName(
                doc, _displayStyleName);

            if (ElementId.InvalidElementId == id)
            {
                using (Transaction t = new Transaction(doc))
                {
                    t.Start("Create AVF Display Style");

                    AnalysisDisplayColoredSurfaceSettings
                        coloredSurfaceSettings = new
                                                 AnalysisDisplayColoredSurfaceSettings();

                    coloredSurfaceSettings.ShowGridLines = false;

                    AnalysisDisplayColorSettings colorSettings
                        = new AnalysisDisplayColorSettings();

                    colorSettings.MinColor = new Color(0, 255, 0);
                    colorSettings.MaxColor = new Color(255, 0, 0);

                    AnalysisDisplayLegendSettings legendSettings
                        = new AnalysisDisplayLegendSettings();

                    legendSettings.ShowLegend = true;

                    AnalysisDisplayStyle analysisDisplayStyle
                        = AnalysisDisplayStyle.CreateAnalysisDisplayStyle(
                              doc, _displayStyleName, coloredSurfaceSettings,
                              colorSettings, legendSettings);

                    view.AnalysisDisplayStyleId
                        = analysisDisplayStyle.Id;

                    t.Commit();
                }
            }
        }
Esempio n. 8
0
        private static void CreateAVFDisplayStyle(Document doc, Autodesk.Revit.DB.View view)
        {
            Transaction t = new Transaction(doc, "Create AVF style");

            t.Start();
            AnalysisDisplayColoredSurfaceSettings coloredSurfaceSettings = new AnalysisDisplayColoredSurfaceSettings();

            coloredSurfaceSettings.ShowGridLines = true;
            AnalysisDisplayColorSettings  colorSettings  = new AnalysisDisplayColorSettings();
            AnalysisDisplayLegendSettings legendSettings = new AnalysisDisplayLegendSettings();

            legendSettings.ShowLegend = false;
            string name = "Paint Solid";
            AnalysisDisplayStyle analysisDisplayStyle = new FilteredElementCollector(doc).OfClass(typeof(AnalysisDisplayStyle)).Cast <AnalysisDisplayStyle>().FirstOrDefault(q => q.Name == name);

            if (analysisDisplayStyle == null)
            {
                analysisDisplayStyle = AnalysisDisplayStyle.CreateAnalysisDisplayStyle(doc, name, coloredSurfaceSettings, colorSettings, legendSettings);
            }

            view.AnalysisDisplayStyleId = analysisDisplayStyle.Id;
            t.Commit();
        }
Esempio n. 9
0
        public static ElementId CreateAnalysisScheme(List <AnalysisDisplayColorEntry> colours, Document doc, string name, bool showLegend)
        {
            var result = ElementId.InvalidElementId;

            var colouredSurfaceSettings = new AnalysisDisplayColoredSurfaceSettings();

            colouredSurfaceSettings.ShowContourLines = true;
            colouredSurfaceSettings.ShowGridLines    = false;

            var colourSettings = new AnalysisDisplayColorSettings();

            colourSettings.MaxColor = colours.Last().Color;
            colourSettings.MinColor = colours.First().Color;
            colourSettings.SetIntermediateColors(colours);
            colourSettings.ColorSettingsType = AnalysisDisplayStyleColorSettingsType.GradientColor;

            if (AnalysisDisplayStyle.IsNameUnique(doc, name, null))
            {
                var ads = AnalysisDisplayStyle.CreateAnalysisDisplayStyle(
                    doc,
                    name,
                    colouredSurfaceSettings,
                    colourSettings,
                    new AnalysisDisplayLegendSettings());
                if (!showLegend)
                {
                    ads.GetLegendSettings().ShowLegend = false;
                }
                result = ads.Id;
            }
            else
            {
                result = AnalysisDisplayStyle.FindByName(doc, name);
            }

            return(result);
        }
Esempio n. 10
0
        private static Element createSolidDisplayStyle(Document doc, string name)
        {
            AnalysisDisplayColoredSurfaceSettings style = new AnalysisDisplayColoredSurfaceSettings();

            style.ShowGridLines = true;

            AnalysisDisplayColorSettings colors = new AnalysisDisplayColorSettings();

            colors.ColorSettingsType = AnalysisDisplayStyleColorSettingsType.GradientColor;
            colors.MinColor          = new Color((byte)255, (byte)165, (byte)0);
            colors.MaxColor          = new Color((byte)0, (byte)0, (byte)255); // orange to blue

            // we need to create it
            Element pc =
                AnalysisDisplayStyle.CreateAnalysisDisplayStyle(doc, name,
                                                                style,
                                                                colors,
                                                                new AnalysisDisplayLegendSettings()
            {
                ShowLegend = false
            });

            return(pc);
        }
Esempio n. 11
0
        /// <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;
                }
            }
        }
Esempio n. 12
0
        /// <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;
        }
Esempio n. 13
0
        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();
        }
        /// <summary>
        /// Creates new AnalysisVisualizationStyle for document
        /// </summary>
        /// <returns>TRUE</returns>
        public bool GetOrCreateAVS()
        {
            AnalysisDisplayStyle analysisDisplayStyle = null;

            FilteredElementCollector fec = new FilteredElementCollector(m_doc);
            ICollection<Element> collector = fec.OfClass(typeof(AnalysisDisplayStyle)).ToElements();

            var displayStyle = from element in collector
                               where element.Name == "KTMStyle"
                               select element;

            if (displayStyle.Count() == 0)
            {
                // Set marker settings
                AnalysisDisplayMarkersAndTextSettings markerSettings = new AnalysisDisplayMarkersAndTextSettings();
                markerSettings.MarkerType = AnalysisDisplayStyleMarkerType.Circle;
                markerSettings.MarkerSize = markerSettings.MarkerSize / 2;
                markerSettings.Rounding = 1.0;
                markerSettings.ShowText = true;
                markerSettings.TextLabelType = AnalysisDisplayStyleMarkerTextLabelType.ShowAll;

                // Another FilteredElementCollector
                FilteredElementCollector fecTextNoteType = new FilteredElementCollector(m_doc).OfClass(typeof(TextNoteType));

                foreach (TextNoteType t in fecTextNoteType)
                {
                    if (t.Name.Contains("3/32"))
                        markerSettings.TextTypeId = t.Id;
                }

                // Color settings
                AnalysisDisplayColorSettings colorSettings = new AnalysisDisplayColorSettings();
                Color red = new Color(255, 0, 0);
                Color blue = new Color(0, 0, 255);
                Color green = new Color(0, 255, 0);

                colorSettings.MaxColor = red;
                colorSettings.MinColor = blue;
                IList<AnalysisDisplayColorEntry> map = new List<AnalysisDisplayColorEntry> { new AnalysisDisplayColorEntry(green) };
                colorSettings.SetIntermediateColors(map);

                AnalysisDisplayLegendSettings legendSettings = new AnalysisDisplayLegendSettings();
                legendSettings.NumberOfSteps = 6;
                legendSettings.Rounding = 1.0;
                legendSettings.ShowDataDescription = true;
                legendSettings.ShowLegend = true;

                // Yet another FilteredElementCollector
                FilteredElementCollector fecLegendText = new FilteredElementCollector(m_doc);
                ICollection<Element> elementCol = fecLegendText.OfClass(typeof(TextNoteType)).ToElements();
                var textElements = from element in fecLegendText
                                   where element.Name == "LegendText"
                                   select element;

                if (textElements.Count() > 0)
                {
                    TextNoteType textType = textElements.Cast<TextNoteType>().ElementAt<TextNoteType>(0);
                    legendSettings.TextTypeId = textType.Id;
                }
                // Create AnalysisDisplayStyle
                analysisDisplayStyle = AnalysisDisplayStyle.CreateAnalysisDisplayStyle(m_doc, "KTMStyle", markerSettings, colorSettings, legendSettings);
            }
            else
            {
                analysisDisplayStyle = displayStyle.Cast<AnalysisDisplayStyle>().ElementAt<AnalysisDisplayStyle>(0);
            }

            // Set current view AnalysisDisplayStyleId to newly created
            m_doc.ActiveView.AnalysisDisplayStyleId = analysisDisplayStyle.Id;

            return true;
        }
Esempio n. 15
0
        /// <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();
            }
        }
Esempio n. 16
0
        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);
        }
Esempio n. 17
0
        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();
        }