<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Create view with coloured elements in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/create-view-with-coloured-elements/m-p/7997420#M50185</link>
    <description>&lt;P&gt;As Jeremy suggests&amp;nbsp;visibility filters are a good suggestion but if you have a lot of variation i.e. beam sizes then you don't want lots of rules to achieve this.&amp;nbsp;Such would be added to the UI and would then be hard for the user to find their ones within the generated ones.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What you are asking is possible and would work with either 'consistent colors' or 'shaded'. Disadvantage of overriding per view is you'd have to update it when new elements are created in the view via DMU etc. I have a routine that colours by&amp;nbsp;beam sizes it's clear to the user that you run it at&amp;nbsp;one point in time and if you need the view updated you run it again (that workflow is simple enough). For checking sizes or depths of beams is a good visual indicator.&lt;/P&gt;</description>
    <pubDate>Sat, 12 May 2018 11:51:17 GMT</pubDate>
    <dc:creator>RPTHOMAS108</dc:creator>
    <dc:date>2018-05-12T11:51:17Z</dc:date>
    <item>
      <title>Create view with coloured elements</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/create-view-with-coloured-elements/m-p/7995193#M50183</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to create a view where all elements are colored depending on some parameters.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've successfully created a view with the view style = shaded. Then I've tried to &lt;U&gt;set&lt;/U&gt; a certain colour to the elements, but I'm only able to do that &lt;STRONG&gt;IF&lt;/STRONG&gt; I read the materials in each element and then set the colour for each material in that element.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Fig 1" style="width: 363px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/499278iE104CE20D132719C/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.JPG" alt="Fig 1" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Fig 1&lt;/span&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Fig 2" style="width: 360px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/499279iE65EDEF89044D499/image-size/large?v=v2&amp;amp;px=999" role="button" title="2.JPG" alt="Fig 2" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Fig 2&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;If I right-click the element and select 'Override Graphics in View&amp;gt;By Element', the windows on top will appear. As, by default, the surface patterns are set 'by material', this means that I have to change the colours of each material in the element. What I would like to do is to set the pattern to 'solid fill', so that I don't need to change the colour of each material.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't know if I'm being clear enough.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 May 2018 11:35:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/create-view-with-coloured-elements/m-p/7995193#M50183</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-05-11T11:35:39Z</dc:date>
    </item>
    <item>
      <title>Re: Create view with coloured elements</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/create-view-with-coloured-elements/m-p/7995469#M50184</link>
      <description>&lt;P&gt;Before you do anything programmatically, you should always study the SDK samples.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Even before that, you should research the optimal approach manually through the user interface.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case, I believe that a view filter will achieve almost exactly what you are trying to do with a minimum of effort and maximum efficiency.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that is indeed the case,&amp;nbsp;the&amp;nbsp;ElementFilter/ViewFilters sample will be of especial interest to you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jeremy&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 May 2018 13:23:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/create-view-with-coloured-elements/m-p/7995469#M50184</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2018-05-11T13:23:30Z</dc:date>
    </item>
    <item>
      <title>Re: Create view with coloured elements</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/create-view-with-coloured-elements/m-p/7997420#M50185</link>
      <description>&lt;P&gt;As Jeremy suggests&amp;nbsp;visibility filters are a good suggestion but if you have a lot of variation i.e. beam sizes then you don't want lots of rules to achieve this.&amp;nbsp;Such would be added to the UI and would then be hard for the user to find their ones within the generated ones.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What you are asking is possible and would work with either 'consistent colors' or 'shaded'. Disadvantage of overriding per view is you'd have to update it when new elements are created in the view via DMU etc. I have a routine that colours by&amp;nbsp;beam sizes it's clear to the user that you run it at&amp;nbsp;one point in time and if you need the view updated you run it again (that workflow is simple enough). For checking sizes or depths of beams is a good visual indicator.&lt;/P&gt;</description>
      <pubDate>Sat, 12 May 2018 11:51:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/create-view-with-coloured-elements/m-p/7997420#M50185</guid>
      <dc:creator>RPTHOMAS108</dc:creator>
      <dc:date>2018-05-12T11:51:17Z</dc:date>
    </item>
    <item>
      <title>Re: Create view with coloured elements</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/create-view-with-coloured-elements/m-p/8000488#M50186</link>
      <description>&lt;P&gt;Thank you very much Jeremy and&amp;nbsp;RPTHOMAS108,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've found a solution that suits me based on your input. I'll paste it here in case someone else wants to reuse it:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;IEnumerable&amp;lt;ViewFamilyType&amp;gt; viewFamilyTypes = from elem in new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType))&lt;BR /&gt; let type = elem as ViewFamilyType&lt;BR /&gt; where type.ViewFamily == ViewFamily.ThreeDimensional&lt;BR /&gt; select type;&lt;BR /&gt;&lt;BR /&gt;//And then open transaction&lt;BR /&gt; using (Transaction trans = new Transaction(doc, "name"))&lt;BR /&gt; {&lt;BR /&gt; trans.Start();&lt;BR /&gt;&lt;BR /&gt;//create view
                    View3D new3D = View3D.CreateIsometric(doc, viewFamilyTypes.First().Id);                   
                    new3D.Name = "Name";
                    
                    //Set Visual Style to Shaded = 4
                    new3D.get_Parameter(BuiltInParameter.MODEL_GRAPHICS_STYLE).Set(4);

                    OverrideGraphicSettings graphics = new OverrideGraphicSettings();
                    //set the transparency
                    graphics.SetSurfaceTransparency(60);
                    //define the level of detail
                    graphics.SetDetailLevel(ViewDetailLevel.Coarse);
                    int index = 0;

                    //=========================== Verifications =========================== 
                    foreach (Element element in totalElements)
                    {
                        
                        //max and minimum of indicator
                        double max = LISTA.Max();
                        double min = LISTA.Min();

                        double indicator = LISTA[index]; //in here I do the verification and withdraw the value from a list
                        //set the color
                        Autodesk.Revit.DB.Color color = new Autodesk.Revit.DB.Color(0, 0, 0);
                        if (indicator &amp;gt; 4 / 5 * (max - min))
                        {
                            color = new Autodesk.Revit.DB.Color(255, 69, 0); // Orange Red
                        }
                        else if (indicator &amp;gt; 3 / 5 * (max - min))
                        {
                            color = new Autodesk.Revit.DB.Color(255, 165, 0); // Orange
                        }
                        else if (indicator &amp;gt; 2 / 5 * (max - min))
                        {
                            color = new Autodesk.Revit.DB.Color(255, 255, 224); // Light yellow
                        }
                        else if (indicator &amp;gt; 1 / 5 * (max - min))
                        {
                            color = new Autodesk.Revit.DB.Color(173, 255, 47); // Green yellow
                        }
                        else
                        {
                            color = new Autodesk.Revit.DB.Color(0, 128, 0); // green
                        }
                        //set the color
                        graphics.SetProjectionFillColor(color);

                        //and then fill the Patern as 'Solid Fill'
                        //a) find the solid fill Id
                        List&amp;lt;FillPatternElement&amp;gt; fillPatternList = new FilteredElementCollector(doc).WherePasses(new ElementClassFilter(typeof(FillPatternElement))).
                ToElements().Cast&amp;lt;FillPatternElement&amp;gt;().ToList();
                        ElementId solidFillPatternId = null;

                        foreach (FillPatternElement fp in fillPatternList)
                        {
                            if (fp.GetFillPattern().IsSolidFill)
                            {
                                solidFillPatternId = fp.Id;
                                break;
                            }
                        }
                        //b) set the id
                        graphics.SetProjectionFillPatternId(solidFillPatternId);
                        //and finally I override the graphic settings of the element
                        new3D.SetElementOverrides(element.Id, graphics);
                        index = 0;
                    }&lt;BR /&gt; trans.Commit();&lt;BR /&gt; }&lt;BR /&gt; MessageBox.Show("Views created.");&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it is highly likely this code can be simplified, but it worked for me for now.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;Ruben&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 14:47:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/create-view-with-coloured-elements/m-p/8000488#M50186</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-05-14T14:47:59Z</dc:date>
    </item>
    <item>
      <title>Re: Create view with coloured elements</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/create-view-with-coloured-elements/m-p/8002335#M50187</link>
      <description>&lt;P&gt;Dear Ruben,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for the interesting sample code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do not see where the individual element is queried so that you can decide the appropriate colour for it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On one hand, you iterate over the elements using `foreach (Element element in totalElements)`.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On the other, you determine the `indicator = LISTA[index]` and say, 'in here I do the verification and withdraw the value from a list'.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Where does index come from?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there some code missing in between?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For instance, maybe the `index` could be read from a parameter value on the element?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for clarifying!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jeremy&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 May 2018 08:50:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/create-view-with-coloured-elements/m-p/8002335#M50187</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2018-05-15T08:50:09Z</dc:date>
    </item>
    <item>
      <title>Re: Create view with coloured elements</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/create-view-with-coloured-elements/m-p/8002403#M50188</link>
      <description>&lt;P&gt;Dear Jeremy,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically I created a list of total elements in the project using one of your codes (thank you!):&lt;/P&gt;&lt;PRE&gt; public List&amp;lt;Element&amp;gt; GetElementsProject(Document document)
        {
            Dictionary&amp;lt;string, Category&amp;gt; categories = new Dictionary&amp;lt;string, Category&amp;gt;();
            FilteredElementCollector collector = new FilteredElementCollector(document);//elementCollector will filter all elements in the project (i.e. doc)
            collector.WhereElementIsNotElementType().WhereElementIsViewIndependent().ToElements();
            List&amp;lt;Element&amp;gt; elements = new List&amp;lt;Element&amp;gt;();
            foreach (Element element in collector)
            {
                //make sure that, if the element is null, then I will not consider it (otherwise it would give errors later on)
                ElementType elementtype = document.GetElement(element.GetTypeId()) as ElementType;
                if (elementtype is null)
                    continue;
                if (null != element.Category
                  &amp;amp;&amp;amp; 0 &amp;lt; element.Parameters.Size
                  &amp;amp;&amp;amp; (element.Category.HasMaterialQuantities))
                {
                    if (!categories.ContainsKey(
                      element.Category.Name))
                    {
                        categories.Add(
                          element.Category.Name,
                          element.Category);
                    }
                    elements.Add(element);
                }
            }
            return elements;
        }&lt;/PRE&gt;&lt;P&gt;I think I just added a line where I make sure that, if an element type is null, I will ignore it (otherwise it would crash my code).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I query each element in that list (using the foreach block). Before the foreach block I create an instance &lt;STRONG&gt;int index =0;&lt;/STRONG&gt; which, in the end of the foreach loop, I will add a value to it. &lt;U&gt;Basically I could replace the 'foreach' with a 'for' block &lt;/U&gt;(still learning programming!). The index allow me to screen each variable inside the lists (e.g. ListA[index];), it isn't related with the parameter value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I have is List_A, which contain the name of all elements, and then List_B, which contains a &lt;SPAN&gt;Parameter_Value&lt;/SPAN&gt; also for all elements. &lt;U&gt;So they have the same size&lt;/U&gt;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;E.g. index = 0; I will obtain the first instance in List_A (e.g. Wall1) and corresponding parameter &lt;SPAN&gt;in List_B&amp;nbsp;&lt;/SPAN&gt;(e.g. PV = 2), then index=1; I will obtain the second instance in List_A (e.g. Door1) and corresponding parameter in List_B (e.g. PV=5), and so on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, before the colouring, I've checked the max and min value in List_B. Then, the 'foreach' block will compare the Parameter_Value in each element with the max and min values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope I've clarified the code a bit more now. If not, just let me know!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;Ruben&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 May 2018 09:14:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/create-view-with-coloured-elements/m-p/8002403#M50188</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-05-15T09:14:06Z</dc:date>
    </item>
    <item>
      <title>Re: Create view with coloured elements</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/create-view-with-coloured-elements/m-p/8002463#M50189</link>
      <description>&lt;P&gt;By the way, when I migrated the code to Revit 2019 I noticed some functions were/will be obsolete. These are:&lt;/P&gt;&lt;PRE&gt;//these are obsolete
graphics.SetProjectionFillColor(color);
graphics.SetProjectionFillPatternId(solidFillPatternId);
//you can replace by these ones
graphics.SetSurfaceForegroundPatternColor(color);
graphics.SetSurfaceForegroundPatternId(solidFillPatternId);

&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 May 2018 09:41:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/create-view-with-coloured-elements/m-p/8002463#M50189</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-05-15T09:41:47Z</dc:date>
    </item>
  </channel>
</rss>

