Override Element Color depending on Project parameter value intervals

Hello! I’m working on my master thesis where one of my objectives is to color code certain elements depending on how certain project parameters fall within value intervals. This meaning, for example, if a parameter has a value between 1 and 2 it colors green, between 3 and 4 orange, between 4 and 5 red. If anyone can help it would be very appreciated! I’m new to dynamo and sort of new to Revit, and I’ve been teaching myself to get through my thesis but in this aspect I’m a bit stuck…

Thank you for your time

Hello and welcome to the forum!

Have you thought about searching the forum a bit?

Also check out DiRoots Plugin, might already do what you want.

Good luck with your thesis!

Hello!

Yes I have been searching the forum for a few days and came up with some similar problems to mine but no quite enough in order for me to pull something for my work :confused:

I will check out the Pugin, thank you for your help!

King regards

Hey,

To get a hang of things with dynamo try the dynamo primer:

Above posted link provides a simple way of doing it via dynamo.
It will need to be adapted to your parametername and element category. So in essence to your project.

Try to get it going by yourself and if you get stuck somewhere on the way feel free to respond here again.

1 Like

Hi,

Here’s an example of how to get started using Python and the bisect library, to assign a color according to a range of values

import clr
import sys
import bisect
from bisect import bisect_left, bisect_right
import System
clr.AddReference("System.Numerics")

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS

#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB

#import net library
from System import Array
from System.Collections.Generic import List, IList, Dictionary

#import transactionManager and DocumentManager (RevitServices is specific to Dynamo)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument


def get_color_by_interval(value, interval_values=[], color_values=[]):
    """
    Assigns color based on the input value interval.

    Args:
    value (float): The input value to assign a color to.
    interval_values (List): A list of interval values to determine color assignment.
    color_values (List): A list of color values corresponding to the interval values.

    Returns:
    str: The color assigned to the input value.
    """
    i = bisect_right(interval_values, value)
    return color_values[i-1]


def assign_colors_to_elements(lst_elems, parameterName, interval_values, color_values):
    """
    Assigns colors to elements based on the given parameter value.

    Args:
    lst_elems (List): List of elements to assign colors to.
    parameterName (str): The parameter name to retrieve values from elements.
    interval_values (List): A list of interval values to determine color assignment.
    color_values (List): A list of color values corresponding to the interval values.

    Returns:
    List: A list of elements with assigned colors.
    """
    out = []
    for elem in lst_elems:
        para = elem.LookupParameter(parameterName)
        if para is not None:
            paraValue = float(para.AsValueString())
            ds_color = get_color_by_interval(paraValue, interval_values, color_values)
            out.append([elem, paraValue, ds_color])
    return out


toList = lambda x : UnwrapElement(x) if isinstance(x, list) else UnwrapElement([x])
lst_elems = toList(IN[0])
parameterName = IN[1]
interval_values = toList(IN[2])
color_values = toList(IN[3])

OUT = assign_colors_to_elements(lst_elems, parameterName, interval_values, color_values)
2 Likes