Revit二次開發之替換牆的構造層資訊
UIDocument uidoc=commandData.Application.ActiveUIDocument;
Document doc=uidoc.Document;
Material material=new FilteredElementCollector(doc).OfClass(typeof(Material)).Cast().First() as Material;
Reference refer = commandData.Application.ActiveUIDocument.Selection.PickObject(ObjectType.Element);
Wall wall = doc.GetElement(refer) as Wall;
CompoundStructure cs = wall.WallType.GetCompoundStructure();
Transaction ts = new Transaction(doc,"BIM");
ts.Start();
CompoundStructureLayer layer = new CompoundStructureLayer(300/304.8,MaterialFunctionAssignment.Structure,material.Id);
CompoundStructureLayer layer1 = new CompoundStructureLayer(200/304.8, MaterialFunctionAssignment.Structure, material.Id);
CompoundStructureLayer layer2 = new CompoundStructureLayer(100/304.8, MaterialFunctionAssignment.Structure, material.Id);
IList list = new List() { layer,layer1,layer2};
cs.SetLayers(list);
wall.WallType.SetCompoundStructure(cs);
ts.Commit();
//材質 厚度,資訊互換
//非目標牆
//Reference refer1 = commandData.Application.ActiveUIDocument.Selection.PickObject(ObjectType.Element);
//Wall wall1 = commandData.Application.ActiveUIDocument.Document.GetElement(refer1) as Wall;
//Transaction ts = new Transaction(commandData.Application.ActiveUIDocument.Document, "BIM");
//ts.Start();
//CompoundStructure cs1 = wall1.WallType.GetCompoundStructure();
//ElementId materialId = null;
//double width = 0;
//foreach (CompoundStructureLayer layer in cs1.GetLayers())
//{
// if (layer.Function == MaterialFunctionAssignment.Structure)
// {
// materialId = layer.MaterialId;
// layer.Width = 300 / 304.8;
// width = layer.Width;
// break;
// }
//}
//CompoundStructure cs = wall.WallType.GetCompoundStructure();
//MessageBox.Show((doc.GetElement(materialId) as Material).Name);
//CompoundStructureLayer newlayer = null;
//foreach (CompoundStructureLayer layer in cs.GetLayers())
//{
// if (layer.Function == MaterialFunctionAssignment.Structure)
// {
// layer.MaterialId = (doc.GetElement(materialId) as Material).Id;
// layer.Width = width;
// cs.SetMaterialId(layer.LayerId,materialId);
// cs.SetLayerWidth(layer.LayerId,width);
// newlayer = layer;
// break;
// }
//}
//wall.WallType.SetCompoundStructure(cs);
//ts.Commit();
// CompoundStructure cs3 = wall2.WallType.GetCompoundStructure();
// wall.WallType.SetCompoundStructure(cs3);