If Statement/ Updating the Revit Parameter

Dear friends
I am proposing a workflow to integrate thermal comfort monitoring of a building into the BIM model by Dynamo. For defining a threshold I want to use “If/Then” statement in Dynamo, but I don’t exactly know how to do that. I defined two parameters, Temperature and Humidity, for Rooms category and want to make the following If statement in Dynamo for these two parameters:

Relative humidity Acceptable Operating Temperature
If 30% then 24.5 - 28 °C
If 60% then 23 - 25.5 °C

If the temperature value is not within the range in any above condition, then I want to use “Element.SetParameterByName” node to update a parameter defined for room namely “Thermal Comfort Condition” and make it “Exceeded Level”. Can anybody help me by showing me the workflow needed for this process? Thank u so much in advance

1 Like

There’s an If node that takes a boolean check and both a True conditional and False conditional. Try playing around with it and see if you can get somewhere. If you get stuck, post an image of your graph and the problems you’re having. That will help us know how we can help you.

1 Like

In a code block:

Test ? ResultIfTrue : ResultIfNot;

The ? and : define the separation between items.

Feeding a list of 0, 1, 2, 3 into the following:

A>1? “BIGGER THAN AN INDIVIDUAL” : “an individual or none”

Would return:
“an individual or none”
“an individual or none”
“BIGGER THAN AN INDIVIDUAL”
“BIGGER THAN AN INDIVIDUAL”

You can also use designscript to run functions like setting the parameter in the ResultIfTrue : ResultIfFalse portion of the statement.

In your case you have two tests to run, so aid the first wasn’t true start right up on the second. Below is a similar example to yours, where A is an input for the temperature, MaxTemp is an input for the maximum allowable temp, B is the element list, “ThermalComfort” is the name of the parameter which stores a string, and MinTemp is the minimum allowable temp.

