<?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 do I create a loop with PromptEntityResult in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-loop-with-promptentityresult/m-p/11678836#M22020</link>
    <description>&lt;P&gt;Thanks for your help,&lt;/P&gt;&lt;P&gt;I try to use&amp;nbsp;Editor.Command:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;//...
 using (Transaction trans = Database.TransactionManager.StartTransaction())
            {
               try
               {
                  var polylines = _selectedCurves.JoinAllCurves().Select(x =&amp;gt; x.GetEntityToWrite(trans)).Cast&amp;lt;Polyline&amp;gt;().ToList();
                  polylines.ForEach(x =&amp;gt;
                  {
                     Editor.Command("_.FILLET", "_Polyline", "_Radius", radius, x.Id, "");
                  });
                  trans.Commit();
                  count++;
               }
               catch
               {
               }
            }
//...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do not use&amp;nbsp; CommandFlag.Session, but the issue&amp;nbsp; "eInvalidInput" apear.&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="nghia_pt_2-1673670669203.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1162632iACC7A49B1CF6C97E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="nghia_pt_2-1673670669203.png" alt="nghia_pt_2-1673670669203.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 14 Jan 2023 04:31:23 GMT</pubDate>
    <dc:creator>nghia_pt</dc:creator>
    <dc:date>2023-01-14T04:31:23Z</dc:date>
    <item>
      <title>How do I create a loop with PromptEntityResult</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-loop-with-promptentityresult/m-p/8862390#M22015</link>
      <description>&lt;P&gt;How do I get this to loop until I either hit ESC or actually select a block?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// Setting entity prompt, reject message and allowed class type.&lt;BR /&gt;PromptEntityOptions opts1 = new PromptEntityOptions("");&lt;BR /&gt;opts1.Message = "\nSelect a TGDraw conveyor bed to get the elevation dimension: ";&lt;BR /&gt;opts1.SetRejectMessage("\nMust be a valid TGDraw block, try again: ");&lt;BR /&gt;opts1.AddAllowedClass(typeof(BlockReference), true);&lt;BR /&gt;PromptEntityResult ent1 = ed.GetEntity(opts1);&lt;BR /&gt;if (ent1.Status == PromptStatus.Cancel) return;&lt;/P&gt;&lt;P&gt;// reads the selected block and extracts properties and attributes&lt;BR /&gt;BlkStrct elevation = new BlkStrct();&lt;BR /&gt;elevation = ReadBlock(ent1.ObjectId);&lt;BR /&gt;string bname = elevation.blkName.Substring(0, 3);&lt;BR /&gt;if (!BlockFilter("bed filter", bname))&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp; &amp;nbsp;return;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know it has to be simple, but I am not seeing the solution.&lt;/P&gt;&lt;P&gt;Thanks for your help.&lt;/P&gt;&lt;P&gt;Sonny&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2019 11:06:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-loop-with-promptentityresult/m-p/8862390#M22015</guid>
      <dc:creator>sonny3g</dc:creator>
      <dc:date>2019-06-20T11:06:40Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a loop with PromptEntityResult</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-loop-with-promptentityresult/m-p/8862708#M22016</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;            var ed = AcAp.DocumentManager.MdiActiveDocument.Editor;

            var peo = new PromptEntityOptions("\nSelect block: ");
            peo.SetRejectMessage("\nMust be a block.");
            peo.AddAllowedClass(typeof(BlockReference), true);&lt;BR /&gt;
            while (true)
            {
                var per = ed.GetEntity(peo);

                if (per.Status == PromptStatus.Cancel)
                    return; // exit the function

                if (per.Status != PromptStatus.OK)
                    break; // quit the loop

                // do your stuff with the selected bloc
            }&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Jun 2019 12:47:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-loop-with-promptentityresult/m-p/8862708#M22016</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2019-06-20T12:47:46Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a loop with PromptEntityResult</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-loop-with-promptentityresult/m-p/8862777#M22017</link>
      <description>&lt;P&gt;Thanks Giles.&amp;nbsp; I was trying to use do and was getting nowhere fast.&amp;nbsp; Using the while loop instead, with some slight modifications, did the trick for me.&lt;/P&gt;&lt;P&gt;Modified code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;            try
            {
                // Setting entity prompt, reject message and allowed class type.
                PromptEntityOptions opts1 = new PromptEntityOptions("");
                PromptEntityResult ent1;
                BlkStrct elevation = new BlkStrct();
                opts1.Message = "\nSelect a TGDraw conveyor bed to get the elevation dimension: ";
                opts1.SetRejectMessage("\nMust be a valid TGDraw block, try again: ");
                opts1.AddAllowedClass(typeof(BlockReference), true);
                while (true)
                {
                    ent1 = ed.GetEntity(opts1);
                    if (ent1.Status == PromptStatus.Cancel) return; // exit the function
                    // reads the selected block and extracts properties and attributes
                    elevation = ReadBlock(ent1.ObjectId);
                    string bname = elevation.blkName.Substring(0, 3);
                    if (!BlockFilter("bed filter", bname))
                    {
                        System.Windows.Forms.MessageBox.Show("\nMust be a valid TGDraw block, try again: ");
                    }
                    else
                    {
                        break;
                    }
                }&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Jun 2019 13:17:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-loop-with-promptentityresult/m-p/8862777#M22017</guid>
      <dc:creator>sonny3g</dc:creator>
      <dc:date>2019-06-20T13:17:25Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a loop with PromptEntityResult</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-loop-with-promptentityresult/m-p/11678350#M22018</link>
      <description>&lt;P&gt;Hi _gile,&lt;/P&gt;&lt;P&gt;I cannot use methode SendStringToExcute in a loop. &lt;SPAN&gt;Thanks for your help.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;This is my code :&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;for (int i =0;i&amp;lt;2;i++)
         {
            var entityOptions = new PromptSelectionOptions();
            entityOptions.MessageForAdding = "\nSelect polylines";
            var promptSelectionResult = Editor.GetSelection(entityOptions);
            if (promptSelectionResult.Status != PromptStatus.OK)
            {
               return;
            }

            _selectedCurves = promptSelectionResult.GetObject&amp;lt;Curve&amp;gt;();

            using (Transaction trans = Database.TransactionManager.StartTransaction())
            {
               try
               {
                  var polylines = _selectedCurves.JoinAllCurves().Select(x =&amp;gt; x.GetEntityToWrite(trans)).Cast&amp;lt;Polyline&amp;gt;().ToList();
                  polylines.ForEach(x =&amp;gt; 
                  {
                     Doc.SendStringToExecute($"_.fillet _p _r {radius} {x.GetHandelName()} ", false, false, false);
                  });
                  trans.Commit();
                  count++;
               }
               catch
               {
               }
            }
         }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And this is the issue:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="nghia_pt_0-1673645306985.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1162557i42F629D56C78123A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="nghia_pt_0-1673645306985.png" alt="nghia_pt_0-1673645306985.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2023 21:30:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-loop-with-promptentityresult/m-p/11678350#M22018</guid>
      <dc:creator>nghia_pt</dc:creator>
      <dc:date>2023-01-13T21:30:29Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a loop with PromptEntityResult</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-loop-with-promptentityresult/m-p/11678367#M22019</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;SenStringToExecute runs asynchronously.&lt;/P&gt;
&lt;P&gt;Try using Editor.Command instead.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2023 21:42:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-loop-with-promptentityresult/m-p/11678367#M22019</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2023-01-13T21:42:50Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a loop with PromptEntityResult</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-loop-with-promptentityresult/m-p/11678836#M22020</link>
      <description>&lt;P&gt;Thanks for your help,&lt;/P&gt;&lt;P&gt;I try to use&amp;nbsp;Editor.Command:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;//...
 using (Transaction trans = Database.TransactionManager.StartTransaction())
            {
               try
               {
                  var polylines = _selectedCurves.JoinAllCurves().Select(x =&amp;gt; x.GetEntityToWrite(trans)).Cast&amp;lt;Polyline&amp;gt;().ToList();
                  polylines.ForEach(x =&amp;gt;
                  {
                     Editor.Command("_.FILLET", "_Polyline", "_Radius", radius, x.Id, "");
                  });
                  trans.Commit();
                  count++;
               }
               catch
               {
               }
            }
//...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do not use&amp;nbsp; CommandFlag.Session, but the issue&amp;nbsp; "eInvalidInput" apear.&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="nghia_pt_2-1673670669203.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1162632iACC7A49B1CF6C97E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="nghia_pt_2-1673670669203.png" alt="nghia_pt_2-1673670669203.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Jan 2023 04:31:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-loop-with-promptentityresult/m-p/11678836#M22020</guid>
      <dc:creator>nghia_pt</dc:creator>
      <dc:date>2023-01-14T04:31:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a loop with PromptEntityResult</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-loop-with-promptentityresult/m-p/11678933#M22021</link>
      <description>&lt;P&gt;This is probably due to the context in which the method is called. Editor.Command can only be used in document context. &lt;BR /&gt;Are you calling this method in application context (i.e. modeless UI or CommandFlags.Session)?&lt;BR /&gt;In the case of a modeless UI, you can wrap your method in a command (CommandMethod) that you call from your UI with SendStringToExecute, which will have the effect of automatically switching to the document context and locking the document.&lt;BR /&gt;From &lt;A href="https://www.keanw.com/2011/02/managing-drag-drop-from-a-palette-into-autocad-using-net.html" target="_blank" rel="noopener"&gt;Kean Walmsley's blog&lt;/A&gt;:&lt;/P&gt;
&lt;P&gt;"&lt;EM&gt;Once again there’s our important &lt;A href="https://en.wikipedia.org/wiki/Rule_of_thumb" target="_blank" rel="noopener"&gt;rule of thumb&lt;/A&gt; when it comes to implementing a modeless UI: rather than manually locking the current document, it’s safer to define a command – which will implicitly lock the current document – and call that from the UI via SendStringToExecute()&lt;/EM&gt;."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, you should provide more informations about how you call this method.&lt;/P&gt;</description>
      <pubDate>Sat, 14 Jan 2023 06:32:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-loop-with-promptentityresult/m-p/11678933#M22021</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2023-01-14T06:32:38Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a loop with PromptEntityResult</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-loop-with-promptentityresult/m-p/11678936#M22022</link>
      <description>&lt;P&gt;Another way would be to avoid calling an AutoCAD command by using the extension methods below (taken from the &lt;A href="https://github.com/gileCAD/GeometryExtensions" target="_blank" rel="noopener"&gt;GeometryExtensions library&lt;/A&gt;).&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;        /// &amp;lt;summary&amp;gt;
        /// Adds an arc (fillet), when possible, at each vertex.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="pline"&amp;gt;The instance to which this method applies.&amp;lt;/param&amp;gt;
        /// &amp;lt;param name="radius"&amp;gt;The arc radius.&amp;lt;/param&amp;gt;
        public static void FilletAll(this Polyline pline, double radius)
        {
            int n = pline.Closed ? 0 : 1;
            for (int i = n; i &amp;lt; pline.NumberOfVertices - n; i += 1 + pline.FilletAt(i, radius))
            { }
        }

        /// &amp;lt;summary&amp;gt;
        /// Adds an arc (fillet), when possible, at specified vertex.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="pline"&amp;gt;The instance to which this method applies.&amp;lt;/param&amp;gt;
        /// &amp;lt;param name="index"&amp;gt;The vertex index.&amp;lt;/param&amp;gt;
        /// &amp;lt;param name="radius"&amp;gt;The arc radius.&amp;lt;/param&amp;gt;
        /// &amp;lt;returns&amp;gt;1, if the operation succeded; 0, if it failed&amp;lt;/returns&amp;gt;
        public static int FilletAt(this Polyline pline, int index, double radius)
        {
            int prev = index == 0 &amp;amp;&amp;amp; pline.Closed ? pline.NumberOfVertices - 1 : index - 1;
            if (pline.GetSegmentType(prev) != SegmentType.Line ||
                pline.GetSegmentType(index) != SegmentType.Line)
            {
                return 0;
            }
            LineSegment2d seg1 = pline.GetLineSegment2dAt(prev);
            LineSegment2d seg2 = pline.GetLineSegment2dAt(index);
            Vector2d vec1 = seg1.StartPoint - seg1.EndPoint;
            Vector2d vec2 = seg2.EndPoint - seg2.StartPoint;
            double angle = (Math.PI - vec1.GetAngleTo(vec2)) / 2.0;
            double dist = radius * Math.Tan(angle);
            if (dist == 0.0 || dist &amp;gt; seg1.Length || dist &amp;gt; seg2.Length)
            {
                return 0;
            }
            Point2d pt1 = seg1.EndPoint + vec1.GetNormal() * dist;
            Point2d pt2 = seg2.StartPoint + vec2.GetNormal() * dist;
            double bulge = Math.Tan(angle / 2.0);
            if (Clockwise(seg1.StartPoint, seg1.EndPoint, seg2.EndPoint))
            {
                bulge = -bulge;
            }
            pline.AddVertexAt(index, pt1, bulge, 0.0, 0.0);
            pline.SetPointAt(index + 1, pt2);
            return 1;
        }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Jan 2023 06:42:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-loop-with-promptentityresult/m-p/11678936#M22022</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2023-01-14T06:42:56Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a loop with PromptEntityResult</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-loop-with-promptentityresult/m-p/11679004#M22023</link>
      <description>&lt;P&gt;Hi _gile,&lt;/P&gt;&lt;P&gt;This is my code:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;   public class MultiFilletCmd : ICadCommand
   {
      [CommandMethod("MultiFillet")]
      public override void Execute()
      {
         var doc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
         var entityOptions = new PromptSelectionOptions();
         entityOptions.MessageForAdding = "\nSelect polylines";

         double radius = doc.GetNumberFromUser("Enter the radius");
         while (true)
         {
            var promptSelectionResult = doc.Editor.GetSelection(entityOptions);

            if (promptSelectionResult.Status == PromptStatus.Cancel)
            {
               return;
            }

            if (promptSelectionResult.Status != PromptStatus.OK)
            {
               break;
            }

            var selectedCurves = promptSelectionResult.GetObject&amp;lt;Curve&amp;gt;();

            using (Transaction trans = doc.Database.TransactionManager.StartTransaction())
            {
               try
               {
                  var polylines = selectedCurves.JoinAllCurves().Select(x =&amp;gt; x.GetEntityToWrite(trans)).Cast&amp;lt;Polyline&amp;gt;().ToList();
                  polylines.ForEach(x =&amp;gt;
                  {
                     doc.Editor.Command("_.FILLET", "_Polyline", "_Radius", radius, x.Id, "");
                  });
                  trans.Commit();
               }
               catch
               {
               }
            }
         }
      }
   }&lt;/LI-CODE&gt;&lt;P&gt;I known your methode "FilletAll". It is very usefull. But I can use for the polyline which has some arc segments. So I try to use Editor.Command to call Fillet command. But, I met&amp;nbsp;&lt;SPAN&gt;"eInvalidInput" issue. I don't know why.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Jan 2023 08:20:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-loop-with-promptentityresult/m-p/11679004#M22023</guid>
      <dc:creator>nghia_pt</dc:creator>
      <dc:date>2023-01-14T08:20:08Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a loop with PromptEntityResult</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-loop-with-promptentityresult/m-p/11679014#M22024</link>
      <description>When I run this code by click to button, this issue apear.</description>
      <pubDate>Sat, 14 Jan 2023 08:32:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-loop-with-promptentityresult/m-p/11679014#M22024</guid>
      <dc:creator>nghia_pt</dc:creator>
      <dc:date>2023-01-14T08:32:15Z</dc:date>
    </item>
  </channel>
</rss>

