Selectively Setting Parameters based on Family Type Using a Combined List of Family Type, Parameters, and Host Element

I am working on a development project that helps to coordinate our Electrical and Mechanical departments at our company. For this project I use a geometry-less family that is called Electrical Equipment Connection. This family gets hosted to a piece of mechanical equipment. The Electrical Equipment Connection is used (with dynamo’s help) to extract data from the mechanical equipment for scheduling as well as a visual reference and tagging on Electrical Sheets.

The Electrical Equipment Connection has 7 different Family Types. The types are Supply Fan, Return Fan, Exhaust Fan, Cooling Tower Fan, Emergency Heating, Boiler Control Power, and Single Point Connection. So, if a piece of mechanical equipment has a supply, return, and exhaust fan, then three Electrical Equipment Connections are placed (one of each respective type). All Electrical Equipment Types have the same parameter fields, listed below.

Electrical Equipment Connection parameters:

Voltage
Phase
HP
Watts
FLA
Minimum Circuit Amperage
Maximum Overcurrent Protection

Here’s the problem I am currently troubleshooting:

The mechanical equipment may be an air handler unit with supply, return, and exhaust fan horsepowers’. For the Supply Fan, I need only the air handler’s “Supply Fan Motor Horsepower [HP]” parameter’s value to be loaded into the Electrical Equipment Connection family with type: Supply Fan “HP” parameter field. This is one of many similar scenarios.

Currently I am using some lists and list.combine to create a list of the connector, host, and all parameters that I need to extract. It’s a nice little list! :slight_smile: Now…I am not sure how to write a code (syntax) that checks the list for the family type, extracts the necessary parameters, and loads them into the respective connection family.

I’ve attached the actual dynamo file, an image of the file, and an image of a brainstorming sketch of what i would like to happen. Hope this makes some sense. Any help would be rad!

ElecMech-DataCollection.dyn (16.9 KB)

You basically want to run an if statement to set parameter values. I’ve beent rhough this before on the forum and it gets messy quick if I have to recreate your problem, so I won’t. Instead I’ll present a hypothetical situation built around doors. Here it goes.

If a door is hosted by a wall who’s name is “Wall 1” than I want to make a comment on the door which matches the width of the wall. If not I don’t want to make any comment.

If the door is hosted by a wall who’s type name is “Wall 2”, than I want to write the walls “Fire Rating” parameter value to the door’s “Fire Rating” parameter. If not, I don’t want to make any comment.

It can be surprisingly difficult to write only some parameters using if statements, instead I take a “write nothing” approach and write “” (or nothing) to the parameter instead of only writing only some of the time. This shouldn’t impact you as you have nothing as a value in either case. My code block looks like this:

/*First Define my inputs
	a is the list of host walls
	b is the list of doors*/

//define my values for comments
CommentVals =
	a.Name=="Wall 1"?
		a.GetParameterValueByName(
			"Width"
		)+"":
			"";
//define my values for Fire Rating
FireRatingVals =
	a.Name =="Wall 2"?
		a.GetParameterValueByName(
			"Fire Rating"
		):
			"";
//Set my values for comments
b.SetParameterByName(
	"Comments",
	CommentVals
);

//set my values for fire rating
b.SetParameterByName(
	"Fire Rating",
	FireRatingVals
);

This quickly and effectively writes the data without getting into crazy deep nested if statements, which is the other option. An example of that can be found here:

Obviously your situation is more complex than this:

  1. You have multiple unit types to deal with, so converting data may be an issue, and an empty string (“”) may not be the best thing to use in all parameters. A null may be better in some cases, or a 0, or just use a string and let it toss an error.

  2. You’ll have quite a few more parameters to deal with (22 in your current list, though you may want to add a GUID or element Id so you an quickly bounce backwards as needed, and perhaps a Date so you know the last time you ran the DYN to set these values). Managing the variables you use will be important as you go along.

Thanks for the detailed response Jacob. Your recommendations have helped me with the syntax for my IF statements as well as setting my variables. I am familiar with writing “real” code in C# and MatLab, but it’s sure been a while so I appreciate your help greatly.

I think though, I will be using the nested IF statements as well as lists, and nested loops as I feel this will a more elegant and efficient method given the amount of variables, types, and hosts. Previously, I had built this using a multitude of GetParam and SetParam and some bool filters to check the family type and Set the correct variables based on the elements type. This became a large “visual” hassle and was difficult to troubleshoot. Not to mention, it wasn’t working due to my poor management of what became a larger list than I had initially designed for.

I will post where I am at later today as I am making further progress with the list. I think it will be quite the tidy little program when said and done. I hope at least. :slight_smile:

1 Like

Ok…Here’s where I’ve gotten to since the last post. I had some trouble creating my list of host parameters with the hierarchy that I was looking for so I brute forced the monster. There must be a more graceful way (replicators…I need to get a grasp on these).

I am getting this dynamo error and am stuck at this point. I assume the answer lies somewhere in my code block of nasty nested loops of an “if” statement that searches through the param lists.

Any advice is appreciated.

eConnDataCollect.txt (633 Bytes)

ElecMech-DataCollection (2).dyn (28.6 KB)