Material or texture associated with a wall.

Anonymous

Material or texture associated with a wall.

Anonymous
Not applicable

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.

0 Likes
Reply
Accepted solutions (1)
1,414 Views
2 Replies
Replies (2)

naveen.kumar.t
Autodesk Support
Autodesk Support
Accepted solution

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

Anonymous
Not applicable

Just what I needed. Thank you very much.

0 Likes