CATIA V5 Macro Programming
CATIA V5 Macro Programming
Dieter R. Ziethen
Translated by Kyle E. Brand
ISBN: 978-0-07-180003-7
MHID: 0-07-180003-4
The material in this eBook also appears in the print version of this title: ISBN: 978-0-07-180002-0,
MHID: 0-07-180002-6.
McGraw-Hill eBooks are available at special quantity discounts to use as premiums and sales promotions, or for use in
corporate training programs. To contact a representative please e-mail us at [email protected].
All trademarks are trademarks of their respective owners. Rather than put a trademark symbol after every occurrence of
a trademarked name, we use names in an editorial fashion only, and to the benefit of the trademark owner, with no
intention of infringement of the trademark. Where such designations appear in this book, they have been printed with
initial caps.
Information has been obtained by McGraw-Hill from sources believed to be reliable. However, because of the possibility
of human or mechanical error by our sources, McGraw-Hill, or others, McGraw-Hill does not guarantee the accuracy,
adequacy, or completeness of any information and is not responsible for any errors or omissions or the results obtained
from the use of such information.
TERMS OF USE
This is a copyrighted work and The McGraw-Hill Companies, Inc. (“McGraw-Hill”) and its licensors reserve all rights
in and to the work. Use of this work is subject to these terms. Except as permitted under the Copyright Act of 1976 and
the right to store and retrieve one copy of the work, you may not decompile, disassemble, reverse engineer, reproduce,
modify, create derivative works based upon, transmit, distribute, disseminate, sell, publish or sublicense the work or any
part of it without McGraw-Hill’s prior consent. You may use the work for your own noncommercial and personal use;
any other use of the work is strictly prohibited. Your right to use the work may be terminated if you fail to comply with
these terms.
THE WORK IS PROVIDED “AS IS.” McGRAW-HILL AND ITS LICENSORS MAKE NO GUARANTEES OR
WARRANTIES AS TO THE ACCURACY, ADEQUACY OR COMPLETENESS OF OR RESULTS TO BE OBTAINED
FROM USING THE WORK, INCLUDING ANY INFORMATION THAT CAN BE ACCESSED THROUGH THE
WORK VIA HYPERLINK OR OTHERWISE, AND EXPRESSLY DISCLAIM ANY WARRANTY, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS
FOR A PARTICULAR PURPOSE. McGraw-Hill and its licensors do not warrant or guarantee that the functions
contained in the work will meet your requirements or that its operation will be uninterrupted or error free. Neither
McGraw-Hill nor its licensors shall be liable to you or anyone else for any inaccuracy, error or omission, regardless of
cause, in the work or for any damages resulting therefrom. McGraw-Hill has no responsibility for the content of any
information accessed through the work. Under no circumstances shall McGraw-Hill and/or its licensors be liable for any
indirect, incidental, special, punitive, consequential or similar damages that result from the use of or inability to use the
work, even if any of them has been advised of the possibility of such damages. This limitation of liability shall apply to
any claim or cause whatsoever whether such claim or cause arises in contract, tort or otherwise.
Contents
Preface............................................................................................ xvii
1 Basics................................................................................................... 1
1.9.3 For-Next.................................................................................................................. 21
1.9.4 Do-While................................................................................................................. 21
1.9.5 Do Until................................................................................................................... 22
1.10 Anchor Objects of CATScript................................................................................................ 23
1.10.1 CATIA-Application.................................................................................................. 23
1.10.2 CATIA Documents “CATPart” and “CATProduct”................................................. 24
1.10.3 Geometry Containers in CATParts........................................................................ 25
1.10.4 Structural Information and Metadata................................................................... 26
1.11 Using the Macro Recorder................................................................................................... 28
3 Components of CATParts................................................................. 53
3.1 Attributes............................................................................................................................. 53
3.1.1 Standard Attributes................................................................................................ 54
3.1.2 Custom Attributes.................................................................................................. 54
3.2 Origin Elements................................................................................................................... 55
4 Components of CATProducts.......................................................... 77
4.1 Attributes............................................................................................................................. 77
5 2D Wireframe Geometry................................................................... 83
6.2 Points................................................................................................................................... 93
6.2.1 Methods for Creating Points.................................................................................. 93
6.2.2 Case Studies: Points................................................................................................ 95
6.3 Lines.................................................................................................................................... 96
6.3.1 Methods for Creating Lines.................................................................................... 97
6.3.2 Case Studies: Lines.................................................................................................. 99
6.4 Planes................................................................................................................................ 101
6.4.1 Methods for Creating Planes................................................................................ 101
6.4.2 Case Studies: Planes.............................................................................................. 102
6.5 Curves............................................................................................................................... 104
6.5.1 Methods for Creating Curves............................................................................... 106
6.5.2 Case Studies: Curves............................................................................................. 109
6.6 Surfaces............................................................................................................................ 111
6.6.1 Methods for Creating Surfaces............................................................................. 112
6.6.2 Case Studies: Surfaces.......................................................................................... 113
6.7 Transformations................................................................................................................. 115
6.7.1 Methods for Creating Transformations.............................................................. 116
6.7.2 Case Studies: Transformations............................................................................ 117
6.8 Operations......................................................................................................................... 118
6.8.1 Methods for Creating Operations........................................................................ 119
6.8.2 Case Studies: Operations...................................................................................... 121
7 Solids................................................................................................ 123
Index............................................................................................................ 521
This book is organized into sections, from the requirements of a beginner to that of an
advanced user. The following topics will be covered:
� Basics � 3D Wireframe Geometry and Surfaces
� Communication with the Environment � Solids
� Components of CATParts � Featured Object Classes
� Components of CATProducts � Featured VBScript Commands
� 2D Wireframe Geometry
The chapter “Basics” gives an introduction to how V5 macros are created. It contains
the fundamental knowledge that is required for macro programming. It shows how macros
are created, stored, and executed as well as interactions with the user for input and
output.
The chapter “Communication with the Environment” is based on practical examples
of how V5 macros can communicate with the system environment or the user. Through
clear descriptions, it is also possible for a beginner to develop their macros involving a
user.
The chapters “Components of CATParts” and “Components of CATProducts” exp-
lain how to create a macro and the requirements for creating geometry. This is the foun-
dation of all Bodies, Geometrical Sets, and Product Structures.
The chapters “2D Wireframe Geometry,” “3D Wireframe Geometry and Surfaces,”
and “Solids” provide the foundation of how geometry can be created by a V5 macro.
Numerous case studies illustrate these important concepts and best practices.
If readers have worked through the previous chapters and case studies, the last two chapters
“Featured Object Classes” and “Featured VBScript Commands” allow them to solve
their own practical tasks.
The theory of this book is supported in many places with sample macros. Many of the
examples are available online at www.mhprofessional.com/catiav5 for download. Examp-
les that can be downloaded from the Internet are identified by a yellow round stamp with
“WWW” inside.
The contents of this book are based on the software version “V5R19.” It is important to
note that with each release, Dassault Systémes adds more methods of programming, but
existing methods are only very rarely changed. This book can be used with higher software
versions.
This chapter will introduce users to programming macros in CATIA V5 with Visual Basic
Script (VBScript). The following topics are covered:
Basic concepts of VBScript
General structure of a macro
Icons and storage of a macro
Macro editor
Macro recorder
CATScript and CATVBS are both VBScript programming languages. Both macro languages
work with objects and methods. An object is a container that stores information. This
information could be a CATPart, a line, or a surface. A method is an instruction from
which an object is created or modified, or from which information is read.
CATVBS is a type of Microsoft VBScript (MS VBScript) that is extended to objects and
methods of CATIA V5. Up to V5R7, CATVBS only ran on Windows machines. From V5R8
on, Dassault Systémes have expanded their programming so that CATVBS also operates
on UNIX workstations.
CATScript is a variant of MS VBScript that is designed to run on UNIX and Windows.
CATScript was able to run on both platforms prior to V5R8.
CATScript and CATVBS are interpreter languages that serve as the foundation for pro-
gramming macros in CATIA V5. Macros that are written in CATScript or CATVBS can be
used on Windows 7, Vista, XP, NT, 98 and 2000, and UNIX operating systems.
Programming CATIA macros with Visual Basic for Applications (CATVBA) offers more
capabilities for CATIA V5. CATVBA has a compiler and provides many tools for designing
user interfaces. These two points distinguish it from CATScript and CATVBS. An over-
view of all three languages is shown in Table 1.1.
The program syntaxes of CATScript, CATVBS, and CATVBA are very similar. By making
slight changes, program components are very easily transferred from one platform to
another, as long as other methods and objects in that platform are available. In most
cases, the three languages differ only in the way that variables, functions, and procedures
are defined. An overview of these differences is illustrated with a small sample program in
Table 1.2. The differences are highlighted in bold.
Since CATScript through its history has the closest connection with CATIA V5, all pro-
gramming examples and source code in this book are based on CATScript. Through the
differences shown in Table 1.2, the examples can very easily be transferred into CATVBS.
Nomenclature explains the definition of terms used in the following sections. This book
outlines how instructions are used by CATScript. An instruction may be:
A general description
An example of the source code in a macro
A general description provides all the capabilities of the commands in an instruction. One Word
example describes a string that is used in a specific application.
An instruction is usually composed of several words. A word is the smallest unit of an
instruction. Two words are separated, depending on the application, by a period, a comma,
or a space. Important words in a general description and in examples are highlighted in
bold.
A curly brace encloses optional words that do not need to be written. A programmer can {Optional word}
determine the number of words that are shown by a comma and three periods.
An Object is a container that stores information. Each object is assigned a class. A Class
is a description of the information structure of objects of the same object type. Within a
class’s properties and methods, each object has a class.
A Property is a characteristic of an object. A property is usually being read or changed
through the value of its parameter. Some properties can only be read but not changed. In
this case the property is referred to as having “read only” access.
A Method is an instruction used to modify an existing object or create a new one. A
method can have multiple input parameters and output parameters. An output parameter
is the result of applying a method. If a method has an output parameter, then it is called
either a function (Func) or a subroutine (Sub).
placed, the more specialized are its objects. An object can access all properties and
methods of its class and the parent classes. This dependency describes the object path
of an object. An Object Path is the explanation of the dependencies of an object from
its class and parent classes. In the case of an object path, classes are separated by peri-
ods, and child classes are written to the right:
Class hierarchy 0.Class hierarchy 1. ... .Class hierarchy n
An object of the “Pad” class can use the properties and methods of the “Solid,” “Contour-
based Solid,” and “Pad” classes but not the “Pocket” class. The hierarchy is illustrated in
Table 1.3.
A complete object path begins with a root class. A Root Class is the class that stands on
the top hierarchy level and from which all other classes and objects are derived.
The root class of all objects in CATScript is the CATBaseDispatch class (Section 8.12).
CATBaseDispatch has no properties or methods. From CATBaseDispatch, the two
subordinate base classes are derived from AnyObject for individual objects and
Collection for list objects (Table 1.4). In the case of an object’s path, the root class
CATBaseDispatch is typically not written but started directly with a base class.
CATBaseDispatch
AnyObject Collection
(Individual Objects) (List Objects)
An Individual Object is a container for geometry or other information. Each object path
of an individual object begins with the base class AnyObject (Section 8.4). AnyObject
provides basic methods for each individual object.
A List Object is a collection of individual objects. Each object path of list objects begins
with the base class Collection (Section 8.17). Collection provides basic methods for
each list object.
For a practical understanding of the sections below, the foundational theory of program-
ming is started with a basic example. In the “GreetingMacro.CATScript” macro, a user is
greeted with the text “Hello.” In order to prepare the input of the macro, follow these
steps:
Start CATIA V5
Create new CATPart via “File/New”
Select “Tools/Macro/Macros” (or press ALT+F8) from the menu bar
The “Macros” window (Figure 1.1) shows all the macros that are available for immediate
execution. The window is fully explained in Section 1.6. Initially the list is empty.
FIGURE 1.1
Macros window
A macro can be edited using the internal V5-Editor. The V5-Editor is a simple text entry
tool, comparable to “Notepad” in Windows.
Select the “Edit…” button
All commands between or above these two lines are run each time a macro is called. To
complete the macro, the word “Hello” is added to a command, generating a dialog box. The
commands for input and output on the screen are explained in detail in Section 2.1.
Sub CATMain ()
MsgBox (“Hello!”)
End Sub
A macro can be saved by selecting the disk icon of the V5-Editor. The macro “Greeting-
Macro.CATScript” is stored, in this case, in the current document “Part1.CATPart”
(Figure 1.3). The V5-Editor will close, and the macro can be run.
This will start the macro. During the execution, a review of the program logic and syntax
will be made. Since it is an interpreted language, the macro is executed line by line. If the
interpreter finds an error, the macro is canceled during the run. If the source code of the
macro is correct, the greeting “Hello!” will be seen on the screen (Figure 1.5).
With this basic example, all steps are shown that are necessary for the entry and execu-
FIGURE 1.5 Output tion of a macro. The following sections show how to edit, load, save, and run a macro.
of the macro
“GreetingMacro.
CATScript”
In the previous section, the Internal V5-Editor was used. The internal V5-Editor is a very
simple text editor, which is granted as the default editor in CATIA V5. It is utilized automa-
tically when a macro is being processed. An overview of the functionality is provided in
Table 1.5.
Button Description
New File Closes a current file and opens a blank macro-document.
Go to Line Asks for a line number and jumps to the appropriate line.
It is possible to choose a different editor to edit a macro. During the execution of a CATIA
V5 macro, the editor will start automatically and is defined by the options in V5. The
options window is found under “Tools/Options/General/Macros” (Figure 1.6).
For smaller macros, the internal V5-Editor is quite sufficient. However, for intensive macro
work, it can be convenient to have a more powerful editor. Select the “Change editor”
button to choose a different editor. The “Default editor” button resets the editor option
back to the original state, as shown in Figure 1.6.
In the first case, a macro is stored inside of a CATIA document. Thus, a macro and a CATIA
document are closely linked. A CATIA document is a part, product, or a drawing. It can
contain multiple macros.
In the second case, a macro is stored inside a folder with the file type “*.CATScript” and
can be used independently of a CATIA document.
In the “Macros” window and from the “Current macro library or document:” drop-down
(Figure 1.7), select a CATIA document. A macro that is created via the “Create…” button
is stored in this document. A list of “Available macros” in the “Macros” window shows all
the macros that are stored in the selected document. The “Run” button starts the selected
macro.
FIGURE 1.7
“Macros” window and
available macros in a
CATIA document
If a macro is stored in a separate file, you should define a macro library before you create
the macro. A Macro Library is a directory where macros are stored, and CATIA is direc-
ted to their location. By using a macro library, a user receives quick access to all of the
macros within the selected directory.
A macro library is created in the “Macro libraries” window (Figure 1.8). It appears by
clicking the “Macro libraries” button in the “Macros” window. If programmed with
CATScript as the library type, it is seen in the “Directories” drop-down. The other types are
based on programming with VBA (see Section 1.1). The list in the “Current libraries:” field
displays all currently defined macro libraries of one library type. To add a new directory to
the list, select the “Create new library…” button.
In the “Macros” window, a macro library can be selected from the “Current macro library
or document:” drop-down (Figure 1.9). The list of “Available macros:” shows all macros in
a macro library.
FIGURE 1.9
“Macros” window
with a macro in the
macro library
“C:\Temp”
To create a new macro and add it to a macro library, select the “Create…” button. This
opens the “Create a new macro” window (Figure 1.10), which defines a new macro. Select
“OK” to store the macro in the current macro library.
FIGURE 1.10
“Create a new
macro” window
To run a macro from a separate file, open the “Macros” window, choose the appropriate
macro from the list, and select “Run.”
When using macros extensively, it can be repetitive to always open the “Macros” window
and select the appropriate macro library and macro. A shorter way is to run a macro from
a button.
A macro that is stored in a separate file (see Section 1.6.2) can be assigned to a button.
A button can be added to a toolbar and displayed on the user interface of CATIA. A toolbar
is a group of icons that is defined by a user via the command “View/Toolbars.” Toolbars
can be shown or hidden.
FIGURE 1.11
Customize window
with “Commands”
current macros list
Select “Tools/Customize” from the menu bar and then move over to the “Commands”
tab. In the “Categories” column, scroll down and select “Macros.” In the “Commands”
column on the right, a list of all macros in the currently selected library will be dis-
played (Figure 1.11). If no macros are visible, review the selected macro library (see
Section 1.6.2). An icon can be assigned to a macro button by highlighting the desired
macro in the “Commands” list and selecting the “Show Properties” button. Pick an icon
from the “Icon Browser” button, or navigate to an icon through the button folder. Selec-
ting an icon automatically assigns it to the macro button. Selecting “Reset…” returns
the macro’s button icon to the original state.
FIGURE 1.12
Customize window
“Toolbars” tab
A work environment is a workbench (e.g. “Part Design,” for the modeling of solids).
A workbench is the workspace that is active in the CATIA session. By assigning a toolbar
to a workbench, the toolbar is available and can be controlled by users.
The list of all toolbars in the current work environment is located in the “Toolbars” tab of
the “Customize” window (Figure 1.12). The window will open with the command “Tools/
Customize.”
By selecting “New,” a new toolbar is created in the current workbench and the “New Toolbar”
window opens (Figure 1.13). This is a toolbar, which can be given a descriptive name.
The “OK” button closes the window, and the new toolbar is added to the “Toolbars” tab of the
“Customize” window (Figure 1.14).
Assigning a button to a toolbar is controlled through the “Customize” window with the
“Toolbars” tab. In the “Toolbars” tab, select a toolbar and then add a button by selecting
the “Add commands…” button (Figure 1.14).
FIGURE 1.14
“Customize” window,
Toolbars tab with
user-defined toolbar
“My Macros”
This will open the “Commands list” window, and then the
desired command can be assigned (Figure 1.15). The macros
of the current macro library are listed in the “Commands
list.” Click “OK” to add the macro button to the toolbar and
complete the process.
FIGURE 1.15
“Commands list”
window
A Block is a group of instructions in the source code of a macro. Together they include
organizational or logical commands. The source code of a macro is usually composed of
the following blocks:
1. Head of a macro
2. Declaration of global variables and objects
The head of a macro contains descriptive information about the name, author, and func-
tion of the macro as well as important information for the maintenance of the code. This
information typically includes:
Macro name
Version description
Macro language
Brief description of what the macro does
Author and date of creation
Details of a revision (date, person modifying the code, change description)
This information is stored in comment lines. A comment line begins with a single quote
and is ignored when a macro is executed (see Section 9.58).
‘ This is the comment
You may need to tell a user what version of a macro is currently being used. In order for this
information to be understood it is recommended not to open a macro’s source code, but
instead complement the head of a macro with one line of code that displays this informa-
tion. This can be done with the StatusBar property of the Application class (Section 8.5).
An object of the Application class directly represents CATIA (Section 1.10.1).
APPLICATION.StatusBar As CATBSTR
FIGURE 1.16
Example of “Head of
a Macro”
Global variables and objects are declared in the next block. A global variable or object is an
element that is available in all functions and subroutines of a macro.
The declaration of a single variable or an object is done via the Dim statement Dim ()
(Section 9.19). A variable or object can be single- or multi-dimensional.
Dim [Variable1] {, [Variable2]} {As Variable Type}
Dim [Object1] {, [Object2]} {As Class}
Dim [Variable Field] ({Dimension}) {As Variable Type}
Dim [Object Field] ({Dimension}) {As Class}
The head of the macro and global declarations are followed by the macro block “CATMain,”
which contains subroutines and/or functions. CATMain and the following subroutines
and functions can include global and local variables and objects. A local variable or local
object is only valid within its respective range and is similar to a function or subroutine
that declares a global variable or a global object (Section 1.8.2).
1.8.3.1 CATMain
“CATMain” is the main block of a macro from which instructions are run each time the
macro is executed:
... Head of the macro ...
... Declaration of global variables and objects ...
Sub CATMain ()
... Declaration of local variables and objects ...
Instruction 1
Instruction 2
...
End Sub
Within “CATMain” you should place just a few critical lines of code in a macro and then access
additional code by calling subroutines (Sub) and/or functions (Function). This way the source
code is easier to read. A subroutine or function can be called multiple times by CATMain.
Calls to other subroutines and functions are possible within a subroutine or function.
1.8.3.2 Subroutines
A subroutine is a sequence of instructions that performs an action. A call is made via the
name of the subroutine followed by an optional parameter list:
Subroutine {[Parameter], ...}
Declaring a subroutine is performed between the Sub and End Sub statements:
Sub Subroutine {([Parameter] As Variable Type, ...)}
... Declaration of local variables and objects ...
Instruction 1
Instruction 2
...
End Sub
1.8.3.3 Functions
Declaring a function is performed between the Function and End Function statements:
Function Function {([Parameters] As Variable Type, ...)} As Variable Type
... Declaration of local variables and objects ...
Instruction 1
Instruction 2
...
[Function] = [Value]
End Function
The return value is assigned to the variable with the function name.
A branch is a control that determines the basis of testing a criterion from which instruc-
tion blocks are run in a macro. A branch is defined by the statement “If-Then-Else” or
“Select-Case-Else.”
A loop is a series of instructions that are executed repeatedly. In CATScript there are
three types of loops, which are defined by the statements “For-Next,” “Do While,” and
“Do-Until.”
1.9.1 If-Then-Else
“If-Then-Else” describes a branch that separates two instruction blocks. A branch needs a
criterion to decide whether the first or the second instruction block is executed. If the
criterion of a branch is met, the instruction block is executed after the “Then” statement.
If the test criterion is not met, the instruction is executed according to the “Else” state-
ment. The “Else” statement is optional and can be omitted. The general syntax of the
statement “If-Then-Else” is:
If test criterion Then
Instruction 1
{Instruction 2
...
Else
Instruction 1
Instruction 2
...}
End If}
The instruction that follows is the “Then” statement next an “End If” statement, and the
“Else” statement is optional. “End If” marks the end of the “If-Then-Else” statement.
c)
If Not ((A = 1) And (B = 1)) Then
C = 1
Else
C = A * B
D = A - B
End If
Several criteria can be linked by the words “And” and “Or” to other complex criteria. The
“And” statement specifies that both test criteria must be met. The “Or” statement speci-
fies that one criterion must be met by either instruction. The word “Not” negates a crite-
rion. Multiple criteria can also be nested in brackets. Examples are given in Table 1.6.
1.9.2 Select-Case-Else
1.9.3 For-Next
“For-Next” describes a loop that is controlled by a counter. The counter has an initial and
a final value. The counter begins with an initial value, which is incremented by a fixed step
size value toward a final value. If no increment is defined, the step size value is equal to 1.
“Next” indicates the end of the loop. The general syntax for a “For-Next” loop is:
For [Counter] = [Initial Value] To [Final Value] {Step [Increment]}
Instruction 1
{Instruction 2
...}
Next
The “Exit For” statement terminates the loop. With this statement the macro moves to
the next statement after the line “Next.” To keep the code organized, this statement
should be rarely used.
1.9.4 Do-While
“Do-While” describes a loop with an input criterion that runs as long as the test criterion
of the loop is met. The test criterion is checked at the beginning of the loop and before
each new run. Test criteria that have not fulfilled the instructions of the loop is skipped.
The “Loop” statement marks the end of the loop. The general syntax of “Do-While” is:
Do While input criterion
Instruction 1
{Instruction 2
...}
Loop
The “Exit Do” statement terminates the loop. With this statement the macro moves to the
next statement after the line “Loop.”
Sub CATMain ()
Dim I, Sum As Integer
Sum = 0
I = 1
Do While Sum <100
Sum = Sum + I
I = I + 1
Loop
MsgBox(Sum)
End Sub
1.9.5 Do Until
“Do Until” describes a loop with an initial criterion that runs until the test criterion is
met. The criterion is checked after each iteration of the loop and the loop is executed at
least once. “Loop” marks the end of the loop. The general syntax of “Do Until” is:
Do
Instruction 1
{Instruction 2
...}
Loop Until initial criterion
The “Exit Do” statement terminates the loop. With this statement the macro moves to the
next statement after the line “Loop.”
An Anchor Object is an object that is required in every macro to access the elements of
CATIA. There are four major anchor objects in CATScript when solid, wireframe, surfaces,
and product structures are created:
The CATIA application itself
A CATIA document, “CATPart,” or “CATProduct”
The container of the geometric elements of CATParts
The container for structural information and metadata of CATProducts or CATParts
1.10.1 CATIA-Application
The main anchor object is an object of the Application class (Section 8.5) that represents
the application CATIA V5. The CATIA V5 application is described with the CATIA label.
All objects are derived through this anchor object’s properties and methods. A CATIA
document and the provided communication services with an operating system are shown
in Figure 1.17.
A list of all CATIA V5 application windows are shown with the Windows property of
the anchor object (Figure 1.17, top right). The current window is accessed by the
ActiveWindow property.
APPLICATION.Windows As Windows (Read Only)
APPLICATION.ActiveWindow As Window (Read Only)
A list of all open CATIA documents in the CATIA V5 application are shown with the
Documents property (Figure 1.17, top left). The current CATIA document is accessed by
the ActiveDocument property.
APPLICATION.Documents As Documents (Read Only)
APPLICATION.ActiveDocument As Document (Read Only)
FIGURE 1.17
Content of the anchor
object in the
“Application” class
(Source: Online
Documentation of
Dassault Systémes)
A CATIA document is all of the data stored in one file type, whether it is a “CATPart,”
“CATDrawing,” or “CATProduct.” The parent class of all CATIA documents is the
Document class (Section 8.25). For each document type of CATIA V5, there is a
specialized class whose parent class is the Document class. For a CATPart, this is the
PartDocument class (Section 8.16.9); for a CATProduct, this is the Product-
Document class (Section 8.17.7).
If the ActiveDocument property of the Application class is declared, which is an
object of a current CATIA document (Section 1.10.1), the correct class of the docu-
ment is automatically determined. For example, if a CATIA document is a CATPart, the
ActiveDocument is automatically a PartDocument. Additional information on how
to create, load, and store a CATIA document is in Section 2.2.
The geometry of a CATPart is an object of the Part class (Section 8.168) and is assigned
to the third anchor object. The anchor object is derived using the Part property of the
PartDocument class.
PARTDOCUMENT.Part As Part (Read Only)
All other objects are derived from the geometric content of a CATPart through the
methods and properties of the third anchor object (Figure 1.18).
The origin planes and axis systems used in CATParts are accessed by the OriginElements
and AxisSystems properties (Figure 1.18, top left).
Bodies can be accessed through the Bodies properties and Geometrical Sets through
HybridBodies and OrderedGeometricalSets properties (Figure 1.18, bottom left and
top right).
Constraints, relations, and parameters (Figure 1.18 right, center) are accessed through
the Constraints, Relations, and Parameters properties.
Toolboxes are used in CATScript to create geometry. A toolbox is a class that provides
methods to create geometry. The set of all toolboxes are summarized in the Factory
class. The ShapeFactory property represents a toolbox for solid shapes, and the
HybridShapeFactory property represents a toolbox for wireframe geometry and
surfaces (Figure 1.18, bottom right).
The properties outlined in this section are explained in further detail in Chapters 3 to 7.
FIGURE 1.18
Content of an anchor
object in the
“PartDocument” and
“Part” classes
(Source: Online
Documentation of
Dassault Systémes)
The structural information of CATProducts is the list of all elements inside of a CATPro-
duct. The metadata of CATParts or CATProducts are general attributes such as the Trans-
formation Matrix, Part Number, or Version. The structural information and metadata of
CATProducts or CATParts are stored in an object of the Product class (Section 8.176). An
object of the class can be derived via the Product property of the PartDocument class
(Section 8.169) and ProductDocument class (Section 8.177).
PARTDOCUMENT.Product As Product (Read Only)
PRODUCTDOCUMENT.Product As Product (Read Only)
Through the methods and properties of this fourth anchor object, all other objects that
represent the attributes and product structures are defined (Figure 1.19).
FIGURE 1.19
Content of the anchor
object in the
“Product” class
(Source: Online Docu-
mentation of Dassault
Systémes)
The product structure of CATProducts is stored in a Products list object. This list object
stores the Product elements that are used in a CATProduct.
The parameters, formulas, constraints, and publications of CATProducts are stored in the
Parameters, Relations, Constraints, FixTogethers, and Publications list objects.
Other Product object properties describe the transformation matrix, which controls the
positioning of a CATParts or CATProducts within an assembly.
Metadata (e.g. Part Number, Version) of CATProducts or CATParts can be accessed
through the Part Number, Revision, Definition, Nomenclature, Source, and
DescriptionRef properties, shown in Figure 1.19.
The properties outlined in this section are explained in further detail in Chapters 3 to 7.
CATIA V5 has a macro recorder that records the individual steps of a user and converts
these steps into source code. This recording may not always be complete and typically
does not meet the requirements for organized programming. However, it does record
valuable insight for objects and methods.
FIGURE 1.20
Starting the
macro recorder
The macro recorder will start from the “Tools/Macro/Start Recording…” menu
(Figure 1.20).
The macro recorder opens the “Record Macro” dialog box. Here the macro language, loca-
tion, and name of the macro are defined. Select the “Start” button to begin recording
(Figure 1.21).
FIGURE 1.21
“Record macro”
dialog box
CATIA now records and converts the actions that a user performs. A recording ends with
the selection of the “Stop” button (Figure 1.22). The button is only shown during a recor-
ding and is displayed automatically.
FIGURE 1.22
Stop recording button
With the basics of this book, a user will quickly be able to write their own macros. If the
scope of any macro is outside of creating wireframe, surfaces, and solids, the following
sources provide additional information:
“Programming Interface” in the online documentation of CATIA V5 for Classes, Objects,
Properties, and Methods (Figure 1.23)
www.microsoft.com for commands in VBScript
FIGURE 1.23
Full-text search
of the Online
Documentation