Change color in Revit model depending on Excel data using Dynamo

Hello,

I’m writing a student paper and I’m new to Dynamo and Revit (or programming at all).

I hav a model in Revit (a substructure of an offshore wind turbine) and data from structure monitoring in Excel. My task is to import and edit the data via Dynamo and connect them with the Revit model.

I have defined limit values for the data. For example the data has a range of 10, my limits are 3 and 7.

For Data (for example data of the bottom tower) between 3 and 7 the bottom of the tower in my Revit model changes the color to green. If the data is less than 3 or more than 7 it should change the color to red. I did this with the logical operators and it works (see the picture)

Now I want to do this with 3 colors (green, yellow, red)

For example:

Range 20

Limits 4, 8, 12, 16

8 to 12 = green

4 to 8 and 12 to 16 = yellow

less than 4 = red, more than 16 = red

But I have no idea how to do this. With visual programming everything has failed. I think I have to use the code block to do this. My idea is

Maybe with

If (test)

-> Change color

elseif (test)

->change color

elseif

…else

But as I am new to programming it fails :smiley:

Can someone help me how to do this?

Thank you

Hi,

Here is the code. Just put it in a CodeBlock :slight_smile: (x is the number you want to test, color1 is green, color2 is yellow, color3 is red).

x>8 && x<12? color1: x>16 || x<4? color3 : color2;

Try running the code by yourself (with a paper and a pen) to better understand how it works ! :smiley:

Btw : a?b:c; means :

" If a is true, output b, otherwise, output c."

You should probably (also) explain that “&&” is a logic AND :wink:
It means that for the statement:
condition1 && condition2 requires that both conditions are true, otherwise it’s false.

@debranox For future reference, you may need to be careful with the ScopeIf - this node can cause problems/crashes if used improperly. Better to use the regular If
The downside of that the latter is that it evaluates both branches regardless of the input but in a case like this that should be no issue. :slight_smile:

1 Like

Yeah, i should have done it :sweat_smile: Btw @debranox , “||” means OR.

Here is a topic that explains the difference :

Hi!

Thanks for the code mellouze. That sounds very logical to me and was also about the idea you I had.
But it still doesn’t work properly. The component is always shown in green, no matter how I choose x. I have tested different variants but it doesn’t make any sense to me. If for example I connect color 1,2,3 only with red it still shows green :smiley:

It was similar with the if node. The result was also different than I expected. So I took the scope if, because it worked right.

After googling a bit about the if command I found this thread. So I tried to do this with my problem and after try and error my code works:

Actually I wanted the color of the component to be changed directly in the return command. But then I had the idea to get the color as output and to connect it with the element.overwrite node. Then I came to the conclusion that I can do the same with the other code as well. So it first didn’t worked as expected because I conncted the nodes wrong :smiley:

Both codes work perfectly now but I think I use mellouze`s because its simpler :wink:

Thanks for your help!

1 Like