<?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 curve Polyline by two point in C# in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-curve-polyline-by-two-point-in-c/m-p/10245023#M18011</link>
    <description>&lt;P&gt;Thanks &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/565180"&gt;@Gepaha&lt;/a&gt;&amp;nbsp;, this solved the problem in part. The code works perfectly when I'm in WCS, if I'm working on a custom UCS, it automatically assumes that my PickedPoint is the final vertex of the polyline and when selecting the second point, it doesn't add the new polyline.&lt;/P&gt;</description>
    <pubDate>Fri, 16 Apr 2021 17:08:51 GMT</pubDate>
    <dc:creator>Kélcyo</dc:creator>
    <dc:date>2021-04-16T17:08:51Z</dc:date>
    <item>
      <title>How to copy a part of curve Polyline by two point in C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-curve-polyline-by-two-point-in-c/m-p/9856396#M18000</link>
      <description>&lt;P&gt;Hello everybody,&lt;/P&gt;&lt;P&gt;I have a problem that I want to select a Polyline and it has some arc, then I pick two point in this polyline. The result I want is make a part of polyline I've selected, and the startpoint and endpoint is two point I just pick.&lt;/P&gt;&lt;P&gt;You can see image below to know what exactly I want.&lt;/P&gt;&lt;P&gt;Please help me to solved this issue.&lt;/P&gt;&lt;P&gt;Thank you verymuch!&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 999px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/842159i509209D9C1534CE9/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2020 16:53:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-curve-polyline-by-two-point-in-c/m-p/9856396#M18000</guid>
      <dc:creator>quangpt.tric</dc:creator>
      <dc:date>2020-11-09T16:53:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy a part of curve Polyline by two point in C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-curve-polyline-by-two-point-in-c/m-p/9857142#M18001</link>
      <description>&lt;P&gt;Once you have 2 points on the polyline known (say, picked by user), you can call Curve[Polyline].GetSplitCurves(Point3dCollection) to return a DBObjectCollection that would contain 3 non-database-residing entities, and the second one would be what you want. You can add it to database/transaction, and dispose the other 2.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2020 22:23:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-curve-polyline-by-two-point-in-c/m-p/9857142#M18001</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2020-11-09T22:23:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy a part of curve Polyline by two point in C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-curve-polyline-by-two-point-in-c/m-p/9857539#M18002</link>
      <description>&lt;P&gt;thank you for support me,&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/543921"&gt;@norman.yuan&lt;/a&gt;&amp;nbsp;. Can you give some sample code to make it easier?&lt;/P&gt;</description>
      <pubDate>Tue, 10 Nov 2020 03:24:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-curve-polyline-by-two-point-in-c/m-p/9857539#M18002</guid>
      <dc:creator>quangpt.tric</dc:creator>
      <dc:date>2020-11-10T03:24:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy a part of curve Polyline by two point in C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-curve-polyline-by-two-point-in-c/m-p/9858354#M18003</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/543921"&gt;@norman.yuan&lt;/a&gt;&amp;nbsp;, after coding, now I can solved my issue by your support.&lt;/P&gt;&lt;P&gt;Again, thank you very very much!&lt;/P&gt;</description>
      <pubDate>Tue, 10 Nov 2020 11:17:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-curve-polyline-by-two-point-in-c/m-p/9858354#M18003</guid>
      <dc:creator>quangpt.tric</dc:creator>
      <dc:date>2020-11-10T11:17:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy a part of curve Polyline by two point in C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-curve-polyline-by-two-point-in-c/m-p/9860268#M18004</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7310045"&gt;@quangpt.tric&lt;/a&gt;&amp;nbsp;, after seeing your second post, asking some sample code, I did write a bit of test code. While later you said you solved the issue, I thought I could just polish the test code a bit more to make it as a user-friendly command code sample and publish it in my blog so the code may benefit others. Here is it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://drive-cad-with-code.blogspot.com/2020/11/a-user-friendly-command-to-copy-part-of.html" target="_blank" rel="noopener"&gt;https://drive-cad-with-code.blogspot.com/2020/11/a-user-friendly-command-to-copy-part-of.html&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Nov 2020 22:30:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-curve-polyline-by-two-point-in-c/m-p/9860268#M18004</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2020-11-10T22:30:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy a part of curve Polyline by two point in C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-curve-polyline-by-two-point-in-c/m-p/9860733#M18005</link>
      <description>&lt;P&gt;your code is amazing&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/543921"&gt;@norman.yuan&lt;/a&gt;&amp;nbsp;, I always visit your blog to study coding of autocad,&lt;/P&gt;&lt;P&gt;thank you so much again, my Teacher!&lt;/P&gt;</description>
      <pubDate>Wed, 11 Nov 2020 03:01:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-curve-polyline-by-two-point-in-c/m-p/9860733#M18005</guid>
      <dc:creator>quangpt.tric</dc:creator>
      <dc:date>2020-11-11T03:01:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy a part of curve Polyline by two point in C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-curve-polyline-by-two-point-in-c/m-p/10241526#M18006</link>
      <description>&lt;P&gt;I compiled your available code, but I'm getting an error in version 2021&lt;/P&gt;</description>
      <pubDate>Thu, 15 Apr 2021 16:06:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-curve-polyline-by-two-point-in-c/m-p/10241526#M18006</guid>
      <dc:creator>Kélcyo</dc:creator>
      <dc:date>2021-04-15T16:06:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy a part of curve Polyline by two point in C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-curve-polyline-by-two-point-in-c/m-p/10241625#M18007</link>
      <description>&lt;P&gt;You may want to provide more details on the error. Also did you step through the code to see which line of the code raises the error? If you did, you might have already known the reason and possibly the fix of it. I believe that whatever the error is, it is unlikely Acad2020 versus 2021 would be the cause of it for such a simple project.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Apr 2021 16:22:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-curve-polyline-by-two-point-in-c/m-p/10241625#M18007</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2021-04-15T16:22:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy a part of curve Polyline by two point in C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-curve-polyline-by-two-point-in-c/m-p/10241801#M18008</link>
      <description>&lt;P&gt;Yes, I went through the code, but I don't see a simple solution. When exiting the Finaly loop (shown in the image), simply go to Catch with the message indication "ex.Message =" Object reference not set to an instance of an object. ""&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="erroPoly.png" style="width: 536px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/907223i0A71838C7271953F/image-dimensions/536x869?v=v2" width="536" height="869" role="button" title="erroPoly.png" alt="erroPoly.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="erroPoly2.png" style="width: 702px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/907224iDAE585B382B7D4BD/image-dimensions/702x217?v=v2" width="702" height="217" role="button" title="erroPoly2.png" alt="erroPoly2.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Apr 2021 17:07:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-curve-polyline-by-two-point-in-c/m-p/10241801#M18008</guid>
      <dc:creator>Kélcyo</dc:creator>
      <dc:date>2021-04-15T17:07:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy a part of curve Polyline by two point in C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-curve-polyline-by-two-point-in-c/m-p/10242721#M18009</link>
      <description>&lt;P&gt;Any suggestion&lt;/P&gt;</description>
      <pubDate>Fri, 16 Apr 2021 00:14:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-curve-polyline-by-two-point-in-c/m-p/10242721#M18009</guid>
      <dc:creator>Kélcyo</dc:creator>
      <dc:date>2021-04-16T00:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy a part of curve Polyline by two point in C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-curve-polyline-by-two-point-in-c/m-p/10244206#M18010</link>
      <description>&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;I think that the variable&lt;FONT face="courier new,courier"&gt;_ghostPolyline&lt;/FONT&gt;&amp;nbsp;is null in the statement:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&lt;FONT face="courier new,courier"&gt;e.AppendToolTipText($"Selected polyline length = {_&lt;FONT color="#FF0000"&gt;ghostPolyline.Length&lt;/FONT&gt;}");&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;This causes the null reference exception. Try to move the above statement into the if:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;if (ghost != null)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp; &amp;nbsp;...&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&amp;nbsp; &amp;nbsp;e.AppendToolTipText($"Selected polyline length = {_ghostPolyline.Length}");&lt;/FONT&gt;&lt;BR /&gt;} &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;In&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="courier new,courier"&gt;private void Editor_PointMonitor(object sender, PointMonitorEventArgs e)&lt;FONT face="arial,helvetica,sans-serif"&gt; change:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt; if (ghost != null)
 {
    _ghostPolyline = ghost;
    _ghostPolyline.ColorIndex = 1;
    _tsManager.AddTransient(_ghostPolyline, TransientDrawingMode.DirectTopmost, 128, new IntegerCollection());
 }
 e.AppendToolTipText($"Selected polyline length = {_ghostPolyline.Length}";   &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;to:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt; if (ghost != null)
 {
    _ghostPolyline = ghost;
    _ghostPolyline.ColorIndex = 1;
    _tsManager.AddTransient(_ghostPolyline, TransientDrawingMode.DirectTopmost, 128, new IntegerCollection());
    e.AppendToolTipText($"Selected polyline length = {_ghostPolyline.Length}");
}    &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope it helps!&lt;/P&gt;</description>
      <pubDate>Fri, 16 Apr 2021 13:18:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-curve-polyline-by-two-point-in-c/m-p/10244206#M18010</guid>
      <dc:creator>Gepaha</dc:creator>
      <dc:date>2021-04-16T13:18:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy a part of curve Polyline by two point in C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-curve-polyline-by-two-point-in-c/m-p/10245023#M18011</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/565180"&gt;@Gepaha&lt;/a&gt;&amp;nbsp;, this solved the problem in part. The code works perfectly when I'm in WCS, if I'm working on a custom UCS, it automatically assumes that my PickedPoint is the final vertex of the polyline and when selecting the second point, it doesn't add the new polyline.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Apr 2021 17:08:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-curve-polyline-by-two-point-in-c/m-p/10245023#M18011</guid>
      <dc:creator>Kélcyo</dc:creator>
      <dc:date>2021-04-16T17:08:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy a part of curve Polyline by two point in C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-curve-polyline-by-two-point-in-c/m-p/10245168#M18012</link>
      <description>&lt;P&gt;I have no time to test this for now.&lt;/P&gt;&lt;P&gt;Points obtained through Editor.GetPoint are always in UCS.&lt;/P&gt;&lt;P&gt;If the picked point has to participate into some geometry creation or calculation, it has to be transformed from its UCS to WCS since all AutoCAD geometry information is stored&amp;nbsp;in WCS.&lt;/P&gt;&lt;P&gt;Look at the example below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptPointResult ppr = ed.GetPoint("\nSpecify base point: ");
if (ppr.Status != PromptStatus.OK) return;
// point in UCS
Point3d ucsPt = ppr.Value;
// point in WCS
Point3d wcsPt = ucsPt.TransformBy(ed.CurrentUserCoordinateSystem);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt; private ObjectId SelectPolyline(out Point3d pickPoint)
        {
            pickPoint = Point3d.Origin;
            var opt = new PromptEntityOptions("\nSelect a polyline:");
            opt.SetRejectMessage("\nInvalid: not a polyline!");
            opt.AddAllowedClass(typeof(CadDb.Polyline), true);

            var res = _ed.GetEntity(opt);
            
            if (res.Status == PromptStatus.OK)
            {
                using (var tran =  res.ObjectId.Database.TransactionManager.StartTransaction())
                {
                    var poly = (CadDb.Polyline)tran.GetObject(res.ObjectId, OpenMode.ForRead);
                    //make sure the output point is on the polyline
                    //pickPoint = poly.GetClosestPointTo(res.PickedPoint, false);
                    // from UCS to WCS
                    pickPoint = poly.GetClosestPointTo(res.PickedPoint.TransformBy(_ed.CurrentUserCoordinateSystem), false);                    
                    tran.Commit();
                }
                return res.ObjectId;
            }
            else
            {
                return ObjectId.Null;
            }
        }&lt;/LI-CODE&gt;&lt;LI-CODE lang="csharp"&gt;        private bool SelectTwoPointsOnPolyline(ObjectId polyId, Point3d prevPoint, out Point3d startPt, out Point3d endPt)
        {
            startPt = Point3d.Origin;
            endPt = Point3d.Origin;

            _firstPoint = prevPoint;
            var nextPoint = Point3d.Origin;
            _polylineId = polyId;

            bool ok = false;
            using (var tran = _dwg.TransactionManager.StartTransaction())
            {
                var poly = (CadDb.Polyline)tran.GetObject(polyId, OpenMode.ForRead);

                while (true)
                {
                    ClearGhostPolyline();
                    var opt = new PromptPointOptions("\nSelect second point on the polyline:")
                    {
                        AppendKeywordsToMessage = true,
                        AllowNone = true
                    };
                    opt.Keywords.Add("First point");
                    opt.Keywords.Default = "First point";

                    PromptPointResult res;
                    try
                    {
                        // when selecting another point on polyline
                        // show the part of polyline to be cloned
                        // as Transient Graphics
                        _ed.PointMonitor += Editor_PointMonitor;
                        res = _ed.GetPoint(opt);
                    }                   
                    finally
                    {
                        _ed.PointMonitor -= Editor_PointMonitor;
                        ClearGhostPolyline();
                    }

                    if (res.Status == PromptStatus.OK)
                    {
                        //nextPoint = poly.GetClosestPointTo(res.Value, false);
                        // from UCS to WCS
                        nextPoint = poly.GetClosestPointTo(res.Value.TransformBy(_ed.CurrentUserCoordinateSystem), false);                        
                        ok = true;
                        break;
                    }
                    else if (res.Status == PromptStatus.Keyword)
                    {
                        // re-select the first point on polyline
                        var cancel = false;
                        while (true)
                        {
                            var op = new PromptPointOptions("\nSelect first point on polyline:");
                            var rs = _ed.GetPoint(op);
                            if (rs.Status == PromptStatus.OK)
                            {
                                //_firstPoint = poly.GetClosestPointTo(rs.Value, false);  
                                // from UCS to WCS 
                                _firstPoint = poly.GetClosestPointTo(rs.Value.TransformBy(_ed.CurrentUserCoordinateSystem), false);                                
                                break;
                            }
                            else
                            {
                                cancel = true;
                                break;
                            }
                        }

                        if (cancel)
                        {
                            ok = false;
                            break;
                        }
                    }
                    else
                    {
                        ok = false;
                        break;
                    }
                }

                if (ok)
                {
                    SortPickedPoints(poly, _firstPoint, nextPoint, out startPt, out endPt);
                }
                tran.Commit();
            }
            return ok;
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I haven't forgotten something I think it should work.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Apr 2021 18:32:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-curve-polyline-by-two-point-in-c/m-p/10245168#M18012</guid>
      <dc:creator>Gepaha</dc:creator>
      <dc:date>2021-04-16T18:32:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy a part of curve Polyline by two point in C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-curve-polyline-by-two-point-in-c/m-p/10253575#M18013</link>
      <description>&lt;P&gt;Excellent..working perfect..thanks&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 13:12:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-copy-a-part-of-curve-polyline-by-two-point-in-c/m-p/10253575#M18013</guid>
      <dc:creator>Kélcyo</dc:creator>
      <dc:date>2021-04-20T13:12:20Z</dc:date>
    </item>
  </channel>
</rss>

