自己根据AutoCAD .Net Developer's Guide教程上的RotateObject编写的旋转对象命令,命令运行后对象没有任何变化,运行过程中监控了每个变量的情况,均未发现异常。请大家看看这段代码有什么问题,多谢指教。- [CommandMethod("WRT",CommandFlags.UsePickSet)] //WRT=MRT=MyRotate
- public static void MyRotate()
- {
- Database acDb = Application.DocumentManager.MdiActiveDocument.Database;
- Editor acEd = Application.DocumentManager.MdiActiveDocument.Editor;
- ObjectIdCollection acObjIdColl = new ObjectIdCollection();
- using (Transaction acTrans = acDb.TransactionManager.StartTransaction())
- {
- SelectionSet acSSet = CreatSelectionSet();
- if (acSSet!=null) // if1
- {
- PromptPointOptions prPtOpt=new PromptPointOptions("");
- PromptPointResult prPtRslt;
-
- prPtOpt.Message = "\nSpecify the base point:";
- prPtOpt.AllowNone = true;
- prPtRslt = acEd.GetPoint(prPtOpt);
- if (prPtRslt.Status == PromptStatus.OK) // if1-1
- {
- Point3d ptBase = prPtRslt.Value;
- PromptAngleOptions prAngOpt=new PromptAngleOptions("");
- prAngOpt.Message = "\nSpecify the rotation angle:";
- prAngOpt.UseBasePoint = true;
- prAngOpt.BasePoint = ptBase;
- prAngOpt.UseDashedLine = true;
- prAngOpt.AllowNone = true;
- PromptDoubleResult prAngRslt;
- prAngRslt = acEd.GetAngle(prAngOpt);
- if (prAngRslt.Status == PromptStatus.OK) // if1-1-1
- {
- double dAngRt = prAngRslt.Value;
- Matrix3d curUCSMat = acEd.CurrentUserCoordinateSystem;
- CoordinateSystem3d curUCS = curUCSMat.CoordinateSystem3d;
- acObjIdColl = new ObjectIdCollection(acSSet.GetObjectIds());
- foreach (ObjectId acObjId in acObjIdColl)
- {
- Entity acEnt = acTrans.GetObject(acObjId, OpenMode.ForWrite) as Entity;
- acEnt.TransformBy(Matrix3d.Rotation(dAngRt, curUCS.Zaxis, ptBase));
- } //end foreach
- }// end if1-1-1
- } // end if1-1
- } //end if1
- } // end using Transaction
- } // end MyRotate
代码中的CreatSelectionSet()是另外编写的一个选择对象的过程,即判断PickFirst集中有无对象,有则直接返回,没则重新选择后返回选集,在另一个自己编写的移动MyMove()和删除MyErase()命令中均能正常调用。
|