How to create a colour code Revit model based on a parameter value

I have created a shared parameter in dynamo to calculate embodied carbon and want to override the colour in Revit based on this parameter, however, I am struggling to develop the code to override the colours correctly. Here is what I have got so far.

Hi @evyjh10 ,

There are basically two 2 approaches to do this:

  1. Split the list of elements into different lists for each different colour and use multiple Element.OverrideColorInView nodes
  2. Using a nested if-statement replace the numbers of the Embodied Carbon values and replace them by the colours you want them to become.

The second approach is a little bit harder to understand but the scalability is a lot better since you only need one Element.OverrideColorInView node.

Here is an example of approach 2:

EmbodiedCarbon <= 2500 ? DSCore.Color.ByARGB(255,255,0,0) :
	EmbodiedCarbon <= 50000 ? DSCore.Color.ByARGB(255,255,128,0) :
		DSCore.Color.ByARGB(255,0,128,0);

The RGB Colours are Red, Orange and Green respectively.

2 Likes

Thanks, this has helped a lot!

2 Likes

One more question, if I was to add more colours in between that range, I would just add more lines of code with “EmbodiedCarbon <= xxxx ? DSCore.Color.ByARGB(xxx,xxx,xx,0) :”?

I added the indentation in the code block to make it easier to understand, it is not needed though.

You could just add another line: (the following 2 code blocks do exactly the same)

EmbodiedCarbon <= 2500 ? DSCore.Color.ByARGB(255,255,0,0) :
	EmbodiedCarbon <= 50000 ? DSCore.Color.ByARGB(255,255,128,0) :
		EmbodiedCarbon <= 100000 ? DSCore.Color.ByARGB(255,255,128,0) :
			DSCore.Color.ByARGB(255,0,128,0);
EmbodiedCarbon <= 2500 ? DSCore.Color.ByARGB(255,255,0,0) :
EmbodiedCarbon <= 50000 ? DSCore.Color.ByARGB(255,255,128,0) :
EmbodiedCarbon <= 100000 ? DSCore.Color.ByARGB(255,255,128,0) :
DSCore.Color.ByARGB(255,0,128,0);

Just make sure the if-statement, since you are checking for <= is adding up the further you go into the if-statement.

1 Like