Problem with Element.get_Parameter(Builtinparameter) -> returns null

Problem with Element.get_Parameter(Builtinparameter) -> returns null

Anonymous
Not applicable
2,058 Views
3 Replies
Message 1 of 4

Problem with Element.get_Parameter(Builtinparameter) -> returns null

Anonymous
Not applicable

Hello everyone,

 

I am trying to get an element's parameter by using the parameter id. However, it returns null!?

 

By debugging, I am sure that, in my code "bparam" gets created with the provided id. I am also sure that I am looking to the right element which is a Wall and the parameter I'm trying to get is "ANALYTICAL_ABSORPTANCE". So the element definitely has this parameter.

 

Why would the get_parameter method returns null?? What could be the cause? 

 

int pId = -1005435;
BuiltInParameter bparam = (BuiltInParameter) pId;
Parameter p = e.get_Parameter(bparam);
p.SetValueString(value);

 

0 Likes
Accepted solutions (1)
2,059 Views
3 Replies
Replies (3)
Message 2 of 4

RPTHOMAS108
Mentor
Mentor

That's a parameter from an element type such as WallType, so is 'e' an element type (found from the instance via Element.GetTypeId)?

 

The usual reason for that returning null is that the parameter doesn't exist on the element.

0 Likes
Message 3 of 4

SamBerk
Advocate
Advocate
Accepted solution

Hi @Anonymous 

 

Since ANALYTICAL_ABSORPTANCE is a type parameter you have to call get_Parameter from the type element not from the instance element.

 

2 Options:

Option 1 - Cast to Wall type

 

 

Wall wall = e as Wall;
Parameter p = wall.WallType.get_Parameter(bparam);

 

 

Option 2 - Get TypeId

 

 

Element wallType = document.GetElement(e.GetTypeId());
Parameter p = wallType.get_Parameter(bparam);

 

 

 

0 Likes
Message 4 of 4

Anonymous
Not applicable

Thank you very much SamBerk and RPTHOMAS108!!!

0 Likes