vb.netreferencelibrariescatia

VB.NET and CATIA COM libraries


I try to make form app (Windows 11) in Visual Studio 2022 to work with opened CATIA products. I added project references... enter image description here

And run this simple test:

Imports INFITF
Imports MECMOD
Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim catia As Object = Nothing

        Try
            ' Attempt to get a running instance of CATIA
            catia = GetObject(, "CATIA.Application")

            If Not catia Is Nothing Then
                Debug.WriteLine("CATIA is running.")

                ' Check if there is any document open
                If CType(catia, Application).Documents.Count > 0 Then
                    Debug.WriteLine("A document is open in CATIA.")
                Else
                    Debug.WriteLine("No documents are open in CATIA.")
                End If
            Else
                Debug.WriteLine("CATIA is NOT running.")
            End If
        Catch ex As Exception
            Debug.WriteLine("CATIA is not running or an error occurred: " & ex.Message)
        End Try
    End Sub
End Class

But result is always "CATIA is NOT running." because variable catia is always nothing regardless what I run. I have 2 versions of CATIA: CATIA V5-6R2022 and CATIA V5-6R2020

Does not matter which of them I run, my app always display "CATIA is NOT running."

Any ideas what could be the problem?

I tried to pick libraries from each CATIA versions, no change.

Then I opened catia VBA, checked physical path of its libraries and added those into my project (several .tlb files), but result is always the same. "CATIA is NOT running." because variable catia is always nothing enter image description here


Solution

  • The problem is in .NET Framework.

    I just edited .vbproj file to

    <TargetFramework>net48</TargetFramework>
    

    And now everything works as expected.