墙体厚度是只读的,无法修改,所以只能通过修改其内部结构的层厚度。
1、得到墙体结构
2、得到所有层,并遍历修改厚度
3、修改后的层集合设置给结构,并把结构设置给墙类型
大致代码如下:
Wall wall;
double dThickness = 500 / 304.8;
double dHeight = wall.get_Prarmeter(BuiltInParameter.WALL_USER_HEIGHT_PARAM).AsDouble();
double dOffset = wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET).AsDouble();
LocationCurve lc = wall.Location as LocationCurve;
Curve curve = lc.Curve;
using(Transaction trans = new Transaction(doc,"edit"))
{
trans.Start();
try
{
//厚度时类型属性,建议新建一个墙体类型
WallType newType = wall.WallType.Duplicate("NewWallType") as WallType;
CompoundStructure cs = newType.GetCompoundStrycture();
//获取所有层
IList<CompoundStructureLayer> lstLayers = cs.GetLayers();
foreach(CompoundStructureLayer item in lstLayers)
{
if(item.Function == MaterialFunctionAssignment.Structure)
{//这里只考虑有一个结构层,如果有多个就自己算算
item.Width = dThickness;
break;
}
}
//修改后要设置一遍
cs.SetLayers(lstLayers);
newType.SetCompoundStructure(cs);
Wall.Create(doc,curve,newType.Id,wall.LevelId,dHeight,dOffset,false,false);
doc.Delete(wall.Id);
trans.Commit();
}
catch
{
trans.RollBack();
}
}