Material.GetParameterAsString() returns null

Material.GetParameterAsString() returns null

Anonymous
Not applicable
465 Views
3 Replies
Message 1 of 4

Material.GetParameterAsString() returns null

Anonymous
Not applicable

I am porting a material takeoff application from Revit 2014 to 2016. I have managed to catch most of the API changes. Retreiving a parameter valuse from Material is one that is not working like it does in Revit 2014.

 

The UsageId parameter is a string storage type we used in Revit 2014. Material.GetParamaterAsString("UsageId", true) will return the value since it is a string with Revit 2014.

 

Using the same method with the same model with Revit 2016 returns an empty string. I am wondering if I have to use a different method to retreive a material's parameter value?

 

Any ideas why this is different in Revit 2016.

 

Larry

0 Likes
466 Views
3 Replies
Replies (3)
Message 2 of 4

jeremytammik
Autodesk
Autodesk

Dear Larry,

 

Thank you for your query.

 

Have you tried using the much simpler and more direct access to a string value provided by the Parameter.AsString method?

 

As far as I can tell, you should have been using that in the first place.

 

I recommend always using the direct access methods AsString, AsElementId, AsDouble, AsInteger etc.

 

Looking at the Revit 2016 API help file RevitAPI.chm, I do not see any GetParamaterAsString at all.

 

Are you sure that is a standard Revit API method and not an extension method of your own?

 

By the way, looking at it more closely, there is a typo in the name.

 

Do you mean GetParameterAsString?

 

The Revit API does not provide such a method either, though.

 

I hope this helps.

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 4

Anonymous
Not applicable

Hey, 

 

i've just tried the following command and it worked (in Python): 

 

material = [a for a in familyManager.Parameters if a.Definition.Name == 'Structural Material' ][0]
materialId = familyManager.CurrentType.AsElementId( material ) 
materialValue = famDoc.GetElement( materialId ) 

print  materialValue.Name

 

it is probably not the cleanest code, but it get's the job done =P 

cheers~

0 Likes
Message 4 of 4

jeremytammik
Autodesk
Autodesk

I am glad that you found a solution.

 

Yes, definitely not the cleanest or most efficient one.

 

For one, you could replace the first line and the iteration over all parameters by a call to LookupParameter.

 

Secondly, looking up a parameter by name is always a bad idea when it can be avoided.

 

In this case, you can easily use a built-in parameter enumeration value to retrieve the parameter directly with no iteration or name lookup at all.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes