代码示例
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
namespace CreateCircle
{
public class Class1
{
[CommandMethod("CreateCircle")]
public void Test()
{
Database db = HostApplicationServices.WorkingDatabase;
Circle[] circles = new Circle[10000];
//初始化圆对象
for (int i = 0; i < 100; i++)
{
for (int j = 0; j < 100; j++)
{
circles[i * 100 + j] = new Circle(new Point3d(j * 100, i * 100, 0), Vector3d.ZAxis, 50);
}
}
//开启事务处理
using (Transaction tr = db.TransactionManager.StartTransaction())
{
//只读方式开启块表、只写方式开启块表记录
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
//向块表记录附加实体对象
for (int i = 0; i < circles.Length; i++)
{
btr.AppendEntity(circles[i]);
tr.AddNewlyCreatedDBObject(circles[i], true);
}
//提交事务
tr.Commit();
}
}
}
}
说明:需要引入与调试CAD版本对应的库文件,如:AcCoreMgd.dll、AcMgd.dll、AcDbMgd.dll,将按F7生成的CreateCircle.dll库文件加载到CAD中,输入CreateCircle命令即可看到效果。开发环境配置请参考下文:
感谢您的来访,获取更多精彩文章请收藏本站
© 版权声明
THE END
暂无评论内容