.NET

Reply
Contributor
kresimir.kukec
Posts: 12
Registered: ‎01-02-2014
Message 1 of 2 (162 Views)
Accepted Solution

Polyline point at given distance

162 Views, 1 Replies
08-07-2014 02:18 AM

Hi 

 

I am trying to get point on polyline at given distance from point i choose. Synce GetPointAtDist only uses polyline start point  I tryed to brake polyline so startpoint to be at start point of measurement but I get eNotin database? Anyone have idea what I am doint wrong??

 

Here's my code: 

 [CommandMethod("stacpoly", CommandFlags.Modal)]
        public void stacpoly() // This method can have any name
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;
            ObjectId pid = funkcije.odaberi_polyline("Od poly");
            Point3d t = funkcije.pp("Odaberi tocku");
            Point3d t1=default(Point3d);
            Point3d t2 = default(Point3d);
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                Polyline pline = (Polyline)tr.GetObject(pid, OpenMode.ForWrite);
                if (pline.EndPoint.X<pline.StartPoint.X)
                {
                  try
                  {
                      pline.ReverseCurve();
                  }
                  catch( Autodesk.AutoCAD.Runtime.Exception ex)
                  {
                    ed.WriteMessage(ex.Message);
                  }
                }
                t = pline.GetClosestPointTo(t,false);
                Point3dCollection tpoly = new Point3dCollection();
                tpoly.Add(pline.StartPoint);
                tpoly.Add(t);
                tpoly.Add(t);
                tpoly.Add(pline.EndPoint);

                DBObjectCollection plines = pline.GetSplitCurves(tpoly);
                if (plines.Count==2)
                {
                    Polyline p1;
                    Polyline p2;
                    DBObject dbo1 = plines[0];
                    try
                    {
                       p1 = (Polyline)dbo1;
                       tr.AddNewlyCreatedDBObject(dbo1, true);
                       p1.ReverseCurve();
                       DBObject dbo2 = plines[1];
                       p2 = (Polyline)dbo2;
                       tr.AddNewlyCreatedDBObject(p2, true);
                       t1 = p1.GetPointAtDist(200);
                       t2 = p2.GetPointAtDist(200);
                    }
                    catch (Autodesk.AutoCAD.Runtime.Exception ex)
                    {
                        ed.WriteMessage(ex.Message);
                    }
                }
                
                tpoly.Dispose();
                plines.Dispose();
                pline.Erase();
                tr.Commit();
            }
            Line l1 = new Line(new Point3d(0, 0, 0), t1);
            Line l2 = new Line(new Point3d(0, 0, 0), t2);
        }

 

Why not just use GetDistAtPoint() and add the desired distance to that to pass to GetPointAtDist()?

*Expert Elite*
Jeff_M
Posts: 4,519
Registered: ‎07-22-2003
Message 2 of 2 (137 Views)

Re: Polyline point at given distance

08-07-2014 07:06 AM in reply to: kresimir.kukec

Why not just use GetDistAtPoint() and add the desired distance to that to pass to GetPointAtDist()?

Jeff_M, also a frequent Swamper
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.