Search code examples
vb.netvbaapicomcatia

CATIA and VB.NET detect closing of CATIA in external app


I latched onto the Catia using:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim boolCatAlive As Boolean
    boolCatAlive = False

    Try
        Dim myCatia As INFITF.Application
        myCatia = Interaction.GetObject(vbNullString, "CATIA.Application")
        boolCatAlive = True

    Catch ex As Exception
        boolCatAlive = False
    End Try

    Select Case boolCatAlive
        Case True
           'continue loading app, do my stuff

        Case Else
           'end this now
            MsgBox("No running CATIA instance detected, please start a new CATIA instance and re-run this program.", MsgBoxStyle.Critical, "Error")
            End
    End Select

End Sub

So that is a simple boolean switch at the form loading that decides whether the app is going to load or not.

This works ok, but is doing the check only once when the app is started. Is there a way to continually detect CATIA status, so that - if a user exits CATIA in the middle of my app running - app gets notified and realises that the CATIA COM link is no longer alive?

I could also use that to detect selection changes for example?


Solution

  • You can Check it All the time by using a timer.Add a timer and specify the same code in its TICK event.sorry to Post this as an answer.I don't have enough reputation to post comment.

    http://vb.net-informations.com/gui/timer-vb.htm

    This link will be helpfull to you.