2010的那两个托管DLL文件中,增加了对“放样”和“扫琼”的支持,使得我们用C#进行三维建模的手段更加丰富了!
以前的CAD版本,用C#能进行“放样曲面”和“扫琼曲面”的操作,但不能进行实体的操作。
- // 放样示例:天圆地方.
- [CommandMethod("Test")]
- public void Test()
- {
- Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
- Polyline ent1 = new Polyline();
- ent1.AddVertexAt(0, new Point2d(50, 50), 0, 0, 0);
- ent1.AddVertexAt(1, new Point2d(-50, 50), 0, 0, 0);
- ent1.AddVertexAt(2, new Point2d(-50, -50), 0, 0, 0);
- ent1.AddVertexAt(3, new Point2d(50, -50), 0, 0, 0);
- ent1.Closed = true;
- Circle ent2 = new Circle(new Point3d(0, 0, 200), new Vector3d(0, 0, 1), 30);
- Entity[] crossEnts = new Entity[2];
- crossEnts.SetValue(ent1, 0);
- crossEnts.SetValue(ent2, 1);
- Entity[] guideCurs = new Entity[0];
- LoftOptions loftOpt = new LoftOptions();
- Solid3d solid3dEnt = new Solid3d();
- solid3dEnt.RecordHistory = true;
- solid3dEnt.CreateLoftedSolid(crossEnts, guideCurs, null, loftOpt);
- AppendEntity(solid3dEnt);
- }
- ObjectId AppendEntity(Entity ent)
- {
- Database db = HostApplicationServices.WorkingDatabase;
- ObjectId entId;
- using (Transaction trans = db.TransactionManager.StartTransaction())
- {
- BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId,
- OpenMode.ForRead);
- BlockTableRecord btr = (BlockTableRecord)trans.GetObject
- (bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
- entId = btr.AppendEntity(ent);
- trans.AddNewlyCreatedDBObject(ent, true);
- trans.Commit();
- }
- return entId;
- }
ko34sk1sesh.JPG
|