<?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 find the curves that cannot be joined in a selection set? in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-to-find-the-curves-that-cannot-be-joined-in-a-selection-set/m-p/10140722#M17295</link>
    <description>&lt;P&gt;Your&amp;nbsp;GeometryExtensions is so great.&lt;/P&gt;&lt;P&gt;But the following code is ok for all the curves except polyline.&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the selectionset has a polyline, an error will throw:&lt;/P&gt;&lt;P&gt;The best overloaded method match for 'GeometryExtensions.PolylineSegmentCollection.PolylineSegmentCollection(System.Collections.Generic.IEnumerable&amp;lt;GeometryExtensions.PolylineSegment&amp;gt;)' has some invalid arguments.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public void MPline()
{
    var db = HostApplicationServices.WorkingDatabase;
    Editor ed = app.DocumentManager.MdiActiveDocument.Editor;
    TypedValue[] filter = {
        new TypedValue(0,"ARC,LINE,LWPOLYLINE,POLYLINE") };
    var psr = ed.GetSelection(new SelectionFilter(filter));
    if (psr.Status != PromptStatus.OK) return;
    dynamic ms = SymbolUtilityServices.GetBlockModelSpaceId(db);
    dynamic ids = psr.Value.GetObjectIds();
    PolylineSegmentCollection psc = new PolylineSegmentCollection();
    Plane plane = new Plane(Point3d.Origin, Vector3d.ZAxis);
    foreach (dynamic id in ids)
    {
        switch (id.GetType().Name)
        {
            case "Arc":
                psc.Add(new PolylineSegment(
                    new CircularArc2d(
                        id.Center.Convert2d(plane),
                        id.Radius,
                        id.StartAngle,
                        id.EndAngle,
                        Vector2d.XAxis,
                        false)));
                break;
            case "Ellipse":
                psc.AddRange(new PolylineSegmentCollection(id));
                break;
            case "Line":
                psc.Add(new PolylineSegment(
                    new LineSegment2d(
                        id.StartPoint.Convert2d(plane),
                        id.EndPoint.Convert2d(plane))));
                break;
            case "Polyline":
                psc.AddRange(new PolylineSegmentCollection(id));
                break;
        }
    }
    foreach (var segs in psc.Join())
    {
        var pline = segs.ToPolyline();
        ms.AppendEntity(pline);
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 09 Mar 2021 01:31:11 GMT</pubDate>
    <dc:creator>arxbird</dc:creator>
    <dc:date>2021-03-09T01:31:11Z</dc:date>
    <item>
      <title>How to find the curves that cannot be joined in a selection set?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-find-the-curves-that-cannot-be-joined-in-a-selection-set/m-p/10137665#M17293</link>
      <description>&lt;P&gt;How to find the curves that cannot be joined in a selection set?&lt;/P&gt;</description>
      <pubDate>Mon, 08 Mar 2021 01:53:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-find-the-curves-that-cannot-be-joined-in-a-selection-set/m-p/10137665#M17293</guid>
      <dc:creator>arxbird</dc:creator>
      <dc:date>2021-03-08T01:53:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the curves that cannot be joined in a selection set?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-find-the-curves-that-cannot-be-joined-in-a-selection-set/m-p/10137943#M17294</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;You can have a look at the &lt;A href="http://www.theswamp.org/index.php?topic=31865.msg373672#msg373672" target="_blank" rel="noopener"&gt;&lt;STRONG&gt;GeometryExtension&lt;/STRONG&gt;&lt;/A&gt; library at TheSwamp, the PolylineSegmentCollection class provides a Join() method.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.theswamp.org/index.php?topic=31865.msg446965#msg446965" target="_self"&gt;&lt;STRONG&gt;This reply&lt;/STRONG&gt;&lt;/A&gt; shows a using example of the PolylineSegmentCollection.Join method.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Mar 2021 06:27:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-find-the-curves-that-cannot-be-joined-in-a-selection-set/m-p/10137943#M17294</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2021-03-08T06:27:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the curves that cannot be joined in a selection set?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-find-the-curves-that-cannot-be-joined-in-a-selection-set/m-p/10140722#M17295</link>
      <description>&lt;P&gt;Your&amp;nbsp;GeometryExtensions is so great.&lt;/P&gt;&lt;P&gt;But the following code is ok for all the curves except polyline.&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the selectionset has a polyline, an error will throw:&lt;/P&gt;&lt;P&gt;The best overloaded method match for 'GeometryExtensions.PolylineSegmentCollection.PolylineSegmentCollection(System.Collections.Generic.IEnumerable&amp;lt;GeometryExtensions.PolylineSegment&amp;gt;)' has some invalid arguments.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public void MPline()
{
    var db = HostApplicationServices.WorkingDatabase;
    Editor ed = app.DocumentManager.MdiActiveDocument.Editor;
    TypedValue[] filter = {
        new TypedValue(0,"ARC,LINE,LWPOLYLINE,POLYLINE") };
    var psr = ed.GetSelection(new SelectionFilter(filter));
    if (psr.Status != PromptStatus.OK) return;
    dynamic ms = SymbolUtilityServices.GetBlockModelSpaceId(db);
    dynamic ids = psr.Value.GetObjectIds();
    PolylineSegmentCollection psc = new PolylineSegmentCollection();
    Plane plane = new Plane(Point3d.Origin, Vector3d.ZAxis);
    foreach (dynamic id in ids)
    {
        switch (id.GetType().Name)
        {
            case "Arc":
                psc.Add(new PolylineSegment(
                    new CircularArc2d(
                        id.Center.Convert2d(plane),
                        id.Radius,
                        id.StartAngle,
                        id.EndAngle,
                        Vector2d.XAxis,
                        false)));
                break;
            case "Ellipse":
                psc.AddRange(new PolylineSegmentCollection(id));
                break;
            case "Line":
                psc.Add(new PolylineSegment(
                    new LineSegment2d(
                        id.StartPoint.Convert2d(plane),
                        id.EndPoint.Convert2d(plane))));
                break;
            case "Polyline":
                psc.AddRange(new PolylineSegmentCollection(id));
                break;
        }
    }
    foreach (var segs in psc.Join())
    {
        var pline = segs.ToPolyline();
        ms.AppendEntity(pline);
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Mar 2021 01:31:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-find-the-curves-that-cannot-be-joined-in-a-selection-set/m-p/10140722#M17295</guid>
      <dc:creator>arxbird</dc:creator>
      <dc:date>2021-03-09T01:31:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the curves that cannot be joined in a selection set?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-find-the-curves-that-cannot-be-joined-in-a-selection-set/m-p/10141043#M17296</link>
      <description>&lt;P&gt;if you also want to process old style 2d polylines, you should use a better selection filter to avoid polyline3d, polygon meshes and polyfaces (&lt;A href="https://help.autodesk.com/view/OARX/2019/ENU/?guid=GUID-ABF6B778-BE20-4B49-9B58-A94E64CEFFF3" target="_blank" rel="noopener"&gt;which dxf name is also POLYLINE&lt;/A&gt;) and you have to add the Polyline2d type in the switch statement.&lt;/P&gt;
&lt;P&gt;IMHO, you should not use the dynamic type which makes you lose all the help that Visual Studio provides with the strong types..&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;public void Mpline()
{
    var db = HostApplicationServices.WorkingDatabase;
    var ed = AcAp.DocumentManager.MdiActiveDocument.Editor;
    TypedValue[] filter = {
        new TypedValue(-4,"&amp;lt;OR"),
        new TypedValue(0, "ARC,LINE,LWPOLYLINE"),
        new TypedValue(-4, "&amp;lt;AND"),
        new TypedValue(0, "POLYLINE"),
        new TypedValue(-4, "&amp;lt;NOT"),
        new TypedValue(-4, "&amp;amp;"),
        new TypedValue(70, 8 | 16 | 32 | 64), // only Polyline2d
        new TypedValue(-4, "NOT&amp;gt;"),
        new TypedValue(-4, "AND&amp;gt;"),
        new TypedValue(-4, "OR&amp;gt;")};
    PromptSelectionResult psr = ed.GetSelection(new SelectionFilter(filter));
    if (psr.Status != PromptStatus.OK) return;
    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
        BlockTableRecord btr =
            (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
        PolylineSegmentCollection psc = new PolylineSegmentCollection();
        Plane plane = new Plane(Point3d.Origin, Vector3d.ZAxis);
        foreach (ObjectId id in psr.Value.GetObjectIds())
        {
            Entity ent = (Entity)tr.GetObject(id, OpenMode.ForRead);
            switch (ent)
            {
                case Arc arc:
                    psc.Add(new PolylineSegment(
                        new CircularArc2d(
                            arc.Center.Convert2d(plane),
                            arc.Radius,
                            arc.StartAngle,
                            arc.EndAngle,
                            Vector2d.XAxis,
                            false)));
                    break;
                case Line line:
                    psc.Add(new PolylineSegment(
                        new LineSegment2d(
                            line.StartPoint.Convert2d(plane),
                            line.EndPoint.Convert2d(plane))));
                    break;
                case Polyline pline:
                    psc.AddRange(new PolylineSegmentCollection(pline));
                    break;
                case Polyline2d pline2d:
                    psc.AddRange(new PolylineSegmentCollection(pline2d));
                    break;
                default:
                    break;
            }
        }
        foreach (PolylineSegmentCollection segs in psc.Join())
        {
            Polyline pline = segs.ToPolyline();
            btr.AppendEntity(pline);
            tr.AddNewlyCreatedDBObject(pline, true);
        }
        tr.Commit();
    }
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Mar 2021 05:16:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-find-the-curves-that-cannot-be-joined-in-a-selection-set/m-p/10141043#M17296</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2021-03-09T05:16:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the curves that cannot be joined in a selection set?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-find-the-curves-that-cannot-be-joined-in-a-selection-set/m-p/10141050#M17297</link>
      <description>&lt;P&gt;Thanks a lot.The code runs correctly.&lt;/P&gt;&lt;P&gt;Another question:&lt;/P&gt;&lt;P&gt;psc.Join() can join the curves&amp;nbsp;correctly.How to get the curves that cannot be joined?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Mar 2021 05:25:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-find-the-curves-that-cannot-be-joined-in-a-selection-set/m-p/10141050#M17297</guid>
      <dc:creator>arxbird</dc:creator>
      <dc:date>2021-03-09T05:25:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the curves that cannot be joined in a selection set?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-find-the-curves-that-cannot-be-joined-in-a-selection-set/m-p/10142705#M17298</link>
      <description>&lt;P&gt;You can try this:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;public static List&amp;lt;Curve&amp;gt; GetCurvesThatCannotBeJoined(List&amp;lt;Curve&amp;gt; source, Tolerance tolerance)
{
    bool IsJoinable(Curve curve1, Curve curve2) =&amp;gt;
        !(curve1 is Xline || curve1 is Ray || curve1.Closed ||
        curve2 is Xline || curve2 is Ray || curve2.Closed) &amp;amp;&amp;amp;
        (curve1.StartPoint.IsEqualTo(curve2.StartPoint, tolerance) ||
        curve1.StartPoint.IsEqualTo(curve2.EndPoint, tolerance) ||
        curve1.EndPoint.IsEqualTo(curve2.StartPoint, tolerance) ||
        curve1.EndPoint.IsEqualTo(curve2.EndPoint, tolerance));

    var result = new List&amp;lt;Curve&amp;gt;();
    for (int i = 0; i &amp;lt; source.Count - 1; i++)
    {
        bool joinable = false;
        for (int j = i + 1; j &amp;lt; source.Count; j++)
        {
            if (IsJoinable(source[i], source[j]))
            {
                joinable = true;
                break;
            }
        }
        if (!joinable)
        {
            result.Add(source[i]);
        }
    }
    return result;
}&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 09 Mar 2021 17:15:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-find-the-curves-that-cannot-be-joined-in-a-selection-set/m-p/10142705#M17298</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2021-03-09T17:15:18Z</dc:date>
    </item>
  </channel>
</rss>

