<?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: Prevent user terminating add-in command prematurely with escape key, right m in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/prevent-user-terminating-add-in-command-prematurely-with-escape/m-p/5772501#M71078</link>
    <description>&lt;P&gt;I definitely&amp;nbsp;do not recommend using Automatic transaction mode in any situation. It is kept for backward compatibility&amp;nbsp;only. It has virtually no advantage beside the "convenience" and even that is questionable, for automatic transaction cannot be named. On the other hand, automatic transaction has many disadvantages. We have been strongly recommending&amp;nbsp;the Manual Transaction mode since about Revit 2012 or so. It is also a safer approach, because&amp;nbsp;Automatic transaction mode will be eventually removed; hopefully.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ideally, you put your transaction&amp;nbsp;only there where you actually make&amp;nbsp;modifications to the model. An ideal transaction is as short-lived as possible, and is always scoped - that is, it lives inside a &lt;STRONG&gt;using&lt;/STRONG&gt; block. That way you never leave a transaction open, because&amp;nbsp;any started transaction gets closed (rolled back) automatically when leaving the scope in a case of exception.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 15 Aug 2015 02:30:01 GMT</pubDate>
    <dc:creator>arnostlobel</dc:creator>
    <dc:date>2015-08-15T02:30:01Z</dc:date>
    <item>
      <title>Prevent user terminating add-in command prematurely with escape key, right mouse</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/prevent-user-terminating-add-in-command-prematurely-with-escape/m-p/5767471#M71070</link>
      <description>&lt;P&gt;The add-in finishes the operation without a fatal error if the user simply finishes the command by selecting another element than a wall, however If they press esc and revit can't resolve walls contorted back onto themselves by deleting or unjoing geometry the revit application crashes. This shouldn't occur in normal operation however if a user were to be silly and use the tool inappropriately it is a real danger. Is there any way of preventing the user from pressing the escape key?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I currently handle the user ending the command with esc or right mouse with the below code...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;}//end execute method&lt;/P&gt;&lt;P&gt;//If the user right-clicks or presses Esc, handle the exception&lt;BR /&gt;catch (Autodesk.Revit.Exceptions.OperationCanceledException)&lt;BR /&gt;{&lt;BR /&gt;return Result.Cancelled;&lt;BR /&gt;}&lt;BR /&gt;//Catch other errors&lt;BR /&gt;catch (Exception ex)&lt;BR /&gt;{&lt;BR /&gt;message = ex.Message;&lt;BR /&gt;return Result.Failed;&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Wed, 12 Aug 2015 11:13:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/prevent-user-terminating-add-in-command-prematurely-with-escape/m-p/5767471#M71070</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-08-12T11:13:40Z</dc:date>
    </item>
    <item>
      <title>Re: Prevent user terminating add-in command prematurely with escape key, right m</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/prevent-user-terminating-add-in-command-prematurely-with-escape/m-p/5767662#M71071</link>
      <description>&lt;P&gt;The answer is No, there ins't a way to prevent the end user from hitting the Esc key. However, that is exactly how&amp;nbsp;selecting was designed to behave&amp;nbsp;and what you do in your application (catching the OperationCancelled exception) is exactly what you are expected to do,&lt;/P&gt;</description>
      <pubDate>Wed, 12 Aug 2015 12:52:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/prevent-user-terminating-add-in-command-prematurely-with-escape/m-p/5767662#M71071</guid>
      <dc:creator>arnostlobel</dc:creator>
      <dc:date>2015-08-12T12:52:34Z</dc:date>
    </item>
    <item>
      <title>Re: Prevent user terminating add-in command prematurely with escape key, right m</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/prevent-user-terminating-add-in-command-prematurely-with-escape/m-p/5769391#M71072</link>
      <description>Thank you Arnost,&lt;BR /&gt;The problem is when the user cancels the operation the cancel and delete the inverted(walls turned back onto themselves ) dialogs don't appear so that the user can agree that they shouldn't have used the command to pull walls back onto themselves. How can i use the catcjing of the exception assist in preventing the file crashing with a fatal error? Thanx again.&lt;BR /&gt;Frank</description>
      <pubDate>Thu, 13 Aug 2015 11:15:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/prevent-user-terminating-add-in-command-prematurely-with-escape/m-p/5769391#M71072</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-08-13T11:15:39Z</dc:date>
    </item>
    <item>
      <title>Re: Prevent user terminating add-in command prematurely with escape key, right m</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/prevent-user-terminating-add-in-command-prematurely-with-escape/m-p/5769420#M71073</link>
      <description>&lt;P&gt;I just checked then a number of errors can be incurred such as 3xconstraints can't be maintained, 4xelements need to be unjoined and 2xelements are reversed. The errors can accumulate and if the user doesn't handle them and instead chooses to use the "Interrupt" key a fatal error occurs.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2015 11:32:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/prevent-user-terminating-add-in-command-prematurely-with-escape/m-p/5769420#M71073</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-08-13T11:32:41Z</dc:date>
    </item>
    <item>
      <title>Re: Prevent user terminating add-in command prematurely with escape key, right m</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/prevent-user-terminating-add-in-command-prematurely-with-escape/m-p/5769527#M71074</link>
      <description>&lt;P&gt;spammasterblaster:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks like you are not giving us enough information&amp;nbsp;to work with. In your originally posted snippet&amp;nbsp;there&amp;nbsp;was nothing about walls or deleting them. There was not&amp;nbsp;even a transaction used to modify the model. The question was about cancelling&amp;nbsp;a selection and that, I believe was answered&amp;nbsp;- you catch the specific OperationCanceled exception and continue on with your commmand's execution. Now, regarding of model&amp;nbsp;changes, wall deleting, etc., we need to see your actual code and what you do there to be of any help. The problems you were describing do not look like having anything to do with&amp;nbsp;selecting elements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2015 12:49:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/prevent-user-terminating-add-in-command-prematurely-with-escape/m-p/5769527#M71074</guid>
      <dc:creator>arnostlobel</dc:creator>
      <dc:date>2015-08-13T12:49:42Z</dc:date>
    </item>
    <item>
      <title>Re: Prevent user terminating add-in command prematurely with escape key, right m</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/prevent-user-terminating-add-in-command-prematurely-with-escape/m-p/5771174#M71075</link>
      <description>&lt;P&gt;Hi Arnod,&lt;/P&gt;&lt;P&gt;Thanx for investing the time to assist someone who is starting to code in a new area, that being aad-in geometry. I have written some complex add-ins to do with view creation, parameters and models, however I have never come across "fatal errors," when a user presses the interupt key. To summarize I am selecting walls, moving them, locking a constraint, joining geometry and modifying the wall orientation and properties. I make the calls to the methods from within the execute method however much of the code calling the api classes is outside this catch block. To aasist your understanding I copied the entire class and added it to a zip, see attached below.&amp;nbsp;&lt;/P&gt;&lt;P&gt;cheers,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;fabs&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Aug 2015 08:50:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/prevent-user-terminating-add-in-command-prematurely-with-escape/m-p/5771174#M71075</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-08-14T08:50:19Z</dc:date>
    </item>
    <item>
      <title>Re: Prevent user terminating add-in command prematurely with escape key, right m</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/prevent-user-terminating-add-in-command-prematurely-with-escape/m-p/5772091#M71076</link>
      <description>Dear fabs:&lt;BR /&gt;&lt;BR /&gt;I am sorry but I do not have time to examine your application. If you think you may need a help with code-proofing your application I suggest you become a member of the AND. There are really great with helping external programmers.&lt;BR /&gt;&lt;BR /&gt;I can only provide a quick comment and notes. Since you mentioned that in your application you let the exceptions escape from some of the method on deeper levels, I assume you need to refactor your application to avoid cases like that. Even with an exception escaping from your external command, Revit should not crash though. Because that is what you report, however, I can only guess you may not be scoping your transaction properly. Please make sure that all your transaction are always properly scoped in using block (assuming you use C#). It is very important. Otherwise a transaction could be left unfinished when an exception accurse and cause some problem when the garbage collector tries to collect it, eventually.</description>
      <pubDate>Fri, 14 Aug 2015 18:46:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/prevent-user-terminating-add-in-command-prematurely-with-escape/m-p/5772091#M71076</guid>
      <dc:creator>arnostlobel</dc:creator>
      <dc:date>2015-08-14T18:46:06Z</dc:date>
    </item>
    <item>
      <title>Re: Prevent user terminating add-in command prematurely with escape key, right m</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/prevent-user-terminating-add-in-command-prematurely-with-escape/m-p/5772480#M71077</link>
      <description>Thanx Arnost,&lt;BR /&gt;I have the transaction attribute set to automatic. I started doing this as it is more convenient and the code complexity is reduced. Do you think I need manual Transaction in my C# to scope the api class calls? I will try AND out thanx for your time I appreciate it.</description>
      <pubDate>Sat, 15 Aug 2015 01:21:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/prevent-user-terminating-add-in-command-prematurely-with-escape/m-p/5772480#M71077</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-08-15T01:21:11Z</dc:date>
    </item>
    <item>
      <title>Re: Prevent user terminating add-in command prematurely with escape key, right m</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/prevent-user-terminating-add-in-command-prematurely-with-escape/m-p/5772501#M71078</link>
      <description>&lt;P&gt;I definitely&amp;nbsp;do not recommend using Automatic transaction mode in any situation. It is kept for backward compatibility&amp;nbsp;only. It has virtually no advantage beside the "convenience" and even that is questionable, for automatic transaction cannot be named. On the other hand, automatic transaction has many disadvantages. We have been strongly recommending&amp;nbsp;the Manual Transaction mode since about Revit 2012 or so. It is also a safer approach, because&amp;nbsp;Automatic transaction mode will be eventually removed; hopefully.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ideally, you put your transaction&amp;nbsp;only there where you actually make&amp;nbsp;modifications to the model. An ideal transaction is as short-lived as possible, and is always scoped - that is, it lives inside a &lt;STRONG&gt;using&lt;/STRONG&gt; block. That way you never leave a transaction open, because&amp;nbsp;any started transaction gets closed (rolled back) automatically when leaving the scope in a case of exception.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 15 Aug 2015 02:30:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/prevent-user-terminating-add-in-command-prematurely-with-escape/m-p/5772501#M71078</guid>
      <dc:creator>arnostlobel</dc:creator>
      <dc:date>2015-08-15T02:30:01Z</dc:date>
    </item>
    <item>
      <title>Re: Prevent user terminating add-in command prematurely with escape key, right m</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/prevent-user-terminating-add-in-command-prematurely-with-escape/m-p/5772918#M71079</link>
      <description>Arnost, I thought you might like some feedback on what was causing the issue.&lt;BR /&gt;After doing a little refactoring which amounted to no benefit except my code was less clear and less modular, I changed the transaction attribute to manual and placed all the changes to the database within blocks as per below. now the element is reversed and unjoining , deleting of the wall geometry occurs immediately after the button click occurs. and revit handles this first, then if the user presses the interupt key it's after the issues have been resolved and no crash occurs. Many thanx i am quite happy about the support i received from you despite my alias. &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;BR /&gt;using (Transaction trans = new Transaction(doc, "Flip Wall"))&lt;BR /&gt;{&lt;BR /&gt;trans.Start();&lt;BR /&gt;getWall(doc, E1Id).Flip();&lt;BR /&gt;trans.Commit();&lt;BR /&gt;}</description>
      <pubDate>Sun, 16 Aug 2015 00:31:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/prevent-user-terminating-add-in-command-prematurely-with-escape/m-p/5772918#M71079</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-08-16T00:31:48Z</dc:date>
    </item>
    <item>
      <title>Re: Prevent user terminating add-in command prematurely with escape key, right m</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/prevent-user-terminating-add-in-command-prematurely-with-escape/m-p/5773121#M71080</link>
      <description>&lt;P&gt;Excellent! Welcome to a new phase of your Revit API programming.&lt;/P&gt;
&lt;P&gt;Soon you may even want to learn about the benefit of transaction groups, which do allow you to merge all your transaction that have been committed&amp;nbsp;in you external&amp;nbsp;command into just one transaction, which&amp;nbsp;will e the only one item the end-user will see on the undo menu. This merging is actually necessary if your individual transaction aren't supposed to be freely undone/redone individually - that is, the whole command is to be seen as one atomic operation. I'll leave it up to you about the TransactionGroup class and&amp;nbsp;its Assimilate method in the RevitAPI help file and SDK samples.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers&lt;/P&gt;</description>
      <pubDate>Sun, 16 Aug 2015 13:54:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/prevent-user-terminating-add-in-command-prematurely-with-escape/m-p/5773121#M71080</guid>
      <dc:creator>arnostlobel</dc:creator>
      <dc:date>2015-08-16T13:54:12Z</dc:date>
    </item>
  </channel>
</rss>

