skeletank
skeletank

Reputation: 2888

Revit 2016 R2 Crashes on UIApplication.OpenAndActivateDocument

Background

I have a Revit 2016 add-in that does batch exporting to DWF from the main model and its linked models. It works by exporting sheets from the main model and looping through the linked models to export additional sheets. It uses UIApplication.OpenAndActivateDocument to open a document and Document.Close to close it. Because the Revit API does not allow you to close the active document it must open a placeholder document before it closes the active document and opens the next one. This has been working since at least Revit 2014 but has stopped working since the release of Revit 2016 R2.

Now it fails on the call to UIApplication.OpenAndActivateDocument when you export more than a couple of sheets. Even with the most recent release of Revit 2016 R2 Update 4 the issue still exists.

Error

The error is thrown from the UIApplication.OpenAndActivateDocument method. It looks like this:

System.ComponentModel.Win32Exception was unhandled ErrorCode=-2147467259 HResult=-2147467259 Message=Not enough quota is available to process this command NativeErrorCode=1816 Source=WindowsBase StackTrace: at MS.Win32.UnsafeNativeMethods.PostMessage(HandleRef hwnd, WindowMessage msg, IntPtr wparam, IntPtr lparam) at System.Windows.Interop.HwndTarget.UpdateWindowSettings(Boolean enableRenderTarget, Nullable`1 channelSet) at System.Windows.Interop.HwndTarget.UpdateWindowPos(IntPtr lParam) at System.Windows.Interop.HwndTarget.HandleMessage(WindowMessage msg, IntPtr wparam, IntPtr lparam) at System.Windows.Interop.HwndSource.HwndTargetFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)

Here is what the end of the journal file shows:

' 2.510552 2:< ' 1:< ***NOBLE invalidated secondary data id = 130129 due to the modified link document.
' 1:< ***NOBLE invalidated secondary data id = 130130 due to the modified link document.
' 1:< ***NOBLE invalidated secondary data id = 130131 due to the modified link document.
' 1:< ***NOBLE invalidated secondary data id = 130134 due to the modified link document.
' 1:< ***NOBLE invalidated secondary data id = 138258 due to the modified link document.
' 1:< ***NOBLE invalidated secondary data id = 138259 due to the modified link document.
' 1:< ***NOBLE invalidated secondary data id = 138983 due to the modified link document.
' 1:< ***NOBLE invalidated secondary data id = 140000 due to the modified link document.
' 1:< ***NOBLE invalidated secondary data id = 5964554 due to the modified link document.
' 1:< ***NOBLE invalidated secondary data id = 6073456 due to the modified link document.
' 1:< 0 ModelServerState "Destroyed": Current server = "Not Queried", Model server = "", Model server state = "Not Applicable"
' 6:< --TB- Level 368 - Levels : Level : FF EL
' 0.104902 6:<<--TB- recomputeCircuits
' 1.094590!!!!! 4:!!!BIG_GAP ;PERF;MISC;regenerating
' 1.315856 3:<<;PERF;MISC;regenerating/ALL_GAPS 1.210954/TurnOff_GAPs 100%
' 1:< Managed exception occurred:
'C 03-May-2016 08:43:03.892; 1:< Not enough quota is available to process this command
'C 03-May-2016 08:43:03.892; 1:< ExceptionCode=0xe0434352 ExceptionFlags=0x00000001 ExceptionAddress=000007FEFCD0A06D
' 1:< System (MB) [Available / Total ] [Revit Memory Usage (MB) ]
' 1:< RAM Statistics: 9845/ 16323 3199=InUse 3243=Peak
' 1:< VM Statistics: 8381636 / 8388607 3089=InUse 3120=Peak
' 0:< [00002088]QueueMinder stopped
' 2:< ::100:: Delta VM: Avail +3 -> 8381638 MB, Used 3089 MB; RAM: Avail +109 -> 9955 MB, Used -1 -> 3198 MB
'C 03-May-2016 08:43:04.652; 2:< OMICRON finished virtualization services
'C 03-May-2016 08:43:04.652; 2:< OMICRON finished worker services
'C 03-May-2016 08:43:04.652; 2:< OMICRON erased queues
' 0.760501 2:<< ' 1:< SLOG $2360798f 2016-05-03 08:43:04.736 >Crash
' 1:< SLOG System (MB) [Available / Total ] [Revit Memory Usage (MB) ]
' 1:< SLOG RAM Statistics: 9957 / 16323 3198=InUse 3243=Peak
' 1:< SLOG VM Statistics: 8381643 / 8388607 3089=InUse 3120=Peak
' 1:< SLOG $2360798f 2016-05-03 08:43:04.746 ' 1:< FileCheckTrigger dependencies update
' 1:< Third Party Updater 'Revit: ObjectNumberingUpdater' has been unregistered.
' 1:< Third Party Updater 'Revit: ObjectNumberingUpdater' has been unregistered.
' 1:< Before : Destroy Display Manager
' 1:< System (MB) [Available / Total ] [Revit Memory Usage (MB) ]
' 1:< RAM Statistics: 9956 / 16323 3198=InUse 3243=Peak
' 1:< VM Statistics: 8381643 / 8388607 3089=InUse 3120=Peak
' 1:< After : Destroy Display Manager
' 1:< System (MB) [Available / Total ] [Revit Memory Usage (MB) ]
' 1:< RAM Statistics: 9956 / 16323 3198=InUse 3243=Peak
' 1:< VM Statistics: 8381643 / 8388607 3089=InUse 3120=Peak
' 1:< compact data space: 380388 blocks, occupying total of 165719148 bytes > ' 1:< freed 380388 blocks
' 2:<::100:: Delta VM: Avail +36 -> 8381675 MB, Used 3089 MB; RAM: Avail -2 -> 9953 MB, Used -1 -> 3197 MB
' 2:< DBG_INFO: Detected unfrozen change of selection.: line 609 of d:\sunrise\2016_px64\source\revit\revitui\modscope\ModScope.cpp.
' 2:< ;PERF;MISC;FullUpdateGraphicCacheUpdater::updateAll() DBViewProject id=275: 2545 elements need cache update
' 1:< Unconverted MessageBox "A fatal error has occurred. The application will be terminated. You have the opportunity to save recovery files for all of your changed projects.

Theory

I'm guessing that the problem has started because of the new feature introduced in 2016 R2 which causes DWFs to be exported using multiple processes instead of a single one as in previous versions. I've tried to post my problem on the Autodesk Forums but have yet to receive a response from their support.

I'm also guessing that it's tied to memory as I've read about the "Not enough quota is available to process this command message" from several internet sources but my machine has 16GB of RAM which is supposed to be suitable for Revit.

Does anyone else have any ideas?

Upvotes: 1

Views: 1053

Answers (2)

skeletank
skeletank

Reputation: 2888

I found a way to restructure my program so that instead of calling Document.Export a single time with a ViewSet containing all of the sheets in the current model it will call Document.Export once for each sheet in the current model by passing in a ViewSet containing that single sheet. For whatever reason this stops Revit from crashing, probably because it relinquishes the resources that normally cause the crash.

Note that by doing this the DWFs will be exported sequentially instead of in parallel because only by passing in multiple sheets in a single call can you take advantage of the multi-process exporting introduced in Revit 2016 R2. Ironically, the sequential method is just as fast as the parallel method.

Upvotes: 1

skeletank
skeletank

Reputation: 2888

I found out more about the error "Not enough quota was available to process this command" from this question about DataGrid. Evidently the issue has to do with the Windows UI messaging queue which I must admit that I do not fully understand. There is a queue for these underlying PostMessage function calls and a default 10,000 call limit. The quota error is sent when this limit is reached. I'm not in control of the underlying Revit code so I just decided to increase this limit (which is stored as a registry key) and that worked for me (after restarting my computer). My solution was to set the following registry key to 1,000,000:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\Windows\USERPostMessageLimit

I initially tried 20,000 but the error still kept appearing so I picked an arbitrarily high number of 1,000,000 and the error went away. Then I started testing for our largest model at lower values and a value of 500,000 was the lowest possible setting that would not trigger the error. For now I'm letting a single user run with it configured this way because I'm not sure if it will cause problems with other Windows applications seeing as how it affects more than just Revit.

Upvotes: 1

Related Questions