一、了解墙体创建基础条件
该墙体创建采用以下方法实现创建 :
Wall.Creat(Document document,Curve curve,ElementId wallTypeId,ElementId levelId,
double height,double offSet,bool fip,bool structural);
二、创建代码
[Transaction(TransactionMode.Manual)]
public class CreatWall : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
//获得文档中墙体类型
ElementId wallTyId = doc.GetDefaultElementTypeId(ElementTypeGroup.WallType);
//参加墙体线
Line wCenterLine = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(1500 / 304.8, 0, 0));
//获取墙体所在的楼层
ElementId levellId = doc.ActiveView.GenLevel.Id;
//定义墙体的高度
double hight = 3000 / 304.8;
//墙体底部偏移
double botOffSet = 100 / 304.8;
//内外侧
bool fip = false;
//定义是否为结构墙体
bool IsStruc= false;
//新建并启动事务
Transaction trans = new Transaction(doc, "创建墙体");
trans.Start();
Wall wall = Wall.Create(doc, wCenterLine,wallTyId, levellId, hight, botOffSet, fip, IsStruc);
trans.Commit();![请添加图片描述](https://img-blog.csdnimg.cn/direct/565f3b5b6872441fabaf9c3f1b076944.gif)
return Result.Succeeded;
}
}
三 、演示效果
四、注意事项
该程序运行,只能在平面中创建,因为levellId是通过当前视图获取的,三维视图无法获取到所需的构件楼层标高,用户为了程序不报错,可以将创建部分通过 try{}catch{}处理,当用户在三维视图中进行操作时候,进行提示,让其切换到平面视图中创建。