Below is for demonstration purposes to keep it all as code, I wouldn't do it this way in reality. The sample mimics the progress bar by creating a copy of it centre parent.
There are various steps for each view printed therefore you may want to look at the 'Stage' and 'Caption' properties of the event args to understand how many stages there typically are per view. You know how many views you have to start with so you can use this further analysed information accordingly to determine the progress through those views. Caption may change multiple times for each view.
Private IntCancelButton As Button = Nothing
Private IntPB As ProgressBar = Nothing
Private IntTB As TextBlock = Nothing
Private IntCancel As Boolean = False
Private Sub PChg(s As Object, e As Autodesk.Revit.DB.Events.ProgressChangedEventArgs)
IntPB.Minimum = e.LowerRange
IntPB.Maximum = e.UpperRange
IntPB.Value = e.Position
IntTB.Text = e.Caption
IntCancelButton.IsEnabled = e.Cancellable
If IntCancel AndAlso e.Cancellable Then
e.Cancel()
End If
Windows.Forms.Application.DoEvents()
End Sub
Private Function GetProgresBarWindow(ParentHwnd As IntPtr) As Window
Dim Wn As New Window With {.WindowStartupLocation = WindowStartupLocation.CenterOwner,
.WindowStyle = WindowStyle.None,
.SizeToContent = SizeToContent.WidthAndHeight,
.ResizeMode = ResizeMode.NoResize}
IntPB = New ProgressBar
IntTB = New TextBlock
Wn.BorderThickness = New Thickness(8)
Wn.BorderBrush = New Windows.Media.SolidColorBrush(Colors.LightGray)
Dim Gr As New Controls.Grid
Gr.ColumnDefinitions.Add(New Controls.ColumnDefinition With {.Width = New GridLength(400)})
Gr.ColumnDefinitions.Add(New Controls.ColumnDefinition With {.Width = New GridLength(75)})
Gr.RowDefinitions.Add(New Controls.RowDefinition With {.Height = New GridLength(30, GridUnitType.Auto)})
Gr.RowDefinitions.Add(New Controls.RowDefinition With {.Height = New GridLength(35, GridUnitType.Auto)})
Gr.Children.Add(IntTB)
IntTB.SetValue(Controls.Grid.RowProperty, 0)
IntTB.SetValue(Controls.Grid.ColumnProperty, 0)
IntTB.SetValue(Controls.Grid.ColumnSpanProperty, 2)
IntTB.Margin = New Thickness(3)
IntTB.Height = 40
Gr.Children.Add(IntPB)
IntPB.SetValue(Controls.Grid.RowProperty, 1)
IntPB.SetValue(Controls.Grid.ColumnProperty, 0)
IntPB.Margin = New Thickness(3)
IntPB.Height = 35
Dim CloseIt = Sub(s As Object, e As RoutedEventArgs)
IntCancel = True
End Sub
IntCancelButton = New Controls.Button With {.Content = "Cancel"}
Gr.Children.Add(IntCancelButton)
IntCancelButton.SetValue(Controls.Grid.RowProperty, 1)
IntCancelButton.SetValue(Controls.Grid.ColumnProperty, 1)
IntCancelButton.Height = 35
AddHandler IntCancelButton.Click, CloseIt
Wn.Content = Gr
Dim HelperWn As New Interop.WindowInteropHelper(Wn)
HelperWn.Owner = ParentHwnd
Return Wn
End Function
Public Function TObj95(ByVal commandData As Autodesk.Revit.UI.ExternalCommandData,
ByRef message As String, ByVal elements As Autodesk.Revit.DB.ElementSet) As Result
Dim Doc As Document = commandData.Application.ActiveUIDocument.Document
AddHandler commandData.Application.Application.ProgressChanged, AddressOf PChg
Dim IntPbarWn As Window = GetProgresBarWindow(commandData.Application.MainWindowHandle)
IntTB.Text = "The progress is..."
Dim VS As New ViewSet
Dim FEC As New FilteredElementCollector(Doc)
Dim ECF As New ElementClassFilter(GetType(ViewSheet))
Dim Els As List(Of ElementId) = FEC.WherePasses(ECF).ToElementIds
For i = 0 To Els.Count - 1
Dim Vsht As ViewSheet = Doc.GetElement(Els(i))
If Vsht.IsTemplate Then Continue For Else
VS.Insert(Vsht)
Next
IntPbarWn.Show()
Dim DN As String = "c:\temp"
Dim Path As String = Guid.NewGuid.ToString
Using Tx As New Transaction(Doc, "Print")
If Tx.Start = TransactionStatus.Started Then
Doc.Export(DN, Path, VS, New DWFExportOptions() With {.CropBoxVisible = False, .MergedViews = True})
Tx.RollBack()
End If
End Using
VS.Dispose()
IntPbarWn.Close()
RemoveHandler commandData.Application.Application.ProgressChanged, AddressOf PChg
Return Result.Succeeded
End Function