A>MaxTemp?
B.SetParameterByName(“ThermalComfort”, “Too hot - turn up the AC!” :
A<MinTemp? B.SetParameterByName(“ThermalComfort”,“Too cold - turn on the heat!” :
B.SetParameterByName(“ThermalComfort”, “Just right - Goldilocks will be happy! Well at least with the temperature.”)

2 Likes

It actually seems like you don’t even need an If node since you’re only doing something to the rooms that do not meet their operating temperatures. So really you just need to filter your rooms down to those that fail their requirements.

3 Likes

Thanks Jacob for your response and explanations.

Could you please show your solutions in the code block? I played a little with if node as shown in the attached picture. As can be seen, there is a problem. In the second part of if statement I used (>). The humidity level (x) is 71.14% and y is 70, but under if node it says that it is not true ( x (71.14) > y (70) is true). Could u please tell me why it was not recognized true while the first if node worked correctly.

I have also another question. I think using “if node” several times does not work for me, since I have several if condition and I should use (If Then Else) using code blocks or etc. You said that I can also use designscript to run functions. Could you explain it to me by showing a sample in Dynamo? Thank u so much for your helps.

Thank u Nick for your response. I posted an image of my graph. Anyway, I should I have to use a code block since it is a multi-conditional problem. Could you please give me your comments. Thanks.

Make sure 71.44 is a number and not a string.

Try something like this:

2 Likes

Thank you so much dear Nick for your quick response

I looked at your graph. But there is no list. There was a list of humidity and temperature but only the maximum values were extracted to update the BIM model as shown in the attached images. In your graph how can I consider only one value (which is the max temperature and humidity in my case) in the workflow? Thanx

1

I used this to make a quick version of your dataset:

Capture

From there I ran this script:

Which is basically just this code:
//first define the variables
rooms;

RH =
	rooms.GetParameterValueByName(
		"Humidity"
	);

Temp =
	rooms.GetParameterValueByName(
		"Temperature"
	);
RH30Min = 24.8;
RH30Max = 28;
RH60Min = 23;
RH60Max = 25.5;

//then do some logic work

CalculatedWorkingRange =
	//if the RH is 30
	RH == 30?
		//is the temp less than the min?
		Temp < RH30Min?
			"Too Cold!":
			//if not is the temp over the max?
			Temp > RH30Max?
				"Too Hot!":
				//if not the temp is good
				"Just Right!":
	//if the RH is 60...
	RH == 60?
		//is the temp less than the max?
		Temp<RH60Min?
			"Also Too Cold!":
			//if not is the temp over the max?
			Temp>RH60Max?
				"Also Too Hot!":
				//if so than the temp is good
				"Also Just Right!":
	// but if the RH was neither 60 nor 30...
	"Your condensation is showing";

//and set my parameter value with my result
rooms.SetParameterByName(
	"Working Range Check",
	CalculatedWorkingRange
);

And got this result:

Capture

3 Likes

I’m not sure I understand your issue. Instead of checking a list of values (temps and RHs) you’re only checking to see if the maximum falls within the allowable range? The graph I posted should handle a single item the same way it handles a list.

1 Like

I don’t know how I can thank you. Thank u so much for your time dear friends. I used your code block and it worked. I need to do a small modifications on my initial conditions.

Actually I have to use the following condition:

Relative humidity Acceptable Operating Temperature
(Summer)
If 30 =< RH <60 24.5 - 28 °C
If 60=< RH <70 23 - 25.5 °C

                                    (Winter)                                               

If 30 =< RH <60 20.5 - 25.5 °C
If 60=< RH <70 20 - 24 °C

For summer and Winter, I think I can define a type project parameter (e.g “Season”) which can be same for all rooms of a building. In Winter time, we can assign manually Winter and during summer we can assign Summer to this parameter. But Could u please modify your code blocks based on this conditions.

For the first part:
If 30 =< RH <60 24.5 - 28 °C
If 60=< RH <70 23 - 25.5 °C
I did some modifications but I think it is not correct (See the attached image). Your helps to modify your previous script based on new conditions (Winter & Summer) is kindly appreciated. Thank u again for all your helps.

1 Like

I attached an image of the new conditions which is clearer. Thank u so much

4

Thank you so much Nick for your help. Yes. I am gonna check only the maximum value to see whether it is in the range or not

Dear friend

I am so sorry to bother you, but could u please help me to modify your script based on the new conditions? Thank u so much for your helps

I don’t really understand what you are after anymore. Is it two separate parameter values (one winter and one summer) with a single value for each element? Do some units only need only the winter value and some need only the summer value? Is it one parameter with a single value like: “winter ok, summer not ok”? For what it’s worth two values in one parameter is a less than ideal means of communicating the intent.

Hard to know how to help if I don’t really understand the output. If you clarify I might be able to squeeze this in.

Also I’m not around the computer much this weekend (long holiday weekend for me), and when I will be I’ll likely have my hands full with my own projects. I may have a bit of time depending on the train schedule, friend’s arrival times, and the like.

Basically, don’t count on it coming in to save the day if you’re on a deadline.

1 Like

@jacob.small I know that you are so busy and thank u so much for your time. For this condition (Winter and Summer), I defined a project parameter namely “Season”. The script needs to be like this:
If “Summer” is assigned to “Season” parameter, then the condition of Summer (RH and Temperature) as shown in above table should be met, and if “Winter” is assigned to “Season” parameter, then the condition of Winter should be met. For this case, Summer and Winter are assigned manually to “Season” parameter as shown in attached images.

If the above situation can be defined in a script it will be great. But if it is time consuming, don’t spend your time and I don’t want to get your time my friend. Only the following condition as shown in the image is good for me.

Thank u so much again for your time and cooperation.

Regards

4

Ah! So you need to use a condition to set the value of the min and max temperatures. Sounds like a fun little diversion and an exercise I can learn from. I’ll try to get to it this weekend.

1 Like

:slightly_smiling_face::relaxed:

Thank you so much dear friend for your time.

Try this.

//first define the variables
RoomSeason =
	Rooms.GetParameterValueByName(
		"Season"
	);
RoomRH =
	Rooms.GetParameterValueByName(
		"Humidity"
	);
RoomTemp =
	Rooms.GetParameterValueByName(
		"Temperature"
	);
WinterRH30Range =
	{20.5,25.5};
WinterRH60Range =
	{20,24};
SummerRH30Range =
	{24.5,28};
SummerRH60Range =
	{23,25.5};

/*get the minimum temp for each space based
on season and RH*/
MinTemp =
	RoomSeason == "Winter"?
		RoomRH == 30?
			WinterRH30Range[0]:
			WinterRH60Range[0]:
		RoomSeason == "Summer"?
			RoomRH==30?
				SummerRH30Range[0]:
				SummerRH60Range[0]:
		"No Season";

/*get the maximum temp for each space based
on season and RH*/
MaxTemp =
	RoomSeason == "Winter"?
		RoomRH == 30?
			WinterRH30Range[1]:
			WinterRH60Range[1]:
		RoomSeason == "Summer"?
			RoomRH==30?
				SummerRH30Range[1]:
				SummerRH60Range[1]:
			"No Season";

/*Check the temp against the min and max temp,
and define a string accordingly*/
GetWorkingRangeCheck =
	RoomTemp<MinTemp?
		"Too Cold":
		RoomTemp>MaxTemp?
			"Too Hot":
			"Just Right";

//Set the working range check value
	Rooms.SetParameterByName(
		"Working Range Check",
		GetWorkingRangeCheck
	);

Wound up being easier to set a define a variable for min and max temp for each room in the list, based on the season and the RH, then compared that value to the room temperature, and set the working range check based on the result. Unlike the last node, this doesn’t allow for string outputs based on RH, season, etc, but simply says “too hot”, “too cold”, or “just right” instead. If you need that level of specificness you’ll have to modify it accordingly.

3 Likes