本文主要是介绍AutoCAD .Net EntityJig – Jig Line by Start and End Points,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
本实例展示使用 EntityJig 技术,动态交互模式创建直线。
翻译自: AutoCAD .NET: EntityJig – Jig Line by Start and End Points
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;public class JigLineSample
{[CommandMethod("JigLine")]public static void JigLine(){Document doc = Application.DocumentManager.MdiActiveDocument;if (LineJigger.Jig()){doc.Editor.WriteMessage("\nsuccess\n");}else{doc.Editor.WriteMessage("\nfailure\n");}}
}public class LineJigger : EntityJig
{public Point3d endPnt = new Point3d();public LineJigger(Line line): base(line){}protected override bool Update(){Document doc = Application.DocumentManager.MdiActiveDocument;(Entity as Line).EndPoint = endPnt;return true;}protected override SamplerStatus Sampler(JigPrompts prompts){Document doc = Application.DocumentManager.MdiActiveDocument;JigPromptPointOptions prOptions1 = new JigPromptPointOptions("\nNext point:");prOptions1.BasePoint = (Entity as Line).StartPoint;prOptions1.UseBasePoint = true;prOptions1.UserInputControls = UserInputControls.Accept3dCoordinates| UserInputControls.AnyBlankTerminatesInput | UserInputControls.GovernedByOrthoMode | UserInputControls.GovernedByUCSDetect | UserInputControls.UseBasePointElevation| UserInputControls.InitialBlankTerminatesInput | UserInputControls.NullResponseAccepted;PromptPointResult prResult1 = prompts.AcquirePoint(prOptions1);if (prResult1.Status == PromptStatus.Cancel)return SamplerStatus.Cancel;if (prResult1.Value.Equals(endPnt)){return SamplerStatus.NoChange;}else{endPnt = prResult1.Value;return SamplerStatus.OK;}}#regionpublic static bool Jig(){try{Document doc = Application.DocumentManager.MdiActiveDocument;Database db = doc.Database;PromptPointResult ppr = doc.Editor.GetPoint("\nStart point:");if (ppr.Status != PromptStatus.OK)return false;Point3d pt = ppr.Value;Line line = new Line(pt, pt);line.TransformBy(doc.Editor.CurrentUserCoordinateSystem);LineJigger jigger = new LineJigger(line);PromptResult pr = doc.Editor.Drag(jigger);if (pr.Status == PromptStatus.OK){using (Transaction tr = db.TransactionManager.StartTransaction()){BlockTable bt = tr.GetObject(db.BlockTableId,OpenMode.ForRead) as BlockTable;BlockTableRecord modelSpace = tr.GetObject(bt[BlockTableRecord.ModelSpace],OpenMode.ForWrite) as BlockTableRecord;modelSpace.AppendEntity(jigger.Entity);tr.AddNewlyCreatedDBObject(jigger.Entity, true);tr.Commit();}}else{line.Dispose();return false;}return true;}catch{return false;}}#endregion
}
这篇关于AutoCAD .Net EntityJig – Jig Line by Start and End Points的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!