[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class cmd : IExternalCommand
{
public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elements)
{
UIDocument uiDoc = cmdData.Application.ActiveUIDocument;
Document doc = uiDoc.Document;
Transaction ts = new Transaction(uiDoc.Document, "http://revit.5d6d.com");
ts.Start();
Wall wall = uiDoc.Document.GetElement(uiDoc.Selection.PickObject(ObjectType.Element, "wall")) as Wall;
//取得一种材质
Materials materials = doc.Settings.Materials;
ElementId materialId = materials.get_Item("隔热层/保温层 - 空心填充").Id;
//得到墙结果
CompoundStructure cs = wall.WallType.GetCompoundStructure();
//ElementId matId = Material.Create(doc, "MyMaterial");//创建材质
//创建保温层(厚度,功能,材质)
CompoundStructureLayer layer = new CompoundStructureLayer(100 / 304.8, MaterialFunctionAssignment.Insulation, materialId);
cs.SetLayer(cs.GetFirstCoreLayerIndex(), layer);
//修改墙体厚度
IList<CompoundStructureLayer> listLayer = cs.GetLayers();
int iIdx = 0;
foreach (CompoundStructureLayer cLayer in listLayer)
{
if (MaterialFunctionAssignment.Structure == cLayer.Function)
{
break;
}
iIdx += 1;
}
cs.SetLayerWidth(iIdx, 400 / 304.8);
//调用更新
wall.WallType.SetCompoundStructure(cs);
ts.Commit();
return Result.Succeeded;
}
}
[Regeneration(RegenerationOption.Manual)]
public class cmd : IExternalCommand
{
public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elements)
{
UIDocument uiDoc = cmdData.Application.ActiveUIDocument;
Document doc = uiDoc.Document;
Transaction ts = new Transaction(uiDoc.Document, "http://revit.5d6d.com");
ts.Start();
Wall wall = uiDoc.Document.GetElement(uiDoc.Selection.PickObject(ObjectType.Element, "wall")) as Wall;
//取得一种材质
Materials materials = doc.Settings.Materials;
ElementId materialId = materials.get_Item("隔热层/保温层 - 空心填充").Id;
//得到墙结果
CompoundStructure cs = wall.WallType.GetCompoundStructure();
//ElementId matId = Material.Create(doc, "MyMaterial");//创建材质
//创建保温层(厚度,功能,材质)
CompoundStructureLayer layer = new CompoundStructureLayer(100 / 304.8, MaterialFunctionAssignment.Insulation, materialId);
cs.SetLayer(cs.GetFirstCoreLayerIndex(), layer);
//修改墙体厚度
IList<CompoundStructureLayer> listLayer = cs.GetLayers();
int iIdx = 0;
foreach (CompoundStructureLayer cLayer in listLayer)
{
if (MaterialFunctionAssignment.Structure == cLayer.Function)
{
break;
}
iIdx += 1;
}
cs.SetLayerWidth(iIdx, 400 / 304.8);
//调用更新
wall.WallType.SetCompoundStructure(cs);
ts.Commit();
return Result.Succeeded;
}
}