Catia V5 Api
Catia V5 Api
When we talk about scripting on Windows we talk in fact about the COMenabled DLLs accessed through TypeLibraries CATIA provides. This is a short introduction how to use this Scripting API in CATIA-VBA, VB6 and VB.Net
To get the CATIA application object you need to use the GetObject or CreateObject method, e.g. when CATIA is already running
Dim CATIA As INFITF.Application Set CATIA = GetObject(, "CATIA.Application")
This will create an Interop DLL in the bin folder of your VB.Net project
Lets see how this works in a standard VB.Net Windows application. Such an application automatically imports the following libraries
However, good practice is to have the Strict option set to on which would lead to a compiler error with the above code as the GetObject method returns a generic object not an Application object. So it needs to be changed to the following
Dim CATIA As INFITF.Application CATIA = CType(Microsoft.VisualBasic.GetObject(, "CATIA.Application"), _ INFITF.Application)
The second method is to generate the interop libraries manually using the tlbimp utility of the .Net framework. This can be found in the installation path of the framework, e.g. C:\Program Files\Microsoft.NET\SDK\v1.1\Bin\tlbimp.exe To create a interop library for the basic API (the environment variables are used to make the command line more simple (which is represented as 2 lines in the following)
set set set set TLBIMP="C:\Program Files\Microsoft.NET\SDK\v1.1\Bin\tlbimp.exe" CATIA=C:\Program Files\Dassault Systemes\B15\intel_a\code\bin TYPELIB=InfTypeLib OUT=C:\Active\Applications\VSNet\CATIAR15DLL
This creates the interop library InfTypeLib.15.0.dll in the directory %OUT% In addition a namespace is defined for this library as well as a version. You have to add this as a reference to your project using the Add references panels via Browse and select the newly created dll
which then can be used with the following code (you have to use the Namespace you have defined with tlbimp utility).
Dim CATIA As CATIA.InfTypeLib.Application CATIA = CType(Microsoft.VisualBasic.GetObject(, "CATIA.Application"), _ CATIA.InfTypeLib.Application)
Optionally without using the Microsoft.VisualBasic compatibility library it is possible to use the InterOpServices
CATIA = CType(System.Runtime.InteropServices.Marshal.GetActiveObject( _ "CATIA.Application"), _ CATIA.InfTypeLib.Application)
Using tlbimp you have to take care that some typelibs are dependant on others, e.g. KweTypeLib depends on InfTypeLib. In this case tlbimp would create an interop library automatically (like in the Visual Studio environment). To avoid this you first have to create the base interops and the reference them in the tlbimp, e.g. for KweTypeLib
set set set set TLBIMP="C:\Program Files\Microsoft.NET\SDK\v1.1\Bin\tlbimp.exe" CATIA=C:\Program Files\Dassault Systemes\B15\intel_a\code\bin TYPELIB=InfTypeLib OUT=C:\Active\Applications\VSNet\CATIAR15DLL
%TLBIMP% "%CATIA%\%TYPELIB%.tlb" /out:%OUT%\%TYPELIB%. 15.0.dll /namespace:CATIA.%TYPELIB% /asmversion:5.15.0.0 set TYPELIB=KweTypeLib %TLBIMP% "%CATIA%\%TYPELIB%.tlb" /out:%OUT%\%TYPELIB%. 15.0.dll /namespace:CATIA.%TYPELIB% /asmversion:5.15.0.0 /reference: %OUT%\InfTypelib.15.0.dll