0

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?

inxcent
  • 5
  • 3
  • how do you start catia? through the shortcut or through another process? if is through process you can directly have an information about catia instance activity. through getobject you cant know which instance was active neither how many. if you just want to read if process exists you can do it through windows processes too – tsolina Jan 15 '19 at 14:32

3 Answers3

1

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.

akhil kumar
  • 1,598
  • 1
  • 13
  • 26
0

Thanks, it works fine.

I put this code inside Tick event, set timer to enabled, and use 1000ms interval to check every 1 second for CATIA link.

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    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
End Sub
inxcent
  • 5
  • 3
0

I would recommend to ask the actual Catia Object in timer instead of getting new object. Assuming you have Global CatiaApp variable

Put in the timer something like this

Try
   If CatiaApp.Name.Length > 0 Then
   'catia is alive
   End If
Catch ex As Exception
   'catia is down
   CatiaApp = Nothing
End Try

You get an exception if Name.Length fails which signal that catia is down

DJakub
  • 41
  • 5