iLogic: Hacking the Progress Bar

iLogic Progress bar

What happens when I spend a night away in a hotel on business? I seem to find myself writing and testing iLogic code! Getting the progress bar to work with iLogic turns out to be quite simple, the API sample is a bit tricky, but I got there, and hopefully you will be able to re-use this code quite easily.

I created 2 versions of the code, one for parts and one for assemblies. Parts require a bit more input in the code (below the animation), the progress bar needs to be prompted to update at each step. The sample iLogic code that I have put together should be really easy to follow. Simply replace the “InventorVb.SetViewCamera”  code with your code.

The animated GIF below shows the progress bar, implemented in iLogic on a part file.

Autodesk Inventor iLogic progress bar parts

Here is the part file code:

' iLogic Code by @ClintBrown3D - Originally posted at https://clintbrown.co.uk/Progressbar
'Create a new Progress Bar
Dim oProgressBar As Inventor.ProgressBar
oProgressSteps = 5
oProgressStep = 0
oProgressStaticText = "iLogic progress bar demo:  Step "
oProgressBar = ThisApplication.CreateProgressBar(False, oProgressSteps, "@ClintBrown3D")'Big Progress Bar, use True for small
oProgressBar.Message = (oProgressStaticText & oProgressStep & " of " & oProgressSteps)
oProgressBar.UpdateProgress

'Part Model progress bar step 1
InventorVb.SetViewCamera(ViewCameraOption.SetExtents, New Double() {6.1656988165194626, 6.3371488354022087, 7.6966839334780808}, New Double() {0, 0.17145001888275146, 1.5309851169586182}, New Double() {-0.40824829046386291, 0.81649658092772626, -0.40824829046386318}, New Double() {4.1673777842621327, 5.6634496801562131})
oProgressStep += 1
oProgressBar.Message = (oProgressStaticText & oProgressStep & " of " & oProgressSteps)
oProgressBar.UpdateProgress

'Part Model progress bar step 2
InventorVb.SetViewCamera(ViewCameraOption.FitExtents, New Double() {10.67930369627708, 0.17145000000056876, 1.5309850000000027}, New Double() {8.2109424814902354E-09, 0.17145000000056876, 1.5309850000000003}, New Double() {0, 1, 0}, New Double() {5.3396518440330683, 7.25656542165135})
oProgressStep += 1
oProgressBar.Message = (oProgressStaticText & oProgressStep & " of " & oProgressSteps)
oProgressBar.UpdateProgress

'Part Model progress bar step 3
InventorVb.SetViewCamera(ViewCameraOption.FitExtents, New Double() {8.2109401102084665E-09, 0.17145000000056876, 12.210288688066134}, New Double() {8.2109424814902354E-09, 0.17145000000056876, 1.5309850000000003}, New Double() {0, 1, 0}, New Double() {5.3396518440330683, 6.3991716535807814})
oProgressStep += 1
oProgressBar.Message = (oProgressStaticText & oProgressStep & " of " & oProgressSteps)
oProgressBar.UpdateProgress

'Part Model progress bar step 4
InventorVb.SetViewCamera(ViewCameraOption.SetExtents, New Double() {6.1656988165194626, 6.3371488354022087, 7.6966839334780808}, New Double() {0, 0.17145001888275146, 1.5309851169586182}, New Double() {-0.40824829046386291, 0.81649658092772626, -0.40824829046386318}, New Double() {4.1673777842621327, 5.6634496801562131})
oProgressStep += 1
oProgressBar.Message = (oProgressStaticText & oProgressStep & " of " & oProgressSteps)
oProgressBar.UpdateProgress

'Part Model progress bar step 5
InventorVb.SetViewCamera(ViewCameraOption.FitExtents, New Double() {10.67930369627708, 0.17145000000056876, 1.5309850000000027}, New Double() {8.2109424814902354E-09, 0.17145000000056876, 1.5309850000000003}, New Double() {0, 1, 0}, New Double() {5.3396518440330683, 7.25656542165135})
oProgressStep += 1
oProgressBar.Message = (oProgressStaticText & oProgressStep & " of " & oProgressSteps)
oProgressBar.UpdateProgress

oProgressBar.Close

Assemblies are a bit easier, because you can use an iteration to go through the model, so there is less need to manually update the progress bar.

Here is an animated GIF of the progress bar implemented on an assembly. The iLogic code (at the bottom) is iterating through the assembly and moving the model around for each component found, it’s not at all useful in terms of doing anything to the files, but it easily shows how you can implement the progress bar.

Autodesk Inventor iLogic - Progress Bar Assembliez

' iLogic Code by @ClintBrown3D - Originally posted at https://clintbrown.co.uk/Progressbar
' Create a new Progress Bar
Dim oProgressBar As Inventor.ProgressBar
oProgressBarSteps = ThisAssembly.Components.Count 'Calculate the amount of parts in the Assembly
oProgressBar = ThisApplication.CreateProgressBar(False, oProgressBarSteps, "@ClintBrown3D")'Big Progress Bar, use True for small
oProgressBarStep = 0
'oProgressBar.Message = ("iLogic Progress Bar Demo:  Step " & oProgressBarStep & " of " & oProgressBarSteps)

'Iterate Through the Assembly
Dim oDoc As Inventor.AssemblyDocument
oDoc = ThisApplication.ActiveDocument
Dim oCompDef As Inventor.ComponentDefinition
oCompDef = oDoc.ComponentDefinition
Dim oCompOcc As ComponentOccurrence
For Each oCompOcc In oCompDef.Occurrences
oProgressBarStep += 1
oProgressBar.Message = ("iLogic Progress Bar Demo:  Step " & oProgressBarStep & " of " & oProgressBarSteps)

'========================================================================================
'Insert your own iLogic code here

'Set Model to ISometric View
InventorVb.SetViewCamera(ViewCameraOption.FitExtents, New Double() {10.357674367992015, -10.22432435330543, 12.765969313947291}, New Double() {0, 0.13335001468658447, 2.4082949459552765}, New Double() {-0.408248290463863, 0.408248290463863, 0.816496580927726}, New Double() {6.93388885828219, 9.4828067097788349})

'Part Model progress bar step 2
InventorVb.SetViewCamera(ViewCameraOption.FitExtents, New Double() {-3.9834842493507989E-15, -17.806668165857698, 2.4082949459552756}, New Double() {0, 0.13335001468658447, 2.4082949459552765}, New Double() {5.5511151231257839E-17, 1.1102230246251568E-16, 1}, New Double() {4.0022803082553153, 6.7110190525141942})

'========================================================================================

' Display the Progress Bar
oProgressBar.Message = ("iLogic Progress Bar Demo:  Step " & oProgressBarStep & " of " & oProgressBarSteps)
oProgressBar.UpdateProgress
Next

' Terminate the progress bar.
oProgressBar.Close