<?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 Re: How to copy a part of polyline in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-polyline/m-p/3558938#M54287</link>
    <description>&lt;P&gt;Thanks for reply of Balaji_Ram and&amp;nbsp; Hallex. Maybe my poor representation,gives a misunderstand.&lt;/P&gt;&lt;P&gt;In fact,I want to extract a part of vertex from a old polyline to form a new polyline.For example,my code intends to get 0,2,4,6,... vertex from pline,then to create a new polyline named acPoly.&lt;BR /&gt;The motive behind my question is to simplify contour lines in terrain which own too dense vertex. Anyone can help me?thanks.&lt;/P&gt;</description>
    <pubDate>Tue, 31 Jul 2012 07:21:30 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2012-07-31T07:21:30Z</dc:date>
    <item>
      <title>How to copy a part of polyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-polyline/m-p/3555140#M54284</link>
      <description>&lt;P&gt;Hi,everyone,&lt;/P&gt;&lt;P&gt;I am a beginer of AutoCAD.net. My question is how to create a new polyline which vertex is from a old polyline.&lt;BR /&gt;My code seems have a copy a polyline in debug, but I can't find the new polyline in AutoCAD,why?&lt;/P&gt;&lt;P&gt;The code is below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [CommandMethod("CopyPartPolyline")]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void CopyPartPolyline()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Document acDoc = Application.DocumentManager.MdiActiveDocument;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Database acCurDb = acDoc.Database;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Polyline pline = selectOnePolyline(acCurDb); //prompt user to select a polyline from screen&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BlockTable acBlkTbl;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,OpenMode.ForRead) as BlockTable;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BlockTableRecord acBlkTblRec;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],OpenMode.ForWrite) as BlockTableRecord;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Create a lightweight polyline&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Polyline acPoly = new Polyline();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; acPoly.SetDatabaseDefaults();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (int i = 0; i &amp;lt; pline.NumberOfVertices; i=i+2)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; double x = pline.GetPoint2dAt(i).X; double y = pline.GetPoint2dAt(i).Y;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; acPoly.AddVertexAt(i/2, new Point2d(x, y), 0, 0, 0);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; acBlkTblRec.AppendEntity(acPoly);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; acTrans.AddNewlyCreatedDBObject(acPoly, true);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; acPoly.Closed = true;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; acTrans.Commit();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jul 2012 08:43:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-polyline/m-p/3555140#M54284</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-07-27T08:43:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy a part of polyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-polyline/m-p/3557576#M54285</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The "index" parameter in the call to "AddVertexAt" seems to be wrong.&lt;/P&gt;
