方法一:Dynamo
当材质参数为类型参数时
当材质参数为实例参数时
方法二:Revit API
void ChangeElementMaterial( Document doc, ElementId id ) { Element e = doc.GetElement( id ); if( null != e.Category ) { int im = e.Category.Material.Id.IntegerValue; List<Material> materials = new List<Material>( new FilteredElementCollector( doc ) .WhereElementIsNotElementType() .OfClass( typeof( Material ) ) .ToElements() .Where<Element>( m => m.Id.IntegerValue != im ) .Cast<Material>() ); Random r = new Random(); int i = r.Next( materials.Count ); using( Transaction tx = new Transaction( doc ) ) { tx.Start( "Change Element Material" ); e.Category.Material = materials[ i ]; tx.Commit(); } } }