Accessing CAA V5 Object from Scripting Languages

Accessing CAA V5 Object from Scripting Languages

Objective:

This article describes the methodology of creating a CAA V5 object that can be accessed from scripting languages. The step by step procedure of creating a CAA V5 object( in Visual Studio 2005 ) and accessing the same from VBA (CATIA) is also presented.

Description:

·     

For calling any CAA V5 object from simple scripting language we need to use automation interfaces. Automation Interfaces are special interfaces that allow CAA V5 programming from simple scripting languages.

  • The CAA V5 IDL (Interface Definition Language) is the language used to write automation interfaces.
  • The CAA V5 IDL (Interface Definition Language) is dedicated to creating programming language independent interfaces that we can use from both compiled languages such as C++, and scripting languages such as Visual Basic and JScript with Windows, and Basic Script with UNIX.
    IDL provides C-language like declarations that associate an identifier with a type.
  • The IDL compiler (MIDL) builds the run time type library from IDL source files and stores it in a shared library(Type Library or .tplib).
    Scripting languages use these type libraries (.tplib) to access the type of information about the functions. The actual function implementation is available in a DLL.
  • The type library is a compiled version of a set of IDL files. It contains the description of all the interfaces, all the method prototypes, properties, and all the parameters they require along with their types.
    The base interface for exposed interfaces that are used in scripting languages is the IDispatch interface. The IDispatch interface derives from the IUnknown interface.
  • Compared to C++, scripting languages have parameter type support restrictions. The compatible parameters of the method signatures are available in the CAA Encyclopedia at the following link.

Steps for creating  a sample CAA Application that can be accessed from  VBscrpit (of CATIA.)

Step 1: Create a New Framework for IDL Interface creation in CAA-RADE

1. File > New CAA V5 Workspace

Select the Workspace directory and Tool Level.

2. In the New CAA V5 Workspace dialog, select “New Generic frameworks”.

3. In the New Framework dialog select ‘Framework type” as Interface and select the “IDL Support” option.

4. Create an Interface

Go to File>CAA V5 Item > Interface.

In the Insert Interface dialog, Provide the Interface name and Select language as  “ Automation IDL”,  Select Header repository as “PublicInterfaces”.

This module will generate .idl file.

Resolve the Common build error:

If framework is not visible in the solution explorer then close the workspace, and delete the ToolsData Folder in the workspace and open the workspace in the VC again. And build the workspace using mkmk.

After the build an error will be generated saying  that “unresolved type declaration : AnyObject [ Interface ‘Test’  ]”

Open the .MK file in  the TypeLib.m module and delete :   JS0GROUP JS0FM JS0GROUP from the WIZARD_LINK_MODULES.

Open the .tplib file from the same module and  add the following macro in the Prerequisite type libs after   #pragma REPREQ InfTypeLib

#pragma REPREQ InfTypeLib in the // Prerequisite type libs

Accessing CAA V5 Object from Scripting Languages

Build the workspace using mkmk.

A Successful built will produce a TypeLibrary that corresponds to the IDL and a DLL that corresponds to Interface.

Step 2 : Create a New Framework for Implementation.

1. File>Add CAA V5 project > New Framework.

Select Framework type as “Implementation” and complete the framework creation.

2. Insert a new module in the above Framework

File> Add CAA V5 project—New Module.

3. In the New Module dialog select the Shared Object option under the  Module Information options.

4. Add new Item to the created Module.

File>Add CAA V5 Item>Component.

6. In the Insert, Component Dialog provides the following information.

Derived from option provide “ CATBaseObject “.

In the TIE Mode option ADD the created Interface.

In the Header Repository select “ Public Interfaces”.

Build the Workspace, this generates a DLL (Shared Library) that corresponds to the Implementation Module.

Steps for using CAA Object in the CATIA VBA Script.

  1. Start the CATIA Session and open the required file.
    Open  VBA Editor by following

    Tools> Macro > Visual Basic Editor.

    3.  Add the Type Library (.tplib) that we created.

    Go to Tools>References and add the library by using the Browse button.

    Open a new Module and add the following lines of code after  CATMain()

    //Declare a Variable of type VB Object name, this VB object name is available in the IDL file that we created in Step 1.

    1. Dim (Variable Name) As (VB Object Name)

    // Set the Variable to the CATIA Application.

    2. Set (Variable Name)  = GetObject(“”, “CATIA.Application”)

    // Call the Method or Function in the interface

    3. Call  (Variable Name). (Method Name).


    Example code:

    Dim CATIATUTORObj As DrawingFactory

    Set CATIATUTORObj =  GetObject(“”, “CATIA.Application”)

    Call CATIATUTORObj.MyFunction();

Leave a Reply

Your email address will not be published. Required fields are marked *