本文主要是介绍AutoCAD .Net EntityJig – Jig Circle by Center and Radius,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
本实例展示使用 EntityJig 技术,动态交互模式创建圆。
翻译自: AutoCAD .NET: EntityJig – Jig Circle by Center and Radius
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;[CommandMethod("JigCircle")]
public static void JigCircle()
{Document doc = Application.DocumentManager.MdiActiveDocument;if (CircleJigger.Jig()){doc.Editor.WriteMessage("\nSuccess\n");}else{doc.Editor.WriteMessage("\nFailure\n");}
}public class CircleJigger : EntityJig
{private Circle _circle;public int step = 1;private Point3d _center = new Point3d();private double _radius = 0.0001;public CircleJigger(Circle circle): base(circle){_circle = circle;_circle.Center = _center;_circle.Radius = _radius;}protected override bool Update(){switch (step){case 1:_circle.Center = _center;break;case 2:_circle.Radius = _radius;break;default:return false;}return true;}protected override SamplerStatus Sampler(JigPrompts prompts){switch (step){case 1:JigPromptPointOptions prOptions1 = new JigPromptPointOptions("\n圆心:");PromptPointResult prResult1 = prompts.AcquirePoint(prOptions1);if (prResult1.Status == PromptStatus.Cancel)return SamplerStatus.Cancel;if (prResult1.Value.Equals(_center)){return SamplerStatus.NoChange;}else{_center = prResult1.Value;return SamplerStatus.OK;}case 2:JigPromptDistanceOptions prOptions2 = new JigPromptDistanceOptions("\n半径:");prOptions2.BasePoint = _center;PromptDoubleResult prResult2 = prompts.AcquireDistance(prOptions2);if (prResult2.Status == PromptStatus.Cancel)return SamplerStatus.Cancel;if (prResult2.Value.Equals(_radius)){return SamplerStatus.NoChange;}else{if (prResult2.Value < 0.0001){return SamplerStatus.NoChange;}else{_radius = prResult2.Value;return SamplerStatus.OK;}}default:break;}return SamplerStatus.OK;}public static bool Jig(){try{Document doc = Application.DocumentManager.MdiActiveDocument;Database db = doc.Database;Circle circle = new Circle();CircleJigger jigger = new CircleJigger(circle);PromptResult pr;do{pr = doc.Editor.Drag(jigger);jigger.step++;}while (pr.Status != PromptStatus.Cancel&& jigger.step <= 2);if (pr.Status != PromptStatus.Cancel){using (Transaction tr = db.TransactionManager.StartTransaction()){BlockTable bt = tr.GetObject(db.BlockTableId,OpenMode.ForRead) as BlockTable;BlockTableRecord btr = tr.GetObject(bt[BlockTableRecord.ModelSpace],OpenMode.ForWrite) as BlockTableRecord;btr.AppendEntity(jigger.Entity);tr.AddNewlyCreatedDBObject(jigger.Entity, true);tr.Commit();}}else{return false;}return true;}catch{return false;}}
}
这篇关于AutoCAD .Net EntityJig – Jig Circle by Center and Radius的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!