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

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.