自己编写的旋转命令不能运行,请大家指出错误
自己根据AutoCAD .Net Developer's Guide教程上的RotateObject编写的旋转对象命令,命令运行后对象没有任何变化,运行过程中监控了每个变量的情况,均未发现异常。请大家看看这段代码有什么问题,多谢指教。 //WRT=MRT=MyRotatepublic 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()命令中均能正常调用。
补充:在第40行后面加入acEd.Regen();后,窗口会在图形旋转到的位置闪一下(表示图形已经旋转到目标位置),但是原来的图形仍没有变化。奇怪。 没有提交事务acTrans.commit() 本帖最后由 syeanwoo 于 2011-10-19 15:42 编辑
sailorcwx 发表于 2011-10-19 15:14 static/image/common/back.gif
没有提交事务acTrans.commit()
Oh, my gosh! 如此严重的低级错误,我还使劲在Transformby()方法上排查!非常感谢!
页:
[1]