<?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: Abort Pickobject() in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/abort-pickobject/m-p/6224958#M66799</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought of it but unfortunatly it does not return objects in the same order the user selected which is important in my case.&lt;/P&gt;</description>
    <pubDate>Sun, 20 Mar 2016 14:30:58 GMT</pubDate>
    <dc:creator>basionyecg</dc:creator>
    <dc:date>2016-03-20T14:30:58Z</dc:date>
    <item>
      <title>Abort Pickobject()</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/abort-pickobject/m-p/6224515#M66795</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to abort pickobject() other than the user press ESC.&lt;/P&gt;&lt;P&gt;I am using Pickobject() in a loop in an External Form :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;while (!user_pressed_stop)
    {
             
        Selection sel = revit.Application.ActiveUIDocument.Selection;
        ElementPickFilter myfilter = new ElementPickFilter();
        Reference pickedRef = null;
        pickedRef = sel.PickObject(ObjectType.Element, myfilter, "Please select an Element");

        Element elem =document.GetElement(pickedRef);
        listelement.Add(elem);
                    
     }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to stop the "pick object" from waiting the user input when he clicks the stop button,&lt;/P&gt;&lt;P&gt;I even tried to make work around by sending ESC Key to Revit but it doesnot work properly Every time&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;private void buttonstop_Click(object sender, EventArgs e)
        {
            static WindowHandle _hWndRevit = null;
            IntPtr ptr;
            
            Process[] processes = Process.GetProcessesByName("Revit");
                if (0 &amp;lt; processes.Length)
                {
                    ptr = processes[0].MainWindowHandle;
                    _hWndRevit = new WindowHandle(ptr);
                }

            SetForegroundWindow(ptr);
            SendKeys.SendWait("{ESC}");
            
        }&lt;/PRE&gt;&lt;P&gt;Any Proper way to cancel that Function?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Basiony&lt;/P&gt;</description>
      <pubDate>Sat, 19 Mar 2016 20:15:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/abort-pickobject/m-p/6224515#M66795</guid>
      <dc:creator>basionyecg</dc:creator>
      <dc:date>2016-03-19T20:15:23Z</dc:date>
    </item>
    <item>
      <title>Re: Abort Pickobject()</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/abort-pickobject/m-p/6224617#M66796</link>
      <description>&lt;P&gt;Basiony,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;please forgive me for being so straightforward, but it is my opinion that you approach is not exactly right and is is potentially misleading (the user, that is). Let me explain: If an action of picking invoked, it&amp;nbsp;prompts the user to select&amp;nbsp;elements and the only&amp;nbsp;actions allowed in the use should&amp;nbsp;be:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;selecting an element&lt;/LI&gt;
