<?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 coordinates of a line parallel to another on the same layer in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-to-find-the-coordinates-of-a-line-parallel-to-another-on-the/m-p/10854918#M14253</link>
    <description>&lt;P&gt;As you certainly noticed, the code uses the LineSegment3d type which exposes a GetDistanceTo method. This method is used to find the closest parallel line.&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;        [CommandMethod("FINDPARALLEL")]
        public static void FindClosestParallelLineCmd()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            var options = new PromptEntityOptions("\nSelect Line: ");
            options.SetRejectMessage("Must be a Line.");
            options.AddAllowedClass(typeof(Line), true);
            var result = ed.GetEntity(options);
            if (result.Status != PromptStatus.OK) 
                return;
            using (var tr = db.TransactionManager.StartTransaction())
            {
                var source = (Line)tr.GetObject(result.ObjectId, OpenMode.ForRead);
                if (TryFindParallelLine(source, tr, out LineSegment3d line, out double distance))
                {
                    ed.WriteMessage(
                        "\nStart point: {0:0.00} End point: {1:0.00}\nDistance = {2:0.00}", 
                        line.StartPoint, 
                        line.EndPoint, 
                        distance);
                }
                else
                {
                    ed.WriteMessage("\nNone parallel line");
                }
                tr.Commit();
            }
        }

        static bool TryFindParallelLine(Line source, Transaction tr, out LineSegment3d line, out double distance)
        {
            string layer = source.Layer;
            var segment = new LineSegment3d(source.StartPoint, source.EndPoint);
            var direction = segment.Direction;
            var segments =
                ((BlockTableRecord)tr.GetObject(source.OwnerId, OpenMode.ForRead))
                .Cast&amp;lt;ObjectId&amp;gt;()
                .Where(id =&amp;gt; id != source.ObjectId &amp;amp;&amp;amp; id.ObjectClass.DxfName == "LINE")
                .Select(id =&amp;gt; (Line)tr.GetObject(id, OpenMode.ForRead))
                .Where(l =&amp;gt; l.Layer == layer)
                .Select(l =&amp;gt; new LineSegment3d(l.StartPoint, l.EndPoint))
                .Where(s =&amp;gt; s.Direction.IsParallelTo(direction));
            if (segments.Any())
            {
                line = segments.Aggregate((s1, s2) =&amp;gt;
                    (s1.GetDistanceTo(segment) &amp;lt; s2.GetDistanceTo(segment)) ? s1 : s2);
                distance = line.GetDistanceTo(segment);
                return true;
            }
            else
            {
                line = null;
                distance = -1.0;
                return false;
            }
        }&lt;/LI-CODE&gt;</description>
    <pubDate>Mon, 03 Jan 2022 12:35:36 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2022-01-03T12:35:36Z</dc:date>
    <item>
      <title>How to find the coordinates of a line parallel to another on the same layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-find-the-coordinates-of-a-line-parallel-to-another-on-the/m-p/10851881#M14249</link>
      <description>&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;Hi everyone.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;How could I do to identify the start and end coordinates of the parallel line closest to another and which are on the same layer?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;Thanks a lot, bye.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Dec 2021 17:58:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-find-the-coordinates-of-a-line-parallel-to-another-on-the/m-p/10851881#M14249</guid>
      <dc:creator>mecoman6GF27</dc:creator>
      <dc:date>2021-12-31T17:58:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the coordinates of a line parallel to another on the same layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-find-the-coordinates-of-a-line-parallel-to-another-on-the/m-p/10851913#M14250</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I think this will help you&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/net/parallel-loop/m-p/3726470" target="_blank"&gt;https://forums.autodesk.com/t5/net/parallel-loop/m-p/3726470&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Dec 2021 18:34:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-find-the-coordinates-of-a-line-parallel-to-another-on-the/m-p/10851913#M14250</guid>
      <dc:creator>hosneyalaa</dc:creator>
      <dc:date>2021-12-31T18:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the coordinates of a line parallel to another on the same layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-find-the-coordinates-of-a-line-parallel-to-another-on-the/m-p/10852459#M14251</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can try something like this:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;        [CommandMethod("FINDPARALLEL")]
        public static void FindClosestParallelLineCmd()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            var options = new PromptEntityOptions("\nSelect Line: ");
            options.SetRejectMessage("Must be a Line.");
            options.AddAllowedClass(typeof(Line), true);
            var result = ed.GetEntity(options);
            if (result.Status != PromptStatus.OK) 
                return;
            using (var tr = db.TransactionManager.StartTransaction())
            {
                var source = (Line)tr.GetObject(result.ObjectId, OpenMode.ForRead);
                if (TryFindParallelLine(source, tr, out LineSegment3d line))
                {
                    ed.WriteMessage("\nStart point: {0:0.00} End point: {1:0.00}", line.StartPoint, line.EndPoint);
                }
                else
                {
                    ed.WriteMessage("\nNone parallel line");
                }
                tr.Commit();
            }
        }

        static bool TryFindParallelLine(Line source, Transaction tr, out LineSegment3d line)
        {
            string layer = source.Layer;
            var segment = new LineSegment3d(source.StartPoint, source.EndPoint);
            var direction = segment.Direction;
            var segments =
                ((BlockTableRecord)tr.GetObject(source.OwnerId, OpenMode.ForRead))
                .Cast&amp;lt;ObjectId&amp;gt;()
                .Where(id =&amp;gt; id != source.ObjectId &amp;amp;&amp;amp; id.ObjectClass.DxfName == "LINE")
                .Select(id =&amp;gt; (Line)tr.GetObject(id, OpenMode.ForRead))
                .Where(l =&amp;gt; l.Layer == layer)
                .Select(l =&amp;gt; new LineSegment3d(l.StartPoint, l.EndPoint))
                .Where(s =&amp;gt; s.Direction.IsParallelTo(direction));
            if (segments.Any())
            {
                line = segments.Aggregate((s1, s2) =&amp;gt;
                    (s1.GetDistanceTo(segment) &amp;lt; s2.GetDistanceTo(segment)) ? s1 : s2);
                return true;
            }
            else
            {
                line = null;
                return false;
            }
        }&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 01 Jan 2022 11:08:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-find-the-coordinates-of-a-line-parallel-to-another-on-the/m-p/10852459#M14251</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2022-01-01T11:08:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the coordinates of a line parallel to another on the same layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-find-the-coordinates-of-a-line-parallel-to-another-on-the/m-p/10854769#M14252</link>
      <description>&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;Hi, thank you so much for your help.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;Your code works perfectly but I asked myself: how can I find the perpendicular distance between the two parallel lines?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="img.jpg" style="width: 155px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1006830i29A4FADF05CB8348/image-size/small?v=v2&amp;amp;px=200" role="button" title="img.jpg" alt="img.jpg" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;I tried like this:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;ed.WriteMessage (vbLf &amp;amp; "Perpendicular distance beetwen line1 and line2:" &amp;amp; line.StartPoint.DistanceTo (source.GetClosestPointTo (line.StartPoint, False)))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;What I have written only works in three cases:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;1. when the two lines are inclined at a certain angle;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;2. when the two lines have the same length;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;3. when I select the longest line.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;If the two lines, horizontal or vertical, have a different length and I select the shorter line, I get the distance between points A and C and not the perpendicular distance between the two lines.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;Where do you think I'm wrong?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;Thanks a lot, bye.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jan 2022 10:53:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-find-the-coordinates-of-a-line-parallel-to-another-on-the/m-p/10854769#M14252</guid>
      <dc:creator>mecoman6GF27</dc:creator>
      <dc:date>2022-01-03T10:53:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the coordinates of a line parallel to another on the same layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-find-the-coordinates-of-a-line-parallel-to-another-on-the/m-p/10854918#M14253</link>
      <description>&lt;P&gt;As you certainly noticed, the code uses the LineSegment3d type which exposes a GetDistanceTo method. This method is used to find the closest parallel line.&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;        [CommandMethod("FINDPARALLEL")]
        public static void FindClosestParallelLineCmd()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            var options = new PromptEntityOptions("\nSelect Line: ");
            options.SetRejectMessage("Must be a Line.");
            options.AddAllowedClass(typeof(Line), true);
            var result = ed.GetEntity(options);
            if (result.Status != PromptStatus.OK) 
                return;
            using (var tr = db.TransactionManager.StartTransaction())
            {
                var source = (Line)tr.GetObject(result.ObjectId, OpenMode.ForRead);
                if (TryFindParallelLine(source, tr, out LineSegment3d line, out double distance))
                {
                    ed.WriteMessage(
                        "\nStart point: {0:0.00} End point: {1:0.00}\nDistance = {2:0.00}", 
                        line.StartPoint, 
                        line.EndPoint, 
                        distance);
                }
                else
                {
                    ed.WriteMessage("\nNone parallel line");
                }
                tr.Commit();
            }
        }

        static bool TryFindParallelLine(Line source, Transaction tr, out LineSegment3d line, out double distance)
        {
            string layer = source.Layer;
            var segment = new LineSegment3d(source.StartPoint, source.EndPoint);
            var direction = segment.Direction;
            var segments =
                ((BlockTableRecord)tr.GetObject(source.OwnerId, OpenMode.ForRead))
                .Cast&amp;lt;ObjectId&amp;gt;()
                .Where(id =&amp;gt; id != source.ObjectId &amp;amp;&amp;amp; id.ObjectClass.DxfName == "LINE")
                .Select(id =&amp;gt; (Line)tr.GetObject(id, OpenMode.ForRead))
                .Where(l =&amp;gt; l.Layer == layer)
                .Select(l =&amp;gt; new LineSegment3d(l.StartPoint, l.EndPoint))
                .Where(s =&amp;gt; s.Direction.IsParallelTo(direction));
            if (segments.Any())
            {
                line = segments.Aggregate((s1, s2) =&amp;gt;
                    (s1.GetDistanceTo(segment) &amp;lt; s2.GetDistanceTo(segment)) ? s1 : s2);
                distance = line.GetDistanceTo(segment);
                return true;
            }
            else
            {
                line = null;
                distance = -1.0;
                return false;
            }
        }&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 03 Jan 2022 12:35:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-find-the-coordinates-of-a-line-parallel-to-another-on-the/m-p/10854918#M14253</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2022-01-03T12:35:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the coordinates of a line parallel to another on the same layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-find-the-coordinates-of-a-line-parallel-to-another-on-the/m-p/10855317#M14254</link>
      <description>&lt;P&gt;Hi, thank you so much for your help.&lt;/P&gt;&lt;P&gt;Bye.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jan 2022 15:38:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-find-the-coordinates-of-a-line-parallel-to-another-on-the/m-p/10855317#M14254</guid>
      <dc:creator>mecoman6GF27</dc:creator>
      <dc:date>2022-01-03T15:38:50Z</dc:date>
    </item>
  </channel>
</rss>

