- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
[CommandMethod("c3p")]
static public void Create3dPolyline()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
Transaction tr = db.TransactionManager.StartTransaction();
using (tr)
{
// Get blocktable and modelspace (for write)
BlockTable bt = (BlockTable)tr.GetObject( db.BlockTableId, OpenMode.ForRead, false);
BlockTableRecord btr =(BlockTableRecord)tr.GetObject( bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false );
// Create a 3D polyline with 6 segments (closed)
Point3d[] pts = new Point3d[]
{ new Point3d(0,0,0),
new Point3d(60,0,0),
new Point3d(60,0,60),
new Point3d(60,60,60),
new Point3d(0,60,60),
new Point3d(0,0,60)
};
Point3dCollection points = new Point3dCollection(pts);
Polyline3d poly = new Polyline3d();
// First add polyline to model space and transaction
btr.AppendEntity(poly);
tr.AddNewlyCreatedDBObject(poly, true);
// Then add all vertices to polyline from point collection
foreach (Point3d pt in points)
{
// Now create the vertices
PolylineVertex3d vex3d = new PolylineVertex3d(pt);
// And add them to the 3dpoly (this adds them to the db also)
poly.AppendVertex(vex3d);
tr.AddNewlyCreatedDBObject(vex3d, true);
}
// Make polyline closed
poly.Closed = true;
// Change color
poly.ColorIndex = 14;
// Commit transaction
tr.Commit();
}
} |
|