Revit crashes using API to export DWG

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Today I encountered a consistent crash using Revit API to export DWG. This cost me several hours so I wanted to share. Perhaps I'm doing something wrong, or maybe it's a bug?
The scenario: With the Project Browser as active view in Revit, I execute the command shown in code below. The command simply opens a "non ui" document and attempts to export a plan view to DWG. This crashes Revit 98% of time for me, and the other 2% results in having to restart Revit.
Note: Important part here is "with Project Browser as active view". If a drawing view is active then Revit does not crash. My solution is to disable the command if active view is System/Project Browser.
<Transaction(TransactionMode.Manual)> <Regeneration(RegenerationOption.Manual)> Public Class Test Implements IExternalCommand Public Function Execute(ByVal commandData As ExternalCommandData, ByRef message As String, ByVal elements As ElementSet) As Result Implements IExternalCommand.Execute Dim app As Application = commandData.Application.Application 'Open docuemnt "behind scenes" Dim doc = app.OpenDocumentFile("C:\Users\Jon\Desktop\Project1.rvt") 'find first plan view to use as test export Dim cViewPlans As New FilteredElementCollector(doc) cViewPlans.OfClass(GetType(ViewPlan)).WhereElementIsNotElementType() Dim views As IList(Of ElementId) = New List(Of ElementId) For Each vp As ViewPlan In cViewPlans If Not vp.IsTemplate Then views.Add(vp.Id) Exit For End If Next 'attempt to export If views.Count = 1 Then doc.Export("C:\Users\Jon\Desktop", "TestExport", views, New DWGExportOptions) doc.Close() Return Result.Succeeded End Function End Class
I get the following error message when crashing.
In the off chance Revit doesn't crash, I get the following errors when attempting to activate a plan view. Ultimately this causes me to restart Revit.
I am very interested to know if there is good reason for this behavior, or if it's an API bug. I'm guessing the non crash errors may give insight into what is happening.
Thanks,
Jon