For a recent automation project, I had to run code against multiple parts in an assembly. This group of parts could be a significant number. At run-time, the client wanted to see an overview of how many files were to be processed for the current configuration and what number have already been processed.
I knew Inventor had a Progress Bar but up until recently, I had yet to have a good reason to use it.
To use the Progress bar, you need to define the following:
- Progress Bar title:
- I'm using "Creating DXDF Files..." in the code below
- Total count of files to be processed
- I'm using the count of an array (sDXFOutList). This portion has been removed from the code sample below.
- Current file being processed
- This is an incremented value
Create the progress bar before you get into your loop and be sure to close it after the loop. While in the loop, I'm incrementing the current file and updating the progess bar.
Below is the sample code and an image showing the Progress Bar during run-time. I've removed portions of the code that doesn't directly reflect the Progress Bar portion of the code.
Replace the portion that says ' Your code with whatever you need to do to each component occurrence.
Sub Main()
' Additional code has been removed
' Setup Progress Bar
Dim DXFOutCount As Integer = sDXFOutList.Count
Dim oMessage As String = "Creating DXF files...."
Dim oProgressBar As Inventor.ProgressBar
oProgressBar = ThisApplication.CreateProgressBar(False,DXFOutCount,oMessage)
Dim iDXFFile As Integer = 0
' Cycle through each occurrence
For Each oCompOcc In oLeafOccs
iDXFFile += 1
' Update the progress bar to reflect which part is being operated on
oProgressBar.Message = ("Processing file " & iDXFFile & " of " & DXFOutCount & "...")
oProgressBar.UpdateProgress
' Run Code Here
' Your code
Next
' Close the progress bar
oProgressBar.Close
End Sub
Comments