最近总会遇到对墙构件的厚度进行修改,就去了解了一下墙修改的类,下面和大家分享一下~~~
主要想通过代码去修改墙类型属性中结构相关内容
对应的类是CompoundStructure 类
- 每一行数据都对应的一个CompoundStructureLayer ,CompoundStructure 类中提供了获取和修改的方法,GetLayer方法可以获取,SetLayer方法可以设置修改。CompoundStructureLayer 里面包含功能、材质、厚度这些参数都可以手动修改
- 下面是实操的代码块。
[Transaction(TransactionMode.Manual)]
public class ChangeWallThicknessDemo : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
Reference selRef = null;
try
{
selRef = uidoc.Selection.PickObject(ObjectType.Element,new SelectedWall(),"请选择需要改变厚度的墙");
}
catch
{
return Result.Failed;
}
//改变后墙的厚度
double nwWallThickness = 500;
Wall selWall = doc.GetElement(selRef) as Wall;
WallType selWallType = selWall.WallType;
//墙结构的编辑部件界面
CompoundStructure wallTypeStructure = selWallType.GetCompoundStructure();
//拿到墙的整体厚度
double wallThickness = wallTypeStructure.GetWidth();
//拿到核心边界里面的第一个图层再所有图层里面的开始编号和结束编号。如果两个不一样的时候,需要考虑改变的是哪一个图层的厚度
int startIndex = wallTypeStructure.GetFirstCoreLayerIndex();
int eneIndex = wallTypeStructure.GetLastCoreLayerIndex();
Transaction trans = new Transaction(doc, "修改墙厚度");
trans.Start();
//修改厚度
wallTypeStructure.SetLayerWidth(startIndex, nwWallThickness / 304.8);
//墙类型重新赋值
selWallType.SetCompoundStructure(wallTypeStructure);
trans.Commit();
return Result.Succeeded;
}
}
public class SelectedWall : ISelectionFilter
{
public bool AllowElement(Element elem)
{
if (elem is Wall) return true;
return false;
}
public bool AllowReference(Reference reference, XYZ position)
{
return true;
}
}
这个类里面可以挖掘的方法还有很多,这里不一一叙述,后面可以继续挖掘。这次分享的内容不多,希望可以给你指个方向。