Setting Built in Parameter by using a Variable value

Hi All,

I am wanting to pass in my built in parameter key as a string variable as opposed to just hard coding it in like below. Essentially I want to be able to pass what my matching parameter value is from outside the python script, so I can change it just within a code block in dyanmo.

wall_parameter_value wall.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_COMMENTS).AsString()

I assume that because it actually calling something, I obviously cant just write my variable as a string like below:

BaseMatch_Parameter_Key = “ALL_MODEL_TYPE_COMMENTS”

But when I try and just set the variable but don’t use commas, it throws an error in the script.

thanks sam

One thing I’d like to check : Are you calling the get_Parameter method on a wall or a wall type ?

According to your answer the appropriate BuiltInParameter will be ALL_MODEL_INSTANCE_COMMENTS or ALL_MODEL_TYPE_COMMENTS.

Also, if you can provide us the error message it would be helpful to understand.

Not sure if this is what you’re after, but you can create a dictionary from an Enum:

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import BuiltInParameter
from System import Enum

key = IN[0]

names = Enum.GetNames(BuiltInParameter)
values = Enum.GetValues(BuiltInParameter)

bip_dict = dict(zip(names, values))
bip = bip_dict[key]

OUT = bip

I am call it from built in category OST_Walls, so I assume this is just all wall instances in the project. I am corrct in saying filtering by this paramter just calls all walls in a project?

From there, I want to then filter by the type comments.

So when I try and pass the following in:

BaseMatch_Parameter_Key = “ALL_MODEL_TYPE_COMMENTS”

OPTION 01
wall_parameter_value = wall.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_COMMENTS).AsString()

OPTION 02
wall_parameter_value = wall.get_Parameter(BuiltInParameter.BaseMatch_Parameter_Key ).AsString()

If I use option 01, where I hard code it in, it works and sends back what I expect, if I pass i the parameter, where I list the built in parameter as a string, the code runs, but it does not pass back the walls that should match.

Sam

@cgartland @ lkichenin

Essentially I just want to be able to pass in the parameter like you have done through dynamo, and to do as per below:

input = [0]

wall.get_Parameter(BuiltInParameter.input).AsString()

But it doesn’t seem to like it as a built in parameter when I pass it in as a string…

Sam

Right, if you simply pass in a string it is not a BuiltInParameter. Here’s a rewritten example:

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import BuiltInParameter
from System import Enum

key = 'ALL_MODEL_TYPE_COMMENTS'

names = Enum.GetNames(BuiltInParameter)
values = Enum.GetValues(BuiltInParameter)

bip_dict = dict(zip(names, values))
# Returns a BuiltInParameter given its name (key)
bip = bip_dict[key]

# Assume wall is a valid Element
param = wall.Parameter[bip]
param_value = param.AsString()

In your above example, BaseMatch_Parameter_Key is not a member of the BuiltInParameter Enum. Members are accessed by their name, such as BuiltInParameter.ALL_MODEL_TYPE_COMMENTS, but this is not a string. If that were the case, it would be written as BuiltInParameter.“ALL_MODEL_TYPE_COMMENTS”. So, it isn’t possible to replace one of the member names with a string in that manner. The process I have illustrated above creates a dictionary where the keys are the member names and the values are the corresponding BuiltInParameter values.

{ 
'PATH_OF_TRAVEL_FROM_ROOM': BuiltInParameter.PATH_OF_TRAVEL_FROM_ROOM,
'PATH_OF_TRAVEL_TO_ROOM': BuiltInParameter.PATH_OF_TRAVEL_TO_ROOM,
'STEEL_ELEM_PROFILE_VOLUME': BuiltInParameter.STEEL_ELEM_PROFILE_VOLUME
etc...
}

@cgartland
That is great thankyou!

It worked perfectly, so based on that I now know that the getnames returns the built ins as string and thats how I can call it as a dictionary.

The only thing that I got caught on what trying to output the dictionary… but then I realised reading how iron python has issues with dictionaries! so just didnt output it and had no issues.

Thankyou for your help and clear explanations!

Sam