Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Material or texture associated with a wall.

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Anonymous
1357 Views, 2 Replies

Material or texture associated with a wall.

Hi.

In Revit SDK 2019. I am trying to recover the ID or name of the materials used in the walls of a project to then make budgets according to the price per square meter of the material and the area of ​​the wall. 

 

  public void SetTypeParameter(Document doc)
        {
   
            Element e = FindElementByName(doc, typeof(Material), "SW48");
            UIDocument uidoc = new UIDocument(doc);
            Reference myRef = uidoc.Selection.PickObject(ObjectType.Element, "Selecciona un elemento");
            Element m = doc.GetElement(myRef);
            Wall pared = doc.GetElement(m.Id) as Wall;
  
            Material material = doc.GetElement(e.Id) as Material;
            double total;

           
            foreach (Parameter para in pared.Parameters)
            {
                TaskDialog.Show("revit", para.Definition.Name + " - " + para.AsValueString());
            }

            try
            {
                using (Transaction t = new Transaction(doc, "Set Type"))
                {
                    t.Start();
                    Parameter p = material.get_Parameter(BuiltInParameter.ALL_MODEL_COST);
                    Parameter area = pared.get_Parameter(BuiltInParameter.HOST_AREA_COMPUTED);
                    string MyString =area.AsValueString();
              
                    string NewString = MyString.Remove(2,3);
                   

                    total = ((p.AsDouble() * Convert.ToDouble(NewString)));
                    p.Set(360);
                    TaskDialog.Show("Precio", "Precio del material por m2: " + p.AsValueString()+"\n Area total del muro: "+area.AsValueString()+"\n Precio total: $"+total );
                    t.Commit();
                }   
            }
            catch (Exception ex)
            {
                TaskDialog.Show("error ", ex.Message);
            }
        }

In the code, I manually recover the cost of the "SW48" material. Is there a way that when selecting the wall I recover the material that is being used? Thank you.

2 REPLIES 2
Message 2 of 3
naveen.kumar.t
in reply to: Anonymous

Hi @Anonymous,

try the below code

 Element e;
IList<Material> MS = new List<Material>();
                    Wall w = e as Wall;
                    if(w!=null)
                    {
                        IList<ElementId> mat_ids = w.GetMaterialIds(true) as IList<ElementId>;
                        foreach(ElementId mat_id in mat_ids)
                        {
                            Material M = doc.GetElement(mat_id) as Material;
                            MS.Add(M);

                        }
                    }

If you want the  wall paint material to be excluded then

w.GetMaterialIds(false)

else if you want the wall paint material to be included then

 w.GetMaterialIds(true)

Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 3 of 3
Anonymous
in reply to: naveen.kumar.t

Just what I needed. Thank you very much.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community