Inventor Progress bar

Inventor Progress bar

^_^clovis^_^
Advocate Advocate
3,104 Views
6 Replies
Message 1 of 7

Inventor Progress bar

^_^clovis^_^
Advocate
Advocate

Hello,

 

Although I know how to implement an inventor.progressbar in a vba macro,

I was wondering if it's possible to use the Inventor standard progress bar (right under) in vba macro's instead?

 

InventorProgressBar.PNG

 

Thanks

 

0 Likes
Accepted solutions (1)
3,105 Views
6 Replies
Replies (6)
Message 2 of 7

bradeneuropeArthur
Mentor
Mentor
Accepted solution
Public Sub TestStatusBarProgressBar()
    Dim iStepCount As Long
    iStepCount = 50

    ' Create a new ProgressBar object.
    Dim oProgressBar As ProgressBar
    Set oProgressBar = ThisApplication.CreateProgressBar(True, iStepCount, "Test Progress")

    ' Set the message for the progress bar
    oProgressBar.Message = "Executing some process"

    Dim i As Long
    For i = 1 To iStepCount
        ' Sleep 0.2 sec to simulate some process
        Sleep 200
        oProgressBar.Message = "Executing some process - " & i
        oProgressBar.UpdateProgress
    Next

    ' Terminate the progress bar.
    oProgressBar.Close
End Sub

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 3 of 7

Anonymous
Not applicable

just a litle correction>> line 6

 

progressBar = invApp.CreateProgressBar(false, 10, "Test Progress");

 

if you put true, the bar will not be visible.

 

att.

 

Message 4 of 7

DRoam
Mentor
Mentor

@Anonymous wrote:

if you put true, the bar will not be visible.


Actually, not quite. According to the API reference manual, that first argument is called "DisplayInStatusBar", and it "specifies whether the progress bar should be displayed in the status bar or as a dialog."

 

Setting that argument to True doesn't make the bar invisible, it just displays it in the status bar (as in the OP's screenshot) instead of as a pop-up.

Message 5 of 7

sam
Advocate
Advocate

@DRoam @bradeneuropeArthur Hi guys, 

 

If I may ask, by reading the code of progress bar I couldn't understand how I can implement with my macro. In the macro depending on form selection various subs do their thing and sometimes it takes half a minute to finish. How can I implement the progress bar to be shown while code is running? thanks in advance. 

 

regards, 

sam

0 Likes
Message 6 of 7

Liam.U
Contributor
Contributor

Hi Sam, I've just been through what you were trying to do and figured it out.

It's actually very simple if you have a macro that already does some sort of loop (eg. For Each x In y or For i = 0 To y etc).
Put this before the loop:

iStepCount = brs.count 'example from a macro that goes through bom roms, replace with your loop count

    ' Create a new ProgressBar object.
    Dim oProgressBar As ProgressBar
    Set oProgressBar = ThisApplication.CreateProgressBar(False, iStepCount, "Checking all components iproperties etc")

Then at the start of your loop add:

    PN = oDoc.displayName 'optional addition
    oProgressBar.Message = "Checking component " & PN
    oProgressBar.UpdateProgress

Then the progress bar will update with each loop.

After your loop add:

    ' Terminate the progress bar.
    oProgressBar.Close

 

0 Likes
Message 7 of 7

WCrihfield
Mentor
Mentor

Since this topic was just brought up again, and it is a relatively popular and important topic, I decided it may be a good time to drop an additional 'Tip' or few in here about it, so that others to find this topic again will know about them.

 

If your process is a relatively long one (many iterations), &/or is a relatively complex one that may require a lot of processing, &/or may have opportunities for errors or unforeseen complications, then you may want some additional control over the situation.  This is because sometimes processes can take much longer than expected, or may cause Inventor to seemingly 'freeze' (become unresponsive), or you remembered a detail you forgot in the code process just after starting the process, or simply want to stop the process before it finishes for whatever reason.  In cases like that, I recommend that when using the CreateProgressBar method, you specify True for the optional fourth input parameter named "AllowCancel".  Doing so should make the Cancel button visible in the ProgressBar dialog.  However, at this point, clicking that cancel button will only cancel the ProgressBar object itself, because that ProgressBar object does not know what 'process' you are doing that needs to be stopped, it only knows how many steps there are supposed to be.  So, to make this cancel button's functionality more useful / beneficual, we will need to incorporate at least two 'outside' resources into our overall code that are defined outside of the 'main' routine.   One of those resources would be a separate Sub routine, designed to be the 'event handler' (routine designated to run in response to an Event happening) for the ProgressBar.OnCancel Event.  Another resource will be a Boolean type variable, which will indicate the current status of whether we want the process to be canceled or not.  One of the things the code within the event handler Sub routine will do is set the value of that Boolean variable.  Now, with those two recourses in place, we have an extra thing to 'check' within the 'iteration' of 'the process'.  Just inside the iteration loop of the main process code, before we even deal with the ProgressBar.Message or the ProgressBar.UpdateProgress method, we would check the value of that special Boolean type variable.  And if it indicates that the cancel button has been used, or the ProgressBar has been canceled, then use a line of code like "Exit For" or "Exit Do", or "Exit Sub", to either exit that iteration, or exit the entire code process.

 

@JelteDeJong has a good Blog post about this strategy with a code example.  It also includes the use of a third outside tool which you may like.

The link to that post is below:

http://www.hjalte.nl/64-stop-long-running-rule 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes