CATIA caa 使用脚本语言调用CAA V5对象

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 create programming language independent interfaces that we can use from both a 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 uses these type libraries (.tplib) to access the type information about the functions. 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 IDispatch interface. IDispatch interface derives from 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.

CAADoc\Doc\online\CAASysTechArticles\CAASysAutomationItf.htm

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 New CAA V5 Workspace dialog , select “New Generic frameworks”.

3. In the New Framework dialog select ‘Framework type” as Interface and select “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

Build the work space 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 New Module dialog select 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  provide the following information.

For 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 Implementation Module.

Steps for using CAA Object in the CATIA VBA Script.

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

Tools> Macro > Visual Basic Editor.

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

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

  1. 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();

QR Code
微信扫一扫,欢迎咨询~

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 155-2731-8020
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

手机不正确

公司不为空