- using Autodesk..ApplicationServices;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.EditorInput;
- using Autodesk.AutoCAD.Geometry;
- using Autodesk.AutoCAD.GraphicsInterface;
- using Autodesk.AutoCAD.Runtime;
- using System;
- using System.Collections.Generic;
- using ZgxCommomLib;
- [assembly: CommandClass(typeof(test.ClassCommand))]
- namespace test
- {
- //委托类
- public delegate void DelChangeEntity(Entity ent, Point3d frompt, Point3d movetopt);
- public delegate Matrix3d DelSetMat(Point3d frompt, Point3d topt, double angle);
- public class ClassCommand
- {
- [CommandMethod("lplp")]
- public void test()
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Database db = Application.DocumentManager.MdiActiveDocument.Database;
- Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
- PromptSelectionResult psr = ed.GetSelection();
- SelectionSet ss = psr.Value;
- PromptPointResult ppr = ed.GetPoint("\n 选择点");
- Point3d ptBase = ppr.Value;
- ptBase = ptBase.TransformBy(ed.CurrentUserCoordinateSystem);
- //实体变换委托
- void del1(Entity ent, Point3d pt, Point3d moveform)
- {
- using (OpenCloseTransaction tr = db.TransactionManager.StartOpenCloseTransaction())
- {
- tr.GetObject(ent.ObjectId, OpenMode.ForWrite, false);
- if (ent is DBText)
- ((DBText)ent).TextString = pt.ToString();
- else if (ent is MText)
- ((MText)ent).Contents = pt.ToString();
- tr.Commit();
- }
- }
- //变换矩阵委托
- Matrix3d mat(Point3d ptFrom, Point3d ptTo, double angle)
- {
- //angle = 100.02;
- return Matrix3d.Displacement(ptFrom.GetVectorTo(ptTo));
- }
- DelSetMat setMat = new DelSetMat(mat);
- DelChangeEntity changeEntity = new DelChangeEntity(del1);
- //通过类实例化jig
- DelDrawJig delJig = DrawJigEntrance.EnterJig(changeEntity, setMat, true, true);
- int iControlFlag = (int)(UserInputControls.Accept3dCoordinates |
- UserInputControls.NoZeroResponseAccepted |
- UserInputControls.NoNegativeResponseAccepted |
- UserInputControls.NullResponseAccepted);
- delJig.AddEntity(ss);
- delJig.BasePnt = ptBase;
- delJig.Movefrom = ptBase;
- delJig.MoveEndPnt = ptBase;
- delJig.PrmpStr = "\n移动到";
- delJig.KeyString = "A_A旋转;S_S左右镜像;D_D重新选点;F_F图取标高值";
- delJig.CursorType = (int)CursorType.Crosshair;
- delJig.ControlFlag = iControlFlag;
- using (delJig)
- {
- try
- {
- //事务管理器
- using (Transaction trans = db.TransactionManager.StartTransaction())
- {
- // Draw Jig 交互
- PromptResult pr;
- pr = ed.Drag(delJig);
- // 结果
- if (pr.Status == PromptStatus.OK)
- {
- delJig.TransFormEntities();
- trans.Commit();
- ed.WriteMessage("\n 拖拽结束");
- return;
- }
- else
- trans.Abort();
- }// end of using tr1
- }//end of try
- catch (System.Exception ex)
- {
- ed.WriteMessage("\nJig出错了");
- ed.WriteMessage("\ncatch" + ex.Message);
- //Application.SetSystemVariable("orthomode", orthomode);
- return;
- }
- }// end of using Jig
- }
- }
- public class DrawJigEntrance
- {
- public static DelDrawJig EnterJig(DelChangeEntity changeEntity, DelSetMat acquireMat)
- {
- return new DelDrawJig(changeEntity, acquireMat);
- }
- public static DelDrawJig EnterJig(DelChangeEntity changeEntity, DelSetMat setMat, bool useMat)
- {
- DelDrawJig del = new DelDrawJig(changeEntity, setMat);
- del.Usepushmat = useMat;
- return del;
- }
- public static DelDrawJig EnterJig(DelChangeEntity changeEntity, DelSetMat setMat, bool useMat, bool useBasePoint)
- {
- DelDrawJig del = new DelDrawJig(changeEntity, setMat);
- del.Usepushmat = useMat;
- del.Userbasept = useBasePoint;
- return del;
- }
- }
- public class DelDrawJig : DrawJig, IDisposable
- {
|