using语句内部一样可以用try的- [CommandMethod("mm")]
- static public void MMove()
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- Editor ed = doc.Editor;
- PromptSelectionResult res = ed.GetSelection();
- if (res.Status == PromptStatus.OK)
- {
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- foreach (ObjectId id in res.Value.GetObjectIds())
- {
- Move(
- (Entity)id.GetObject(OpenMode.ForRead),
- Point3d.Origin,
- new Point3d(10,10,0)
- );
- }
- tr.Commit();
- }
- }
- }
- static public bool Move(Entity ent, Point3d startPoint, Point3d endPoint)
- {
- try
- {
- ent.UpgradeOpen();
- ent.TransformBy(Matrix3d.Displacement(endPoint - startPoint));
- }
- catch
- {
- return false;
- }
- return true;
- }
|