Application caption doesn't update as expected in OnActiveProjectChanged event

Application caption doesn't update as expected in OnActiveProjectChanged event

rogmitch
Advocate Advocate
486 Views
5 Replies
Message 1 of 6

Application caption doesn't update as expected in OnActiveProjectChanged event

rogmitch
Advocate
Advocate

I wanted to display my current project name as part of the IV window caption.  My addin works fine except when I change the project on the home screen by picking from the project list.  The OnActiveProjectChanged event fires but the caption only updates if I include a messagebox as shown below or move the mouse up to the titlebar.  If the messagebox line is removed the caption does not update until some other event occurs e.g. open part etc.

 

Private Sub m_appEvents_OnActiveProjectChanged(ByVal ProjectObject As Inventor.DesignProject, ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum) Handles m_appEvents.OnActiveProjectChanged

            If BeforeOrAfter = EventTimingEnum.kAfter Then
                g_inventorApplication.Caption = "IV " & g_inventorApplication.SoftwareVersion.DisplayVersion & "  (" & g_inventorApplication.DesignProjectManager.ActiveDesignProject.Name & ")"
                MsgBox(g_inventorApplication.Caption)
            End If
        End Sub

If I change the project from the dropdown project dialog the caption updates as expected when the dialog is closed.

 

Does anyone have any idea how to force the caption change when choosing from the project list on the home screen? I have tried all the usual doevents, application update commands, toolbar redraws, ActiveView refresh etc but nothing has worked.

 

Any help appreciated.

 

Roger Mitchell

0 Likes
487 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

Have you tried this Sub:

VBA.Interaction.AppActivate (ThisApplication.Caption)

to see if that causes it to update?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

rogmitch
Advocate
Advocate

Thanks for the reply.   I tried  many things but I am not sure about your suggestion so I will revisit it and let you know.  I did manage to get it to update with a hack by minimizing and then immediately maximizing the inventor application window.  The screen flashes and it is a rather poor workaround but it does work.

 

I have to say I find it extremely useful to have the project name displayed at all times as I often move between several projects with similar elements and sometimes it can be easy to lose track of which project I'm in when I am away from my computer for some time.

0 Likes
Message 4 of 6

rogmitch
Advocate
Advocate

Unfortunately the AppActivate(Application.Caption) does not update the caption if you change the project from the home page list.  I will have to stick with minimising and then maximising the appllcation window for the time being.  Thanks for the suggestion.

0 Likes
Message 5 of 6

JhoelForshav
Mentor
Mentor

Hi @rogmitch

Have you tried using UserInterfaceManager.DoEvents() ?

It seems like it could help if a messagebox helps. I've had a few situations myself where the code "runs to fast" for inventor to update. I believe what your messagebox does is giving inventor time to process messages in the message queue. This is the purpose of DoEvents. Try it like this 🙂

 

 

Private Sub m_appEvents_OnActiveProjectChanged(ProjectObject As DesignProject, BeforeOrAfter As EventTimingEnum, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum) Handles m_appEvents.OnActiveProjectChanged
        If BeforeOrAfter = EventTimingEnum.kAfter Then
            g_inventorApplication.Caption = "IV " & g_inventorApplication.SoftwareVersion.DisplayVersion & "  (" & g_inventorApplication.DesignProjectManager.ActiveDesignProject.Name & ")"
            g_inventorApplication.UserInterfaceManager.DoEvents()
        End If
    End Sub

 

Message 6 of 6

rogmitch
Advocate
Advocate

It took me a while to get back to this but I'm afraid DoEvents() did not work.  I do not think it is a timing issue but more the correct type of event is needed to drive the update i.e. closing a messagebox or moving the mouse pointer into the title bar.  Thanks for the suggestion

0 Likes