Opening CATIA-V5 using VB.Net

Shailesh Sangle

Opening CATIA-V5 using VB.Net
Hi Friends,
            
                I want to connect CATIA-V5 and VB.Net to create an application which will draft the machine parts (like knuckel,Cotter etc.), inputs for which will be supplied from Vb.net.
I got the code for drafting parts into CATIA from macro application.I just want to know how to open CATIA window(when CATIA is running as well as not running). If u have code for this please reply me.
                Guys, reply soon it is BE Project. Thanx in advance.

Grzegorz Olesinski

RE: Opening CATIA-V5 using VB.Net
(in response to Shailesh Sangle)

Dim CATIA As INFITF.Application

CATIA = GetObject(, "CATIA.Application")

If Err.Number 0 Then

   CATIA = CreateObject(CATIA.Application)

  CATIA.Visible = True

End If

 

Thats how to get/open Catia. You could search the forum - there are some topics about Catia in VB.NET

Shailesh Sangle

RE: Opening CATIA-V5 using VB.Net
(in response to Shailesh Sangle)

Thanks GRZECHU, for replaying.

I typed the code given by u behind the button, but I got following error

"A first chance exception of type 'System.Exception' occurred in Microsoft.VisualBasic.dll"

could you help on it.Please, reply soon.

Grzegorz Olesinski

RE: Opening CATIA-V5 using VB.Net
(in response to Shailesh Sangle)
Did you add proper reference?

Shailesh Sangle

RE: Opening CATIA-V5 using VB.Net
(in response to Shailesh Sangle)
Yes I have added almost all the reference files. But if u know any important one then tell me, I will check it again

Grzegorz Olesinski

RE: Opening CATIA-V5 using VB.Net
(in response to Shailesh Sangle)

Look there:
http://www.coe.org/Collaboration/DiscussionForum/ActiveDiscussions/tabid/210/forumid/10/postid/113709/view/topic/Default.aspx

Do you get this error while compilling project in VB, or when you publish it on a servere? If while compilling, write in which line?

COE Administrator

RE: Opening CATIA-V5 using VB.Net
(in response to Shailesh Sangle)

I get this error for following line while compiling

CATIA = GetObject(, "CATIA.Application")

Grzegorz Olesinski

RE: Opening CATIA-V5 using VB.Net
(in response to Shailesh Sangle)

Could you paste here code of whole function, in which you get this error? Or if it's to big, at least begin of it - head of the function and code you use to open catia.

And I forgot about one thing - put: On Error Resume Next before line, when you got the error, and On Error GoTo 0 after End If

COE Administrator

RE: Opening CATIA-V5 using VB.Net
(in response to Shailesh Sangle)
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim CATIA As INFITF.Application

        CATIA = GetObject(, "CATIA.Application"

        If Err.Number 0 Then

            CATIA = CreateObject(CATIA.Application)

            CATIA.Visible = True

        End If

    End Sub
End Class

Error :  "first chance exception of type 'System.Exception' occurred in Microsoft.VisualBasic.dll "  it pop-up on Immediate window and not on error window.

This is the code of program. I have not yet added any code for drafting, I thought I should open CATIA window first, then I will be no problem to draft part by code.

Grzegorz Olesinski

RE: Opening CATIA-V5 using VB.Net
(in response to Shailesh Sangle)

I've tried to invoke that kind of error, but I wasn't able. I hope you have Catia installed on your machine? You need to add InfInterfaces Object Library (InfTypeLib.tlb) to your project, put code like:

Dim CATIA As INFITF.Application

        On Error Resume Next

        CATIA = GetObject(, "CATIA.Application"

        If Err.Number 0 Then

            CATIA = CreateObject(CATIA.Application)

            CATIA.Visible = True

        End If
        On Error GoTo 0

and it must works

Shailesh Sangle

RE: Opening CATIA-V5 using VB.Net
(in response to Shailesh Sangle)
A first chance exception of type 'System.Exception' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.NullReferenceException' occurred in Catia.exe
A first chance exception of type 'System.NullReferenceException' occurred in Catia.exe

Hi GRZECHU,
             Now I started new project. In that I add the file- "
InfTypeLib.tlb" as follows:
Project - Add References - Browse - C:\Program Files\Dessult System\Bin\Intel_a\code\bin\IntTypeLib.tld. and typed the code given by u. Still it shows the above messages on Immediate windows.

References includes:
 - INFITF
 - System
 - System.Data
 - System.Deployment
 - System.Drawing
 - System.window.forms
 - System.xml

I don't have the original Catia software does it make any difference?
Sorry for the inconvenience cause by me

Grzegorz Olesinski

RE: Opening CATIA-V5 using VB.Net
(in response to Shailesh Sangle)
I've seen VB applications work on "not original version" of catia, so it shouldn't be that. What kind of VB environment you use? You could try on Visual Basic 2005 Express - it's free. And to add references you can use as follow: Project - Add References - COM. There are all Catia references

COE Administrator

RE: Opening CATIA-V5 using VB.Net
(in response to Shailesh Sangle)
You can try this:

1. Open command-line and change to your local CATIA-Install-Path (..intel_a\code\bin)
2. execute cnext /unregserver  'Clears all settings
3. execute cnext /regserver 'registers CATIA as a COM-Server

After that, you should be able to select the INFITF.dll under the COM-Tab in the "AddReference"-Dialog.

Another way to get  the CATIA-Object in your app is this:

Dim CATIA As INFITF.Application
CATIA = System.Runtime.InteropServices.Marshal.GetActiveObject("CATIA.Application"

Hope that helps...
regards
Kaoru