Get Material's Element

Get Material's Element

Anonymous
Not applicable
5,746 Views
4 Replies
Message 1 of 5

Get Material's Element

Anonymous
Not applicable

Hi ! 

 

I would like to get the material's of somes of my element.

I search on the web to get this, but it's doesn't work with everything.

 

I tried this :

ElementId id = e.get_Parameter(BuiltInParameter.MATERIAL_ID_PARAM).AsElementId();

if (id != null)
{
    Material mat = m_doc.GetElement(id) as Material;
}

But it's doesn't work with floor tile or cope.

 

Do you have something to accomplish what i want ?

 

Regards,

Maxence

0 Likes
Accepted solutions (1)
5,747 Views
4 Replies
Replies (4)
Message 2 of 5

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @Anonymous,

To get the material,

Element e ;
 FootPrintRoof FPR = e as FootPrintRoof; 
foreach(ElementId Mat_id in FPR.GetMaterialIds(false))
                        {
                            Material M = doc.GetElement(Mat_id) as Material;                           
                        }

 Here,

FPR.GetMaterialIds(false)

If GetmaterialIds() is set to false then paint material wont be included

If GetmaterialIds() is set to true then paint material will be included


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 5

Anonymous
Not applicable

Hi @naveen.kumar.t,

 

First, Thanks for reply !

 

Unfortunately, it's give me the same result as mine code.. I didn't get the material for the floor..

What I want to get is the same result as when i do : "nomenclature of material -> floor -> material name" 

 

Regards,

Maxence

0 Likes
Message 4 of 5

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @Anonymous,

Are you trying to get the materials from the floor??

I tried the code that i suggested and it works fine for me

could you please provide some screenshots of floor details to recreate the issue?

(Here your files are not confidential)

 

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 5 of 5

Anonymous
Not applicable
Accepted solution

Hi ! 

 

I just figured out that my last reply didn't send.

 

So I had work on this case, and here what i found :

 

HostObject FPR = e as HostObject;

                    Type tp = FPR.GetType();
                    CompoundStructure structure = null;
                    Debug.WriteLine(tp.Name + "\n");
                    switch (tp.Name)
                    {
                        case "Wall":
                            Wall wall = e as Wall;
                            structure = wall.WallType.GetCompoundStructure();
                            break;
                        case "Floor":
                            Floor floor = e as Floor;
                            structure = floor.FloorType.GetCompoundStructure();
                            break;
                        case "FootPrintRoof":
                            FootPrintRoof roof = e as FootPrintRoof;
                            structure = roof.RoofType.GetCompoundStructure();
                            break;
                        case "Fascia":
                            Fascia fascia = e as Fascia;
                            structure = fascia.FasciaType.GetCompoundStructure();
                            break;
                        default:
                            structure = null;
                            break;
                    }

                    Material material = m_doc.GetElement(structure.GetMaterialId(0)) as Material;

It's working find, but i don't know if I could simplify the code (to don't list all Type)

 

 

0 Likes