<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Divide(Measure) a Polyline with a certain interval in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/divide-measure-a-polyline-with-a-certain-interval/m-p/3540710#M54533</link>
    <description>&lt;P&gt;Is it possible to divide a polyline into multiple segments with a certain interval?&lt;/P&gt;&lt;P&gt;I am looking for something similar to "Measure" command.&lt;/P&gt;&lt;P&gt;But I want to do this programmatically.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SendStringToExcute("measure ");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;quite does not help.&lt;/P&gt;&lt;P&gt;I need the point objects created by "measure' commnad in order to draw a new polyine with them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Of course, "SendStringToExcute" does not return such object collection.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know how to solve this problem?&lt;/P&gt;&lt;P&gt;If you could provide me with C# (or .NET ObjectARX 2010) code snippet, it would be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jake&lt;/P&gt;</description>
    <pubDate>Tue, 17 Jul 2012 05:43:32 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2012-07-17T05:43:32Z</dc:date>
    <item>
      <title>Divide(Measure) a Polyline with a certain interval</title>
      <link>https://forums.autodesk.com/t5/net-forum/divide-measure-a-polyline-with-a-certain-interval/m-p/3540710#M54533</link>
      <description>&lt;P&gt;Is it possible to divide a polyline into multiple segments with a certain interval?&lt;/P&gt;&lt;P&gt;I am looking for something similar to "Measure" command.&lt;/P&gt;&lt;P&gt;But I want to do this programmatically.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SendStringToExcute("measure ");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;quite does not help.&lt;/P&gt;&lt;P&gt;I need the point objects created by "measure' commnad in order to draw a new polyine with them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Of course, "SendStringToExcute" does not return such object collection.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know how to solve this problem?&lt;/P&gt;&lt;P&gt;If you could provide me with C# (or .NET ObjectARX 2010) code snippet, it would be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jake&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2012 05:43:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/divide-measure-a-polyline-with-a-certain-interval/m-p/3540710#M54533</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-07-17T05:43:32Z</dc:date>
    </item>
    <item>
      <title>Re: Divide(Measure) a Polyline with a certain interval</title>
      <link>https://forums.autodesk.com/t5/net-forum/divide-measure-a-polyline-with-a-certain-interval/m-p/3540734#M54534</link>
      <description>&lt;P&gt;Try this code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        //      FH
        [CommandMethod("measp")]
        public static void testMeasure()
        {

            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;

            Database db = doc.Database;

            Editor ed = doc.Editor;

            Matrix3d ucs = ed.CurrentUserCoordinateSystem;

            object osm = Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("osmode");

            Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("osmode", 512);

            double fuzz = (double)Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("dimtxt");

            if (fuzz == 0) fuzz = 0.01;// change fuzz to your needs (say 0.1 or so)
            //-------------------------------------------------------------------
            PromptPointOptions ppo = new PromptPointOptions("\nPick a point near to the start of curve: ");

            PromptPointResult ppr = default(PromptPointResult);

            ppr = ed.GetPoint(ppo);

            if (ppr.Status != PromptStatus.OK)
            {
                ed.WriteMessage("\nwrong point specification!");

                return;
            }
            Point3d p = ppr.Value;
            //-------------------------------------------------------------------
            Vector3d vd = new Vector3d(fuzz, fuzz, 0);
            Point3d pMin = p - vd;
            Point3d pMax = p + vd;

            TypedValue[] tvs = new TypedValue[] { new TypedValue(0, "lwpolyline") };

            Point3dCollection points = new Point3dCollection();

            points.Add(pMin);

            points.Add(pMax);

            SelectionFilter sf = new SelectionFilter(tvs);

            PromptSelectionResult sres = ed.SelectFence(points, sf);

            if (sres.Status != PromptStatus.OK)
            {
                ed.WriteMessage("\nWrong selection!");

                return;
            }

            if (sres.Value.Count == 0)
            {
                ed.WriteMessage("\nNothing selected!");

                return;
            }

            //-------------------------------------------------------------------

            Transaction tr = db.TransactionManager.StartTransaction();

            using (tr)
            {
                try
                {

                    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);

                    ObjectId eid = sres.Value.GetObjectIds()[0];

                    Entity ent = tr.GetObject(eid, OpenMode.ForRead) as Entity;
                    // cast entity as Polyline
                    Polyline pline = ent as Polyline;

                    if (pline != null)
                    {
                        ed.WriteMessage("\n{0},{1}", pline.StartPoint.X, pline.StartPoint.Y);
                    }

                    Point3d px = pline.GetClosestPointTo(pMin, false);

                    double leng = pline.Length;

                    bool endclick = false;

                    if ((pline.GetDistAtPoint(px) &amp;gt; leng / 2))
                    {
                        endclick = true;
                    }

                    double theight = db.Textsize;

                    if (theight == 0) theight = db.Dimtxt;

                    double step = 50.0;// &amp;lt;---  change the step to your needs*************************************************

                    int num = (int)(leng / step);

                    double ang;

                    int n = 1;

                    Plane plan = pline.GetPlane();

                    Line ln = null;

                    DBText txt = null;

                    Vector3d vect = new Vector3d();

                    Vector3d vec = new Vector3d();

                    Point3d ptxt = new Point3d();

                    Point3d ppt = new Point3d();

                    Point3d pptx = new Point3d();

                    if (!endclick)
                    {
                        for (n = 0; n &amp;lt; num + 1; n++)
                        {
                            ptxt = pline.GetPointAtDist(step * n);

                            vec = pline.GetFirstDerivative(ptxt).GetPerpendicularVector();

                            ppt = (ptxt + vec * theight * 8).TransformBy(ucs);

                            pptx = (ptxt + vec * theight * 5).TransformBy(ucs);

                            ln = new Line(ptxt, ppt);

                            btr.AppendEntity(ln);

                            tr.AddNewlyCreatedDBObject(ln, true);

                            vect = ln.GetFirstDerivative(ppt).GetPerpendicularVector();

                            txt = new DBText();

                            txt.Position = pptx;

                            txt.TextString = string.Format("{0:f2}", n * step);// &amp;lt;---  change precision to your needs*************************************************

                            txt.HorizontalMode = TextHorizontalMode.TextCenter;

                            txt.VerticalMode = TextVerticalMode.TextBottom;

                            txt.AlignmentPoint = pptx;

                            ang = ln.Angle + Math.PI;

                            if ((ang &amp;gt; Math.PI / 2) || (ang &amp;lt; Math.PI * 1.5))

                                ang = ang + Math.PI;
                            txt.Rotation = ang;

                            btr.AppendEntity(txt);

                            tr.AddNewlyCreatedDBObject(txt, true);

                        }

                        ptxt = pline.EndPoint;

                        vec = pline.GetFirstDerivative(ptxt).GetPerpendicularVector();

                        ppt = (ptxt + vec * theight * 8).TransformBy(ucs);

                        pptx = (ptxt + vec * theight * 5).TransformBy(ucs);

                        ln = new Line(ptxt, ppt);

                        btr.AppendEntity(ln);

                        tr.AddNewlyCreatedDBObject(ln, true);

                        vect = ln.GetFirstDerivative(ppt).GetPerpendicularVector();

                        txt = new DBText();

                        txt.Position = pptx;

                        txt.TextString = string.Format("{0:f2}", leng);// &amp;lt;---  change precision to your needs*************************************************

                        txt.HorizontalMode = TextHorizontalMode.TextCenter;

                        txt.VerticalMode = TextVerticalMode.TextBottom;

                        txt.AlignmentPoint = pptx;

                        ang = ln.Angle + Math.PI;

                        if ((ang &amp;gt; Math.PI / 2) || (ang &amp;lt; Math.PI * 1.5))

                            ang = ang + Math.PI;

                        txt.Rotation = ang;

                        btr.AppendEntity(txt);

                        tr.AddNewlyCreatedDBObject(txt, true);
                    }
                    else
                    {
                        //---------------------------------------------------
                        for (n = num; n &amp;gt;= 0; n--)
                        {
                            ptxt = pline.GetPointAtDist(step * n);

                            vec = pline.GetFirstDerivative(ptxt).GetPerpendicularVector();

                            ppt = (ptxt + vec * theight * 8).TransformBy(ucs);

                            pptx = (ptxt + vec * theight * 5).TransformBy(ucs);

                            ln = new Line(ptxt, ppt);

                            btr.AppendEntity(ln);

                            tr.AddNewlyCreatedDBObject(ln, true);

                            vect = ln.GetFirstDerivative(ppt).GetPerpendicularVector();

                            txt = new DBText();

                            txt.Position = pptx;

                            txt.TextString = string.Format("{0:f2}", n * step);// &amp;lt;---  change precision to your needs*************************************************

                            txt.HorizontalMode = TextHorizontalMode.TextCenter;

                            txt.VerticalMode = TextVerticalMode.TextBottom;

                            txt.AlignmentPoint = pptx;

                            ang = ln.Angle + Math.PI;

                            if ((ang &amp;gt; Math.PI / 2) || (ang &amp;lt; Math.PI * 1.5))

                                ang = ang + Math.PI;

                            txt.Rotation = ang;

                            btr.AppendEntity(txt);

                            tr.AddNewlyCreatedDBObject(txt, true);

                        }

                        ptxt = pline.EndPoint;

                        vec = pline.GetFirstDerivative(ptxt).GetPerpendicularVector();

                        ppt = (ptxt + vec * theight * 8).TransformBy(ucs);

                        pptx = (ptxt + vec * theight * 5).TransformBy(ucs);

                        ln = new Line(ptxt, ppt);

                        btr.AppendEntity(ln);

                        tr.AddNewlyCreatedDBObject(ln, true);

                        vect = ln.GetFirstDerivative(ppt).GetPerpendicularVector();

                        txt = new DBText();

                        txt.Position = pptx;

                        txt.TextString = string.Format("{0:f2}", leng);// &amp;lt;---  change precision to your needs*************************************************

                        txt.HorizontalMode = TextHorizontalMode.TextCenter;

                        txt.VerticalMode = TextVerticalMode.TextBottom;

                        txt.AlignmentPoint = pptx;

                        ang = ln.Angle + Math.PI;

                        if ((ang &amp;gt; Math.PI / 2) || (ang &amp;lt; Math.PI * 1.5))

                            ang = ang + Math.PI;

                        txt.Rotation = ang;

                        btr.AppendEntity(txt);

                        tr.AddNewlyCreatedDBObject(txt, true);

                    }

                    db.TransactionManager.QueueForGraphicsFlush();

                    tr.Commit();
                }
                catch (Autodesk.AutoCAD.Runtime.Exception ex)
                {
                    MessageBox.Show(string.Format("Error:\n{0}\nTrace:\n{1}", ex.Message, ex.StackTrace));
                }
                finally
                {
                    Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("osmode", osm);
                }
            }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#008000"&gt;~'J'~&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2012 06:37:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/divide-measure-a-polyline-with-a-certain-interval/m-p/3540734#M54534</guid>
      <dc:creator>Hallex</dc:creator>
      <dc:date>2012-07-17T06:37:25Z</dc:date>
    </item>
  </channel>
</rss>

