- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
namespace ExtrudedSolidSample
{
public class Commands
{
[CommandMethod("Test")]
public void Test()
{
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
// Create a closed polyline (it have to be disposed because it won't be added to the database)
using (Polyline pline = new Polyline(12))
{
pline.AddVertexAt(0, new Point2d(100.0, 100.0), 0.0, 0.0, 0.0);
pline.AddVertexAt(0, new Point2d(200.0, 100.0), 0.0, 0.0, 0.0);
pline.AddVertexAt(0, new Point2d(200.0, 130.0), 0.0, 0.0, 0.0);
pline.AddVertexAt(0, new Point2d(180.0, 130.0), 0.0, 0.0, 0.0);
pline.AddVertexAt(0, new Point2d(180.0, 170.0), 0.0, 0.0, 0.0);
pline.AddVertexAt(0, new Point2d(200.0, 170.0), 0.0, 0.0, 0.0);
pline.AddVertexAt(0, new Point2d(200.0, 200.0), 0.0, 0.0, 0.0);
pline.AddVertexAt(0, new Point2d(100.0, 200.0), 0.0, 0.0, 0.0);
pline.AddVertexAt(0, new Point2d(100.0, 170.0), 0.0, 0.0, 0.0);
pline.AddVertexAt(0, new Point2d(120.0, 170.0), 0.0, 0.0, 0.0);
pline.AddVertexAt(0, new Point2d(120.0, 130.0), 0.0, 0.0, 0.0);
pline.AddVertexAt(0, new Point2d(100.0, 130.0), 0.0, 0.0, 0.0);
pline.Closed = true;
DBObjectCollection curves = new DBObjectCollection { pline };
// Create a region (it have to be disposed because it won't be added to the database)
using(DBObjectCollection regions = Region.CreateFromCurves(curves))
{
// Create a solid 3d (it will be added to the database)
Solid3d solid = new Solid3d();
solid.Extrude((Region)regions[0], 500.0, 0.0);
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr =
(BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
btr.AppendEntity(solid);
tr.AddNewlyCreatedDBObject(solid, true);
// Create a slicing plane
Plane plane = new Plane(new Point3d(200.0, 200.0, 500.0), new Vector3d(0.0, 1.0, -1.0));
// Slice the solid 3d with the plane
solid.Slice(plane, true);
}
}
tr.Commit();
}
}
}
} |
|