Message 1 of 6

Not applicable
05-24-2016
05:30 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I use the GetClosestPointTo method to make sure the point on the curve
then I get a eInvalidInput error when using GetParameterAtPoint for a LWPolyline。
here is my code
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.Geometry; [assembly: CommandClass(typeof(test.Class1))] namespace test { public class Class1 { [CommandMethod("eg1")] public static void eg1() { Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; PromptEntityOptions peop = new PromptEntityOptions("\nchoose a polylne:"); peop.SetRejectMessage("\n polyline only!"); peop.AddAllowedClass(typeof(Polyline), true); PromptEntityResult res = ed.GetEntity(peop); if (res.Status != PromptStatus.OK) return; PromptPointOptions ppt = new PromptPointOptions("\nchoose a point:"); PromptPointResult pptRes = ed.GetPoint(ppt); if (pptRes.Status != PromptStatus.OK) return; Polyline txt0 = null; using (Transaction trans = doc.Database.TransactionManager.StartTransaction()) { txt0 = trans.GetObject(res.ObjectId, OpenMode.ForWrite) as Polyline; trans.Commit(); } Point3d pt = txt0.GetClosestPointTo(pptRes.Value, true); double param1 = txt0.GetParameterAtPoint(pt); ed.WriteMessage("\nparam1=" + param1.ToString()); double dis = txt0.GetDistAtPoint(pt); ed.WriteMessage("\ndis=" + dis.ToString()); } } }
and here is my drawing
Solved! Go to Solution.