How to change wall material.

How to change wall material.

Anonymous
Not applicable
2,151 Views
3 Replies
Message 1 of 4

How to change wall material.

Anonymous
Not applicable

I want to change all wall material is "Precast Wall Status 1 (DS)".

-------------------------------------

FilteredElementCollector assCollector = new FilteredElementCollector(doc).OfClass(typeof(AssemblyInstance));
    foreach(Element el in assCollector){
      ElementFilter EF = new ElementClassFilter(typeof(FamilyInstance));
      IList<ElementId> dependentElementIDS = el.GetDependentElements(EF) as IList<ElementId>;
      foreach(ElementId dependentElementID in dependentElementIDS){
        Element elem = doc.GetElement(dependentElementID);
        if (elem.Name == "type-aw"){
          ElementType elemType = doc.GetElement(elem.GetTypeId()) as ElementType;
          elemType.LookupParameter("Structural Material").SetValueString("Precast Wall Status 1 (DS)");
        } // if
    } //foreach
}/foreach

 

-------------------------------------
Thank you.

22-11-2563 11-50-22.png

0 Likes
Accepted solutions (1)
2,152 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

I have writen a program about changing wall material in python, and the code may be helpful for you.

The funciton used can be found in Revit API docs.

def change_wall_material(self,wall, m_Id):# m_Id means the Id of Target material
if wall.GetType().ToString() == 'Autodesk.Revit.DB.Wall':
wall = wall.WallType
marks = wall.GetCompoundStructure()
if marks:
marks.SetMaterialId(0, ElementId(m_Id))#Change the material of first layer of wall
wall.SetCompoundStructure(marks)
I = wall.GetCompoundStructure()
print(I.GetLayers()[0].MaterialId)

 

Message 3 of 4

so-chong
Advocate
Advocate
Accepted solution

Hi,

As these walls are "Model-In-Place" elements (not created by Wall system families) you could write something like this (macro c#)

public void ChangeWallStructuralMaterial()
{
    Document doc = this.ActiveUIDocument.Document;

	    using (Transaction t = new Transaction(doc, "Change Wall Structural Material"))
	    {
		 t.Start();
		
		 List<FamilyInstance> walls = new FilteredElementCollector(doc)		 
			.OfClass(typeof(FamilyInstance))
			.OfCategory(BuiltInCategory.OST_Walls)		 	
		    .Cast<FamilyInstance>()
			.ToList();
		 
   		 Material mat = new FilteredElementCollector(doc)
	        .OfClass(typeof(Material))
	        .Cast<Material>()
	        .FirstOrDefault(q => q.Name == "Precast Wall Status 1 (DS)") as Material; 
		   	
        foreach (Element wall in walls)
        {			        	
        	ElementId elemTypeId = wall.GetTypeId();
			ElementType elemType = (ElementType)doc.GetElement(elemTypeId);
            elemType.LookupParameter("Structural Material").Set(mat.Id);
        }
        
    	t.Commit();
	   }						
}

 wall_model-in-place.png

Message 4 of 4

Anonymous
Not applicable

Thank you very much.

0 Likes