&lt;P&gt;You will need to check the code carefully. As a first step, try creating a copy of the original polyline. After that is done, you may modify it the way you want the new polyline to appear.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the first step :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;			Document activeDoc = Application.DocumentManager.MdiActiveDocument;
			Database db = activeDoc.Database;
			Editor ed = activeDoc.Editor;

			PromptEntityOptions peo = new PromptEntityOptions("Select a polyline : ");
			peo.SetRejectMessage("Not a polyline");
			peo.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Polyline), true);
			PromptEntityResult per = ed.GetEntity(peo);
			if (per.Status != PromptStatus.OK)
				return;

			using (Transaction acTrans = db.TransactionManager.StartTransaction())
			{
				BlockTable acBlkTbl;
				acBlkTbl = acTrans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;

				Autodesk.AutoCAD.DatabaseServices.Polyline pline = acTrans.GetObject(per.ObjectId, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Polyline;

				BlockTableRecord acBlkTblRec;
				acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

				// Create a lightweight polyline
				Autodesk.AutoCAD.DatabaseServices.Polyline acPoly = new Autodesk.AutoCAD.DatabaseServices.Polyline();
				acPoly.SetDatabaseDefaults();

				int index = 0;
				for (int i = 0; i &amp;lt; pline.NumberOfVertices; i++)
				{
					double x = pline.GetPoint2dAt(i).X; 
					double y = pline.GetPoint2dAt(i).Y;
					acPoly.AddVertexAt(index, new Point2d(x, y), 0, 0, 0);
					index++;
				}
				acBlkTblRec.AppendEntity(acPoly);
				acTrans.AddNewlyCreatedDBObject(acPoly, true);
				acPoly.Closed = true;
				acTrans.Commit();
			}&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jul 2012 12:43:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-polyline/m-p/3557576#M54285</guid>
      <dc:creator>Balaji_Ram</dc:creator>
      <dc:date>2012-07-30T12:43:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy a part of polyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-polyline/m-p/3558170#M54286</link>
      <description>&lt;P&gt;Here is quick and dirty example to copy segment of polyline,&lt;/P&gt;&lt;P&gt;see if this what you looking for&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        [CommandMethod("copyseg")]
        public void copySegment()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;
            PromptEntityOptions peo = new PromptEntityOptions("\nSelect the segment to copy: ");
            peo.SetRejectMessage("\nYou have to select polyline only!");
            peo.AllowNone = false;
            peo.AllowObjectOnLockedLayer = false;
            peo.AddAllowedClass(typeof(Polyline), true);
            PromptEntityResult per = ed.GetEntity(peo);
            if (per.Status == PromptStatus.OK)
            {
  
                ObjectId objId = per.ObjectId;
                try
                {
                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        Polyline pline = tr.GetObject(objId, OpenMode.ForRead, false) as Polyline;
                        if (pline != null)
                        {
                            BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId,OpenMode.ForWrite, false) as BlockTableRecord;
                            Point3d pickPt = pline.GetClosestPointTo((Point3d)per.PickedPoint, false);
                            double param = pline.GetParameterAtPoint(pickPt);
                            int index = (int)param;
                          double swid=  pline.GetStartWidthAt(index);
                          double ewid = pline.GetEndWidthAt(index);

                          SegmentType stype=  pline.GetSegmentType(index);
                          if (stype == SegmentType.Line)
                          {
                             LineSegment2d lineseg= pline.GetLineSegment2dAt(index);
                              Polyline spoly = new Polyline();
                              Point2d sp = lineseg.StartPoint;
                              Point2d ep = lineseg.EndPoint;
                              spoly.AddVertexAt(0, sp, 0, swid, ewid);
                              spoly.AddVertexAt(1, ep,0,swid,ewid);
                              spoly.ColorIndex = 1;
                              btr.AppendEntity(spoly);
                              tr.AddNewlyCreatedDBObject(spoly, true);

                          }
                          if (stype == SegmentType.Arc)
                          {
                              CircularArc2d arcseg = pline.GetArcSegment2dAt(index);
                              Polyline spoly = new Polyline();
                              Point2d sp = arcseg.StartPoint;
                              Point2d ep = arcseg.EndPoint;
                              double boo = pline.GetBulgeAt(index);

                              spoly.AddVertexAt(0, sp, boo, swid, ewid);
                              spoly.AddVertexAt(1, ep, boo, swid, ewid);
                              spoly.ColorIndex = 2;
                              btr.AppendEntity(spoly);
                              tr.AddNewlyCreatedDBObject(spoly, true);

                          }
                        }
                        tr.Commit();
                    }
                }
                catch (System.Exception ex)
                {
   
                    ed.WriteMessage("\nError: {0}\nTrace: {1}" , ex.Message , ex.StackTrace);
                }
            }
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800000" face="arial,helvetica,sans-serif"&gt;~'J'~&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jul 2012 17:28:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-polyline/m-p/3558170#M54286</guid>
      <dc:creator>Hallex</dc:creator>
      <dc:date>2012-07-30T17:28:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy a part of polyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-polyline/m-p/3558938#M54287</link>
      <description>&lt;P&gt;Thanks for reply of Balaji_Ram and&amp;nbsp; Hallex. Maybe my poor representation,gives a misunderstand.&lt;/P&gt;&lt;P&gt;In fact,I want to extract a part of vertex from a old polyline to form a new polyline.For example,my code intends to get 0,2,4,6,... vertex from pline,then to create a new polyline named acPoly.&lt;BR /&gt;The motive behind my question is to simplify contour lines in terrain which own too dense vertex. Anyone can help me?thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jul 2012 07:21:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-polyline/m-p/3558938#M54287</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-07-31T07:21:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy a part of polyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-polyline/m-p/3558948#M54288</link>
      <description>&lt;P&gt;In the code snippet that I earlier posted, replace this code and&amp;nbsp;try&amp;nbsp;it.&lt;/P&gt;
&lt;PRE&gt;		int index = 0;
		for (int i = 0; i &amp;lt; pline.NumberOfVertices; i++)
		{
			if (i % 2 == 0)
			{
				double x = pline.GetPoint2dAt(i).X;
				double y = pline.GetPoint2dAt(i).Y;
				acPoly.AddVertexAt(index, new Point2d(x, y), 0, 0, 0);
				index++;
			}
		}&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jul 2012 07:35:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-polyline/m-p/3558948#M54288</guid>
      <dc:creator>Balaji_Ram</dc:creator>
      <dc:date>2012-07-31T07:35:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy a part of polyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-polyline/m-p/3559022#M54289</link>
      <description>&lt;P&gt;That's OK. Thanks,Balaji_Ram.&lt;/P&gt;&lt;P&gt;Another,I&amp;nbsp;know why I can't find new polyline on screen. I used "db.GetObject()",but not "acTrans.GetObject()".&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jul 2012 08:56:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-polyline/m-p/3559022#M54289</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-07-31T08:56:12Z</dc:date>
    </item>
  </channel>
</rss>