&lt;LI&gt;pressing the Esc key (to cancel)&lt;/LI&gt;
&lt;LI&gt;pressing a&amp;nbsp;Finish button, if available, in Revit (to finish picking)&lt;/LI&gt;
&lt;LI&gt;pressing a Cancel&amp;nbsp;button, if available, in Revit (to cancel picking)&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Most of or all other UI elements should&amp;nbsp;be disable to indicate clear to the user that the above actions are the only ones allowed&amp;nbsp;during the picking context.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For that reason I suggest you do following: When you invoke a picking&amp;nbsp;action do disable all controls in your dialog and enable them again only after the picking is finished (through means provided&amp;nbsp;by Revit). This what your users will not have to learn that your application behaves&amp;nbsp;differently than other external applications and differently than Revit too.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By the way, I am sure you know&amp;nbsp;that but I mention it anyway: be aware that if the user cancels a&amp;nbsp;picking process, Revit throws an exception back to the API application that invoked the picking.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 19 Mar 2016 23:04:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/abort-pickobject/m-p/6224617#M66796</guid>
      <dc:creator>arnostlobel</dc:creator>
      <dc:date>2016-03-19T23:04:52Z</dc:date>
    </item>
    <item>
      <title>Re: Abort Pickobject()</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/abort-pickobject/m-p/6224763#M66797</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks Arnošt for repling.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The only reason I need to perform actions in that sequence is that I donot know how many objects the user want to select so, I used a loop to collect all elements the user had selected and to end the loop the user presses Stop button that is when I need to abort the last pickobject.&lt;/P&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;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Basiony&lt;/P&gt;</description>
      <pubDate>Sun, 20 Mar 2016 06:31:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/abort-pickobject/m-p/6224763#M66797</guid>
      <dc:creator>basionyecg</dc:creator>
      <dc:date>2016-03-20T06:31:57Z</dc:date>
    </item>
    <item>
      <title>Re: Abort Pickobject()</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/abort-pickobject/m-p/6224883#M66798</link>
      <description>&lt;P&gt;Can you use PickObjects instead of PickObject? &amp;nbsp; That lets the user select multiple objects and it provides a "finish" button at the top of the screen the user can press when they are finished selecting objects.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Mar 2016 12:21:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/abort-pickobject/m-p/6224883#M66798</guid>
      <dc:creator>stever66</dc:creator>
      <dc:date>2016-03-20T12:21:18Z</dc:date>
    </item>
    <item>
      <title>Re: Abort Pickobject()</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/abort-pickobject/m-p/6224958#M66799</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought of it but unfortunatly it does not return objects in the same order the user selected which is important in my case.&lt;/P&gt;</description>
      <pubDate>Sun, 20 Mar 2016 14:30:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/abort-pickobject/m-p/6224958#M66799</guid>
      <dc:creator>basionyecg</dc:creator>
      <dc:date>2016-03-20T14:30:58Z</dc:date>
    </item>
    <item>
      <title>Re: Abort Pickobject()</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/abort-pickobject/m-p/6225541#M66800</link>
      <description>Place the pickobject inside a try block and set the catch block to only catch the operationcancelled exception.&lt;BR /&gt;Place all of that inside a while loop and place a break; statement in the exception handler. When the user hits escape Your loop will exit and you can begin working withe the selected elements</description>
      <pubDate>Mon, 21 Mar 2016 04:57:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/abort-pickobject/m-p/6225541#M66800</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-03-21T04:57:55Z</dc:date>
    </item>
    <item>
      <title>Re: Abort Pickobject()</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/abort-pickobject/m-p/6225984#M66801</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks Scott for your reply,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I already have a similar way to handle when user presses ESC , For usability reasons I still need to give the user the control to stop the loop through the same interface he used to start it to keep things logical.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Basiony&lt;/P&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, 21 Mar 2016 11:58:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/abort-pickobject/m-p/6225984#M66801</guid>
      <dc:creator>basionyecg</dc:creator>
      <dc:date>2016-03-21T11:58:23Z</dc:date>
    </item>
    <item>
      <title>Re: Abort Pickobject()</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/abort-pickobject/m-p/6226326#M66802</link>
      <description>&lt;P&gt;&lt;SPAN&gt;maybe you could just do the same as I suggest and throw your own custom exception when the button is pressed to abort the pickobject command and break the loop. I do a similar thing with my progress bar to abort long processes.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2016 14:27:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/abort-pickobject/m-p/6226326#M66802</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-03-21T14:27:39Z</dc:date>
    </item>
    <item>
      <title>回复： Abort Pickobject()</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/abort-pickobject/m-p/8113284#M66803</link>
      <description>&lt;P&gt;Hello:&lt;/P&gt;&lt;P&gt;It has been more than 2 years since your posting this article, I'm not sure if your are gonna read this.&lt;/P&gt;&lt;P&gt;Still hope I can help.&lt;/P&gt;&lt;P&gt;Here are my thoughts about this question:&lt;/P&gt;&lt;P&gt;First thing is to set focus on the revit main window.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Add reference to your Visual Studio project: AdWindows.dll. It is in the same directory as the Revit.exe is in.&lt;/LI&gt;&lt;LI&gt;Using Autodesk.Windows namespace&lt;/LI&gt;&lt;LI&gt;Make the following call as illustrated:&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="图像 1.png" style="width: 999px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/520080iE7A5410ABE9BF5D8/image-size/large?v=v2&amp;amp;px=999" role="button" title="图像 1.png" alt="图像 1.png" /&gt;&lt;/span&gt;&lt;/LI&gt;&lt;LI&gt;We'll be using this IntPtr later. For now, let's turn to get some help from Windows API. Declare some methods as illustrated:&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="图像 2.png" style="width: 761px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/520081i231F2D453BF3C8F6/image-size/large?v=v2&amp;amp;px=999" role="button" title="图像 2.png" alt="图像 2.png" /&gt;&lt;/span&gt;&lt;/LI&gt;&lt;LI&gt;The first method is used to set focus on a window; the second one is used to send virtual KEY BOARD signal to windows. (I think, by now, you have already realized what to do next. Yes, focus Revit window, and send ESC down, then ESC up):&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="图像 3.png" style="width: 613px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/520082i7F2E9B5685C1E577/image-size/large?v=v2&amp;amp;px=999" role="button" title="图像 3.png" alt="图像 3.png" /&gt;&lt;/span&gt;&lt;/LI&gt;&lt;LI&gt;Ignore the blue words in the above picture. I declared those methods in another class &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; . So far, now we are able to focus on Revit window, and send ESC PRESSED (with an ESC down followed by an ESC up)&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm afraid that this still cannot help you to reach your aim, but, at least it helps us to abort PickObject()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jul 2018 07:43:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/abort-pickobject/m-p/8113284#M66803</guid>
      <dc:creator>jlpgy</dc:creator>
      <dc:date>2018-07-06T07:43:09Z</dc:date>
    </item>
    <item>
      <title>回复： Abort Pickobject()</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/abort-pickobject/m-p/9174963#M66804</link>
      <description>&lt;P&gt;Many thanks for your solution! It works perfectly!&lt;/P&gt;</description>
      <pubDate>Sat, 30 Nov 2019 17:37:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/abort-pickobject/m-p/9174963#M66804</guid>
      <dc:creator>mgp</dc:creator>
      <dc:date>2019-11-30T17:37:51Z</dc:date>
    </item>
  </channel>
</rss>

