试试看:
[CommandMethod("Test")]public void test2() { Database db = HostApplicationServices.WorkingDatabase; Transaction trans = db.TransactionManager.StartTransaction(); BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId,OpenMode.ForRead); BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace],OpenMode.ForWrite);
try {  oint3d ptCent = new Point3d(0,0,0); Circle cir = new Circle(ptCent,Vector3d.ZAxis,20); Ellipse ell = new Ellipse(ptCent,Vector3d.ZAxis,new Vector3d(10,10,0),0.618,0,0); Line line = new Line(ptCent,new Point3d(10,10,0));
btr.AppendEntity (cir); btr.AppendEntity(ell); btr.AppendEntity(line); trans.AddNewlyCreatedDBObject(cir,true); trans.AddNewlyCreatedDBObject(ell,true); trans.AddNewlyCreatedDBObject(line,true);
foreach(ObjectId id in btr) { Entity ent = (Entity)trans.GetObject(id,OpenMode.ForRead);
if(ent.GetType() == typeof(Line)) { Application.ShowAlertDialog(ent.GetType().ToString()); } else { Application.ShowAlertDialog("Something else!"); } }
trans.Commit(); } catch(System.Exception ex) { Application.ShowAlertDialog(ex.Message); } finally { trans.Dispose(); }
} |