.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Polyline point at given distance

1 REPLY 1
SOLVED
Reply
Message 1 of 2
kresimir.kukec
952 Views, 1 Reply

Polyline point at given distance

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);
        }

 

1 REPLY 1
Message 2 of 2
Jeff_M
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
EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost