I have an Addin based on the Modeless Sample which our staff use to manage sheets, including creating PDF's by printing to the Adobe PDF driver.
For most of the time and with most of the users it all works fine. However there have been several cases of it causing Revit to crash when printing. I have had this while debuging, it happens at the SubmitPrint line
Here is my code for printing selected sheets:
Public Sub SelectionPrint(ByVal uiapp As UIApplication)
Try
Dim doc As Autodesk.Revit.DB.Document = uiapp.ActiveUIDocument.Document
Dim uidoc As UIDocument = uiapp.ActiveUIDocument
For n = 0 To Selected_ID_List.Count - 1
Dim vw As Autodesk.Revit.DB.View = doc.GetElement(Selected_ID_List(n))
'open the view and then print it
uidoc.ActiveView = vw
'print the active view
MyPrintMgr.SubmitPrint()
Next
Select Case Selected_ID_List.Count
Case 1
Update_Text = "1 sheet printed"
Case Else
Update_Text = Selected_ID_List.Count & " sheets printed"
End Select
Catch ex As Exception
DisplayError(ex)
End Try
End Sub
I recently came across this article by Aaron Lu and wondered if something similar is happening?
Edited on 2016/3/8
Someone found the above code "ExternalEvent.Create" method throws Autodesk.Revit.Exceptions.InvalidOperationException: Attempting to create an ExternalEvent outside of a standard API execution, that is a true bug in my code, sorry for that :-(. And the solution is easy: do not call "ExternalEvent.Create" in modeless dialog but in "IExternalCommand.Execute" or "IExternalApplication.OnStartup". Following is a full code example showing that: Run ExternalCommand "EventRegistrationInModelessDialogViaExternalEvent" and then click the button in the modeless dialog to register or unregister DocumentChanged event.