我想我应该通过说我还是一个相对新的(6个月)来限定之前的帖子。Net的任何伪装。我的大部分工作都是在C语言中完成的,但这应该意味着我只走了一小段路。
我相信前一篇文章中的代码会起作用,但可能需要额外注意,使其更“防弹”。
下面是C版本(我包含了更多的实体)。这可能是一个有趣的比较。
顺便提一下,我欢迎对该准则的任何评论和/或批评。
该项目应包括:
使用系统;
使用Autodesk。AutoCAD。运行时间;
使用Autodesk。AutoCAD。应用服务;
使用Autodesk。AutoCAD。数据库服务;
使用Autodesk。AutoCAD。几何学
使用Autodesk。AutoCAD。编辑输入;
- static public void PlinePtAtDist()
- {
- // Obtain Database and Editor
- Database db = HostApplicationServices.WorkingDatabase;
- Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
- db.Pdmode = 66; // to make point more visible
- PromptEntityOptions entOpts = new PromptEntityOptions("\nSelect a pline or spline entity: ");
- entOpts.SetRejectMessage("\nPlease select LWPoly, 2DPoly, 3DPoly, or spline only! ");
- entOpts.AddAllowedClass(typeof(Polyline), true);
- entOpts.AddAllowedClass(typeof(Polyline2d), true);
- entOpts.AddAllowedClass(typeof(Polyline3d), true);
- entOpts.AddAllowedClass(typeof(Spline), true);
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- PromptEntityResult prEntRes = ed.GetEntity(entOpts);
- if (prEntRes.Status != PromptStatus.OK) return; //terminate if no object selected
- Curve crv = (Curve)tr.GetObject(prEntRes.ObjectId, OpenMode.ForRead);
- Double len = crv.GetDistanceAtParameter(crv.EndParam); //total length of curve
- PromptDoubleOptions pdo = new PromptDoubleOptions("\nEnter distance from startpoint: ");
- pdo.AllowNegative = false;
- pdo.AllowZero = true;
- pdo.DefaultValue = len;
- pdo.AllowArbitraryInput = false;
- PromptDoubleResult pdr = ed.GetDouble(pdo);
- if (pdr.Status != PromptStatus.OK || pdr.Value > len) return;//value has been entered and less than total
- Point3d pt = crv.GetPointAtParameter(crv.GetParameterAtDistance(pdr.Value));//crux of routine
- DBPoint ptAtDist = new DBPoint(pt);
- try
- {
- BlockTableRecord btr = (BlockTableRecord)(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite));
- btr.AppendEntity(ptAtDist);
- tr.AddNewlyCreatedDBObject(ptAtDist, true);
- tr.Commit();
- }
- catch (System.InvalidOperationException ex)
- {
- tr.Abort();
- ed.WriteMessage("\nProblem adding point at distance!");
- ed.WriteMessage(ex.Message);
- }
- finally
- {
- ed.WriteMessage("\nPoint at Distance command terminated.");
- }
- }
- }
|