1

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?

skeletank
  • 2,880
  • 5
  • 43
  • 75
  • Possibly unrelated to the issue, but can I ask why you're using OpenAndActivate to export the DWF files and not simply Open? Activating the model shouldn't be necessary and you would be able to close the model without requiring a placeholder. – Colin Stark Apr 26 '16 at 20:43
  • @cs1088 Are you referring to `Application.OpenDocumentFile`? There is no `UIApplication.Open` in the Revit 2016 API. – skeletank Apr 26 '16 at 20:49
  • Yes, sorry. I meant to edit the comment but time had passed. You should be able to use Application.OpenDocumentFile instead of UIApplication.OpenAndActivateDocument – Colin Stark Apr 26 '16 at 20:50
  • @cs1088 I haven't worked on the Revit API in a while but, if I remember correctly, that did not work in the past because I can't open the linked model while the main model is still open. I'll give it a try though. – skeletank Apr 26 '16 at 20:52
  • @cs1088 `Application.OpenDocumentFile` does not work. I get the error "Document is a linked file. Transactions can only be used in primary documents (projects or families.)". However, I have to use a transaction because [exporting to DWF requires using transactions according to Autodesk API Support](https://forums.autodesk.com/t5/revit-api/revit-api-export-dwf-error/td-p/5466357). – skeletank Apr 27 '16 at 13:19
  • I ended up getting `Application.OpenDocumentFile` to work by unloading the links before loading and then reloading them afterwards (see [this answer](http://stackoverflow.com/questions/11417713/revit-set-type-parameter-in-linked-models/35701275#35701275)). However, I inevitably received the same "Not enough quota..." error as in the initial issue. – skeletank Apr 27 '16 at 15:45
  • Sounds like you've run into a Revit bug then most likely... Is the error thrown from Application.OpenDocumentFile? I know that Autodesk staff hang out here on occasion, hopefully they see this. If you're an ADN member, I'd recommend opening an issue. Otherwise, add to your initial post in the forums with added information about your testing with Application.OpenDocumentFile and hope that someone answers – Colin Stark Apr 28 '16 at 16:15
  • @cs1088 The last time that I tested with a small number of DWFs it ran fine and then failed on WPF `Window.Close` with the same issue. It definitely seems like a memory bug or something. I'm not an ADN member but I will add back to my Autodesk forum post describing the attempt with `Application.OpenDocumentFile`. – skeletank Apr 28 '16 at 17:32
  • can you add some information form the journal? – Augusto Goncalves May 03 '16 at 13:20
  • @AugustoGoncalves I've updated my question to include the end of the journal file from when I just ran it a couple of minutes ago. – skeletank May 03 '16 at 14:04

2 Answers2

1

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.

Community
  • 1
  • 1
skeletank
  • 2,880
  • 5
  • 43
  • 75
  • This moved to: `Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows` in registry editor. – JayRizzo Mar 31 '20 at 19:58
1

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.

skeletank
  • 2,880
  • 5
  • 43
  • 75