Hi all,
I have a an angular polyline (not horizontal or vertical). I want to equally divide the polyline with a specified length and get all seperation co-ordinates at each interval. The line remains as polyline, I need to get only the co-ordinates of all the possible divisions for a given length.
I need a C#.Net function for this. Kindly help in achieving this.
Thanks and regards
Since you know the length of the interval (assuming the length is counted along the polyline, which may not be straight with each interval), then you can easily get the coordinates with
Polyline.GetPointAtDist(double)
Norman Yuan
Thanks for the pointer norman.yuan.
Will check with that method and come back.
Try this code for the test, you can expand the functionality
for other object types, currently it's working for lwplines,
3dplines and splines
[CommandMethod("diem")] public void testDivideMethod() { Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; Database db = doc.Database; Matrix3d ucs = ed.CurrentUserCoordinateSystem; Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("pdmode", 34); Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("pdsize", 2.0); Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("osmode", 0); Transaction tr = doc.TransactionManager.StartOpenCloseTransaction(); try { using (tr) { PromptEntityOptions peo = new PromptEntityOptions("\nSelect an Curve >>"); peo.SetRejectMessage("\nPlease select LWPOLYLINE, 3DPOLY or SPLINE only >>"); peo.AddAllowedClass(typeof(Polyline), false); peo.AddAllowedClass(typeof(Spline), false); peo.AddAllowedClass(typeof(Polyline3d), false); PromptEntityResult res; res = ed.GetEntity(peo); if (res.Status != PromptStatus.OK) return; Entity ent = (Entity)tr.GetObject(res.ObjectId, OpenMode.ForRead); if (ent == null) return; Curve curv = (Curve)ent as Curve; if (curv == null) { ed.WriteMessage("\nError: selected entity is not a Curve"); return; } Plane plan = curv.GetPlane(); int num = 36; double delta =curv.GetDistanceAtParameter (curv.EndParam - curv.StartParam) / (num + 1); double step = delta; Point3dCollection pts = new Point3dCollection(); BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); for (int n = 0; n <= num + 1; n++) { Point3d cp = curv.GetPointAtDist(step * n); pts.Add(cp.TransformBy(ucs)); } if (pts == null) return; // a dummy test to see result foreach (Point3d pp in pts) { DBPoint pt = new DBPoint(curv.GetClosestPointTo(pp, false)); pt.SetDatabaseDefaults(); pt.ColorIndex = 1; btr.AppendEntity(pt); tr.AddNewlyCreatedDBObject(pt, true); } tr.Commit(); } } catch (Autodesk.AutoCAD.Runtime.Exception ex) { Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage (ex.ToString()); return; } finally { Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("osmode", 8); Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nCheck result\n"); } }
hi Hallex,
Thanks for your code. Currently, I have put the testing activity on hold for a few days.
Will get back once I start again.