Infrastructure

Invoking CATIA from a Scripting Language


Access to the CATIA object model is provided using scripts in different ways depending on the operating system and on the applications that can share their own objects with CATIA. This also applies for ENOVIA DMU and DELMIA products. In the following you can subsitute "DMU" or "DELMIA" to "CATIA" if you need to access or launch another application based on the common V5 platform.

CATIA is an OLE Automation server for Windows and allows macro record and replay for both Windows and UNIX. The following summarizes CATIA scripting capabilities.

With Windows:
  • In-process access using Visual Basic Scripting Edition or Visual Basic for Application since CATIA hosts both scripting engines.
  • Out-process access from the following OLE Automation clients:
    • Visual Basic for Applications via other applications like those of Office
    • Visual Basic 6 Development Studio
    • Windows Scripting Host and scripting languages such as VB Script or JScript
    • an a html page
With UNIX:
  • in-process access using Visual Basic Scripting Edition.

The macros recorded from the Tools menu and the Record Macro dialog box can use:

In-process access means that the script interpretation is performed in the same process as CATIA. You usually run the macros from the Macros window triggered from the interactive Tools->Macros command. In this case, the macro is processed by CATIA just like any other command.

Out-process access means that you run the macro from another application running in another process. In this case, the macro should first connect to CATIA to then access its data. This connection starts CATIA if no CATIA process is being running.

You can find information about in-process and out-process access in:

Running In-process Macros

In-process access means that the script interpretation is performed in the same process as CATIA using the scripting engine(s) hosted by CATIA. You can run in-process macros with UNIX and Windows. You have three means to run in-process macros:

  1. You usually run the macros from the Macros window triggered from the interactive Tools->Macros command. In this case, the macro is processed by CATIA just like any other command.
    Note that you can add arguments to the CATMain function:
      Sub CATMain(X, Y)
       ' Here we expect X as a scalar and Y as an object
       MsgBox X  & TypeName(Y) End Sub

    When launching such a macro, a dialog windows will request valuation of arguments. 

    Note that even if you use a macro language allowing to type to those arguments, the types won't be user at runtime, so it is recommended to give an explicit name to the variable to avoid end-user mystakes:

      Sub CATMain(iThisNumber, oThatObject)
  2. You can start CATIA and request that a macro being executed as soon as CATIA is started using the -macro option followed by the full path of the macro you want to run:
    CNEXT -macro E:\Users\Macros\MacroToRun.CATScript
    This runs the CATMain function defined in the MacroToRun.CATScript file. Macros can however be stored in other macro libraries like catvba documents or any other V5 documents like CATPart or CATProduct documents. You can use the following syntax to run the CATMain function defined in the myMacro macro of the myDocument document:
    CNEXT -macro myDocument.catvba myMacro 
    CNEXT -macro myDocument.CATPart myMacro
    CATIA sessions launched this way will remain active after the end of the macro unless you explicitly end it in the macro using the CATIA.Quit method.
     
  3. You can start CATIA in batch to execute a macro using the -batch option followed by the full path of the macro you want to run:
    CNEXT -batch -macro E:\Users\Macros\BatchMacro.CATScript
    this generally improves performances by avoiding visualization refreshes. Any syntax of the -macro option can be used with the -batch option. CATIA sessions launched this way will end by itself after the execution of the macro.

     

Running Out-process Macros

Out-process access means that you run the macro from another application running in another process, such as from Visual Basic for Applications associated with products such as Excel or Word, or from Microsoft Visual Basic 5 Development Studio. You can also use the Windows Scripting Host to run VBScript or JScript macros by simply double clicking the macro name from the Windows desktop or Explorer, or from the command console. You can finally use VBScript or JScript macros embedded in html pages.

The macro should first connect to CATIA to then access its data. This connection starts CATIA if no CATIA process is being running. The script is interpreted by the scripting engine hosted by the application from which you start the macro.

You can run out-process macros with Windows only.

Running Out-process Macros from VB 6 or VBA

You can use the following syntax when using Visual Basic 6 or Visual Basic for application

Dim CATIA As Object
Set CATIA = CreateObject("CATIA.Application")

Running Out-process Macros Using the Windows Scripting Host

Another way is to use the Windows Scripting Host. This is a language-independent scripting host which enables scripts written in different languages such as Visual Basic, JScript, and Perl, to be run from the Windows desktop, the Windows Explorer, or the command console.

With Visual Basic, your script should begin by the connection to CATIA, using either CreateObject or GetObject, as follows:
Dim CATIA
Set CATIA = WScript.CreateObject("CATIA.Application")

or

Dim CATIA
Set CATIA = WScript.GetObject("", "CATIA.Application")

Note that the GetObject method requires that its first argument be blank.

To run the macros from the Windows desktop, simply double click on the macro name. These names are suffixed using vbs for Visual Basic.

To run the macros from the command console, use the cscript command as follows:

cscript e:\users\psr\Scripting\Sample\CATIA.vbs

Running Out-process Macros from a Dynamic HTML Page

You can also run macros VBScript macros embedded in a html page. There are several ways of embedding a macro in a html page:

[Top]


Copyright © 1994-2004, Dassault Systèmes. All rights reserved.