Quick Question about the get material name function

Hello Guys,
im trying to get the name from my material via the id. Like you can see in the picture the id works perfectly fine, however the getmaterialname function gives me this error (pic2). I already tried converting the id into an integer which doens’t work and i tried to get the material with the BuiltInParameter method which also not worked for me. I really would like to get my material name in this way (pic1). Any suggestions? If you have a good yt video which explains the parameter funtions in detailed pleasy link it. Many thanks in advance.


image

I don’t see a “GetMaterialName” method in the API, unless you are you trying to work with fabrication parts? Unlikely though as we see a Wall class used.

Keep in mind that walls and any other element can have have many materials, not just one, and the ‘first’ might not be the one you want. You likely want to take the Material Ids (material_Ids = i.GetMaterialIds(False)) and then iterate over those IDs to get the materials (materialElements = [doc.GetElement(i) for i in material_Ids]) before proceeding to get the name of each material (materialNames = [i.Name for i in materialElements]).

I haven’t tested any of this code, but it should give you some direction.

1 Like

No i think i dont work with fabrication parts. I found the method here: https://www.revitapidocs.com/2024/828e75ce-67c4-be63-65a0-d547c2541d21.htm. The wall id is different for each diefferent wall. I think i dont get what explained to me :confused: Do you mean that the wall could have different layers of material?
It looks now like this:

You have a ] where you should have a ) or a ( where you should have a [ in line 34.

Got it! Works Perfectly fine now, thank you very much. Could you explain one more time why your method is better? Or lets say more sturdy against errors?

The method you linked is for FabricationPartElements, which are not walls. Look at what it falls under in the API documentation you sent. As such it’s not ‘better’, but works as if you provide a family, wall, floor, roof, or just about anything it inherits the Element class, which means we can pull the material IDs, which can be used to get the materials, which can be used to get the material names, all of which will be matching in order so long as you don’t shuffle anything.

1 Like