Programming Guide
Programming Guide
CATIA Version 5
Programmer’s Guide
ii Scripting with CATIA Programmer’s Guide
®
Special Notices ©
Any of the following terms may be used in this publication. These terms are trademarks of
the International Business Machines Corporation:
AIX IBM
DB2 RISC System/6000
DB2/6000 SAA
FORTRAN/2 SQL/DS
GDDM
Any of the following terms may be used in this publication. These terms are trademarks of
the Hewlett-Packard Company:
HP HP/GL-2
HP/GL HP-UX
HP VUE HP Vectra XW
HP 9000 Series 700 SAM
Any of the following terms may be used in this publication. These terms are trademarks of
the Silicon Graphics, Inc.:
Indigo2 Onyx2
IRIX OpenGL
O2 Silicon Graphics
Octane
Any of the following terms may be used in this publication. These terms are trademarks of
the Sun Microsystems Computer Company:
HotJava Ultra1
Java Ultra2
Solaris 2.5 Ultra30
Any of the following terms may be used in this publication. These terms are trademarks of
the Microsoft Corporation:
ActiveX OLE
Excel PowerPoint
Internet Explorer VBScript for Windows NT
JScript Visual Basic
Microsoft Windows NT
Office 97 Word
Any of the following terms may be used in this publication. These terms are trademarks of
other companies or institutions:
Acrobat Reader Adobe Systems Inc.
BasicScript Summit Software Corporation
CADAM Dassault Systemes of America Corp.
Digital Personal Workstation 266i Digital Equipment Corporation
InstallShield InstallShield Software Corporation
JavaScript Netscape Communications Corporation
Netscape Navigator Netscape Communications Corporation
PostScript Adobe Systems Inc.
PROFESSIONAL CADAM Dassault Systemes of America Corp.
PDF Adobe Systems Inc.
TIFF Aldus Corporation
UNIX UNIX System Laboratories, Inc.
Versatec Versatec, Inc.
All other company names and product names mentioned are the property of their
respective owners.
v
About Inheritance and Aggregation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .35
Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .46
Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .47
Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .48
Cameras . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .51
Sketch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .74
Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .76
Shapes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .77
Repartition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .88
Limit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .89
Relations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .91
Contents vii
Creating a Formula . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .96
Updating All the Sheets of all the Drawings Contained in a Folder . . . . . . . . .140
Printing All the Sheets of all the Drawings Contained in a Folder . . . . . . . . . .142
Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .147
Contents ix
x Scripting with CATIA Programmer’s Guide
About This Book
This book describes the CATIA exposed objects and how to use them to write macros you can run
to automate your job.
It describes for each product the exposed object architecture and the main properties and methods
of these objects, how they relate, and how to use them. Basic tasks and advanced scenarios are
given as examples you can copy and customize to match your own needs.
Reference material is also provided, and each object, property, and method used in the object archi-
tecture or in the tasks and scenarios points to its reference information.
xi
Preface
The object diagrams included in this book follow the UML (Unified Modeling Language) Notation
from Rational Software Corporation, and uses additional graphic conventions fully described in
Object Architecture Overview.
Drag
Drag and drop
Move
indicates tips.
indicates a warning.
indicates information.
The products that make up CATIA share the same object model which can be accessed, as well as
their own objects, by scripts written in Visual Basic with Windows NT, and scripts written in Basic
Script for UNIX.
You can write your scripts from scratch, but you can also use the journalling facility from the
Tools->Macro command that records end-user scenarios in scripts you can then use as is or mod-
ify.
We put here a simple script example, to show what is scripting with CATIA, which are the different
things to do to script, present briefly the scripting environment and dialog window, and what is jour-
nalling. This example is divided into the following parts:
• Recording the scenario
• Modifying the generated macro
• Replaying the macro
You will then find information about the scripting languages and environments, and some keys for
you if you are not familiar with writing macros in Invoking CATIA from a Scripting Language.
15
1
A Script Sample
This sample illustrates how to use scripting to automate a very simple, but repetitive user task.
We’ll first record the creation of a cylindric pad. Then we’ll modify the generated macro to create
five similar pads. Finally we’ll replay the modified macro.
This scenario creates a circle in a sketch, and uses this sketch to create a cylindric pad.
4. Click File->New, or click on the icon, and double-click Part to create a new part. A new
part is created and a window for this part is opened.
17
1
5. Select the
xy plane
in the
specifica-
tion tree,
and
select the
sketcher
icon
to create
a sketch.
6. In the
sketcher
toolbar,
select the
circle
icon
and click
twice to
indicate
succes-
sively the
center of
the circle
and a
current
point on
the circle.
Language=”VBSCRIPT”
19
1
Sketch3.CloseEdition
PartDocument0.Part.Update
We’ll detail below, line by line, what has been recorded, following the interactive steps:
1. You first put in place the recording environment by selecting the Tools->Macro->Start
Recording command, then giving a name to the macro in the Record Macro dialog box, and
clicking Start. This opens the macro file and generates the first instruction stating the scripting
language used:
Language=”VBSCRIPT”
2. Click File->New, or click on the icon, and double-click Part to create a new part. This
generates the following instructions:
A new document with the Part type is created. To do this, such a document is added to the Doc-
uments collection of the CATIA application. The PartBody of the created part is retrieved from
the Bodies collection in the part document and put in the variable Body1 for future use.
3. Select the xy plane in the specification tree:
A sketch named Sketch3 is added to the Sketches collection using this Plane2 plane. A
Factory2D is created by opening the sketch editor against the created sketch. This Factory2D
includes methods to create 2D objects.
5. In the sketcher toolbar, select the circle icon and click twice to indicate successively the
center of the circle and a current point on the circle
CATIASketch3.CloseEdition
7. Select the pad icon to create a pad, and in the Pad Definition dialog box, choose a length of
10 mm and click OK. The pad is created.
PartDocument0.Part.Update
The AddNewPad method of the ShapeFactory is used to create the pad. It is created using the
sketch and the length of 10mm. The part is updated.
8. Click Stop Recording in the Stop Recording dialog box, or select Tools->Macro->Stop
Recording.
This closes the macro recording sequence and saves the macro in the selected file.
21
1
This task explains how to modify the generated macro to make it loop on the creation of five
identical cylindric pads.
4. Click Edit. Your favorite editor opens on the selected macro. The instructions written using
the bold typeface are those you need to add or modify while the others already exist in the
macro:
Language=”VBSCRIPT”
‘My macro creates five cylinders
x = 0
For I = 1 To 5
Sketch3.CloseEdition
PartDocument0.Part.Update
CATIA.ActiveWindow.ActiveViewer.Reframe
x = x + 25
Next
The second line of the macro begins with a single quote and is a comment which will be dis-
played in the Description area of the Macro dialog box. Then you simply need to initialize a
variable, here x, to allow for the circle center to vary, and create a loop beginning with the
For keyword and ending with the Next keyword. The For keyword specifies the counter
variable I which will take all values between 1 and 5 inclusively. Replace the first coordinate
of the center by x in the CreateClosedCircle method and in the CreatePoint method, and add
a Reframe method to display the whole scene at each step. Then increment the x value to
move the next center of 25mm from the previous one.
23
1
2. Your
macro
should be
the cur-
rent one.
You just
have to
click on
Run to
run this
macro.
Here is
the result.
25
1
CATIA is an OLE Automation server for Windows NT and allows macro record and replay for both
Windows NT and UNIX. The following summarizes CATIA scripting capabilities.
• With Windows NT:
• In-process access using Visual Basic Scripting Edition since CATIA hosts the Visual Basic
scripting engine
• Out-process access from Visual Basic for Applications via applications like those of Office
• Out-process access from Visual Basic 5 Development Studio
• Out-process access using the Windows Scripting Host and scripting languages such as VB
Script or JScript
• Out-process access from a html page
• Out-process access from a COM application accessing CATIA interfaces through the
Invoke method.
• With UNIX: in-process access using Summit’s Basic Script
The macros recorded from the Tools menu and the Record Macro dialog box use the Visual Basic
language, and not VBScript, to be compatible with Basic Script, allowing macro portability
between UNIX and Windows NT, that is a macro recorded on Windows NT can be replayed on
UNIX or the reverse. This means for example that Dim statements are recorded to declare objects
as returned values of properties or methods.
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->Mac-
ros 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 pro-
cess. 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
• Running Out-process Macros
27
1
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 Cre-
ateObject or GetObject, as follows:
Dim CATIA
Set CATIA = WScript.CreateObject(“CATIA.Application”)
or
Dim CATIA
Set CATIA = WScript.GetObject(“”, “CATIA.Application”)
• With JScript, your script should also begin by the connection to CATIA, using either Cre-
ateObject or GetObject, as follows:
var CATIA
CATIA = WScript.CreateObject(“CATIA.Application”)
or
var CATIA
CATIA = WScript.GetObject(“”, “CATIA.Application”)
Note that the GetObject method requires that its first argument be blank for both Basic Script and
JScript.
To run the macros from the Windows desktop, simply double click on the macro name. These
names are suffixed using vbs for Visual Basic, and with js for JScript.
To run the macros from the command console, use the cscript command as follows:
cscript e:\users\psr\Scripting\Sample\CATIA.js
29
1
You can also run macros embedded in a html page. These macros can be written in Visual Basic and
JScript. There are several ways of embedding a macro in a html page:
• The macro is written using the script tag and run when the page is loaded
• The macro is written using the script tag and is included or referenced by a form, input, body,
or a (anchor) tag.
• The macro is written using the a tag (anchor) and run as an hyperlink. This is possible with
JScript only.
31
1
Object Diagrams
This section helps to make you familiar with the diagrams used to describe the objects, their main
properties and methods, and their relationships. The diagrams use the Unified Modeling Language
(UML) notation.
Application
some of the Application
Documents object’s properties
Windows
ActiveDocument ellipsis means that some
ActiveWindow properties are not shown
... Application object’s methods
Help() a collection
Quit() an object This red arrow means
an abstract object
that this terminal object is
1 the root object of another
Documents PartDocument diagram
* Document ProductDocument
1
binary association DrawingDocument Collection
association name
Parent
You can learn from the diagram above that the Application object has properties among which four
of them are listed, and exactly two methods. The Application object aggregates two collection
objects, Documents and Windows. The Documents collection aggregates any number of Documents,
since the multiplicity is set to *. The Document object is an abstract object, and only its derived
types can actually be created, that is the PartDocument for Part Design, the ProductDocument for
Assembly Design, and the DrawingDocument for Drafting. The Windows collection aggregates any
number of Windows, which themselves aggregate one Viewers collection which aggregates any
number of Viewers. The binary association between the Window and the Document objects means
that the Document object is the parent of the Window object. Other associations without name are
aggregations.
The symbol shows that the object to which it refers, that is the object located just left of the sym-
bol, is the root of an object structure expanded in another object diagram. The symbol shows
that the root object near it can be found in one or several object diagrams as an object to expand.
A collection is an object that contains other objects. Like with stamps collecting, where all objects
in the collection are stamps, a collection contains usually objects of the same type. For example a
document collection contains documents. A collection is always denoted as a plural name to help
easily recognize a collection among other objects. The document collection is thus named Docu-
ments. A collection is depicted using a yellow box in the object diagrams, such as Documents .
The collection index begins at 1, and not 0. Usually, an object in the collection is reached using its
index, but it can also be reached using the name you assign to it. This ability of referring to an
object using its name in the collection is stated in the documentation of each collection object, such
as Documents, when the index type is Variant, for example in the Item method.
A property is part of an object and helps to characterize it. For example, the Document object has
the FullName property, which stores its full name, that is the file name that contains the document
and the path to access this file. Retrieving property values of an object makes it possible to distin-
guish it among other objects of the same type. Modifying property values of an object changes the
object characteristics and implies that the object itself is thus modified. To prevent from non-
desired property modifications, an object can have read-only properties from which you can
retrieve their values, but never set them.
To retrieve or set the value of a property of a given object, write the object reference followed by a
period and the property name. For example, you can set the DocName variable with the full name
of the active document as follows:
DocName = CATIA.ActiveDocument.FullName
An object reference always starts from the root object, that is the application object which is always
set to CATIA with in-process access. Then you use the Application object’s properties to access the
objects. In this case, the application object has the ActiveDocument property which holds the
active document. You simply need to write CATIA.ActiveDocument to refer to the active doc-
ument. Then the Document object has the FullName property to hold its full name. Simply add a
period followed by FullName, and you get this full name.
In the same way, you can request to see the hidden elements of the active document by setting the
value of its SeeHiddenElements property to True, as follows:
CATIA.ActiveDocument.SeeHiddenElements = True
A method is an action that you can request an object to do. For example, you can request to save the
active document. To do this, the Document object includes the Save method. Simply request the
document to save itself as follows:
CATIA.ActiveDocument.Save
33
1
Methods have often arguments requested by the action. For example, the SaveAs method carries
out the action of saving a document with another name than the current one. This new name must
be provided to perform this action, otherwise the SaveAs method cannot work. This name is
passed as an argument of the SaveAs method. To save the active document with the name
NewName, proceed as follows:
CATIA.ActiveDocument.SaveAs “NewName”
You will find in the object reference that each method is qualified as either a Function or a Sub,
and with parentheses, even if they have no arguments, as follows:
Sub Update()
This is a Visual Basic notation to distinguish a method that returns a value, or Function, from one
that don’t, or Sub. Note that the returned value of a Function is indicated using the As keyword.
In the example above, the NewCamera method is a Function because it returns a Camera
object. See also Some Tips about Sub and Function to know more about Sub and Function.
An object that inherits from another, named the AnyObject object, inherits the properties and the
methods of this AnyObject object and adds them to its own properties and methods. Inheritance
helps to specialize objects while gathering common properties and methods in the AnyObject
object. Inheritance is a iterative process, since an object can inherit from an object which itself
inherits from another object which itself inherits, and so forth, and the lowest object in the inherit-
ance tree inherits the properties and methods of all the objects above it. Inheritance is depicted
using the following symbol or in the object diagrams.
In the following diagram, the PartDocument object is a specialized document that is dedicated to
parts, and which inherits the properties and methods of the Document object. In addition, the Part-
Document object has its own properties and methods. For example, PartDocument inherits the Save
method from Document, like ProductDocument and DrawingDocument, and owns the PartNum-
ber property, which is a specific property for a part, but which does not make sense for Document.
Collection
Application PartDocument Object
1 PartNumber
Documents ...
Abstract Object
* Document ProductDocument
Object To Expand
Save()
... DrawingDocument
Expanded Object
Assume that MyPart is a PartDocument document and is the active document. You can write the
following to set its part number, and then save it:
MyPart.PartNumber = “123456789-0”
MyPart.Save()
In this example, the value of the PartNumber property owned by MyPart as a PartDocument
document is modified, and then the Save method of the Document object is executed against
MyPart.
Some objects are depicted with a blue box with an italic typeface, such as Document . These
are abstract objects. An abstract object owns properties and methods like any other object, but it
cannot be created. Only objects which inherits from it and which are not abstract objects can be cre-
ated. For example, the Document object is an abstract object which owns properties and methods
shared by all documents, but cannot be created as such. Only objects of types PartDocument, Pro-
ductDocument, and DrawingDocument which inherit from it can actually be created. The active doc-
ument referred to in the examples given in About Objects, Collections, Properties, and Methods is
necessarily an instance of one of these three types.
35
1
Aggregation is the ability of an object to contain another one. For example, the Application object
contains (aggregates) a Documents collection object. With CATIA, the aggregation of a series of
objects of the same type is usually reserved to collection objects. For example, the Documents col-
lections contains (aggregates) a series of Documents, each of them being a PartDocument, a Pro-
ductDocument or a DrawingDocument object. Aggregation is depicted using a line between the two
objects, and the number of contained objects (multiplicity). For example, Application contains one
Documents collection, which can itself contain any number of Documents, since the * symbol is
used.
An item is retrieved from the collection using the Item method and the index of the item in the col-
lection. Usually, the argument representing the index in the Item method is a Variant. This means
that it can either represent the rank of the item in the collection or the name you assigned to this
item using the Name property. The rank in a collection begins at 1. For example, assume that the
document named MyDocument is the sixth document in the Documents collection. To retrieve this
document in the Doc variable, write:
or write:
Each collection has a Count property that holds the number of items in the collection. This is a
handy property to scan the whole collection. For example, to print the name of each document in
the collection in a message box, write:
For I = 1 To CATIA.Documents.Count
msgbox CATIA.Documents.Item(I).Name
Next
or write:
I = 0
Do
I = I + 1
msgbox CATIA.Documents.Item(I).Name
Loop Until I = CATIA.Documents.Count
or you can use the For Each instruction to scan the collection, and get rid of the counter:
In this case, the Doc variable is reinitialized using the current document, starting with the first one
and ending with the last one.
37
1
Dim MyVPOrigin
ReDim MyVPOrigin(2)
CATIA.ActiveWindow.ActiveViewer.Viewpoint3D.GetOrigin MyVPOrigin
You should first declare the array using the Dim statement and assign a size to the array using the
ReDim statement, and then call the GetOrigin method. Assigning a size of 2 allocates an array con-
taining three values.
Contrary to collections, a SafeArrayVariant’s index begins at 0. To set a new triplet of values, you
can write:
or
MyVPOrigin(1) = 200
CATIA.ActiveWindow.ActiveViewer.Viewpoint3D.GetOrigin MyVPOrigin
When you don’t know the size of an array, use the UBound property. It returns the rank of the high-
est element in the array. For example the following example returns 2 in Highestrank:
Highestrank = MyVPOrigin.UBound
Be careful when the methods requests arguments. To pass arguments to a Sub with Visual Basic
Script, do not use parentheses as follows:
You must use Dim and Set only if the returned value is an object, but not if it is a character string
or a number. Nevertheless, character string and number defined as CATIA literals are objects and
Set must be used if a Function returns a literal object.
39
1
The parameter values you can set using macros must be expressed using the MKSA unit system,
since the user interface filter does not exist when you run macros. This also ensures your macros
portability. There is one exception: the literals.
Literals are specific objects that represent a parameter with a given type. For example, the Length
object is dedicated to store a length, but its state of object brings more that the simple value storage.
The Length object derives from the Dimension object, and thus inherits from it the Valuate-
FromString method. This method allows the value stored in the Length object to be valuated
using a figure and a unit. For example, valuate the radius of a face fillet using the Radius property
of the FaceFillet object which aggregates a Length object to store this radius:
MyFaceFillet.Radius.ValuateFromString(“5.08mm”)
The character string is interpreted as a value of 5.08 expressed in mm. You can enter a decimal
value since the Dimension object derives from the RealParam object which allows for real values to
be set. You may want to enter inches instead. Simply write:
MyHole.Diameter.ValuateFromString(“2in”)
The available unit symbols you can use are those listed in the Units tab-page of the Tools-
>Options menu. The RealParam and the IntParam objects provide to their derived objects the
Value method which sets or returns the value expressed in the MKSA unit system, except for
length expressed in millimeters and angles expressed in decimal degrees.
2. Select
Tools-
>Cus-
tomize,
then the
Com-
mands
tab, and
Macros.
Drag the
macro
name to
the tool-
bar you
wish. The
default
icon
is used
41
1
3. To select
another
icon than
the
default
one, click
Show
Proper-
ties, and
browse
the cur-
rently
used
icons by
clicking
.
Select the
appropri-
ate icon
and drag
the
macro
name.
by clicking .
43
2
Application Collection
1
Documents PartDocument Object
1 Camera2D
Cameras
1
* Camera Viewpoint2D
Camera3D
1
1 Viewpoint3D
Windows
* Window SpecsAndGeomWindow
1
Viewers Viewer2D SpecsViewer
1
* Viewer Viewpoint2D
Viewer3D
1
Viewpoint3D
1
SystemService
1
LightSources
* LightSource
These objects are shared by all CATIA products. The root object is the Application, which aggre-
gates, or includes, Documents, a Document collection, and Windows, a Window collection. A collec-
tion is an object that gathers objects of the same type and is denoted as a plural name. Documents
gathers Document objects and provides methods for managing individual documents in the collec-
tion.The documents belong to one of the three types, that is the PartDocument, the ProductDocu-
ment, and the DrawingDocument. Windows gathers Window objects, and provides methods for
managing individual windows in the collection.
In addition to this functional view, we can superimpose another view to help understand some basic
mechanisms:
Selection
LightSource
Viewpoint2D
Viewpoint3D
All objects, and not only those shown in this diagram, except collections, derive from the AnyObject
abstract object which supplies the Application, Name, and Parent properties. You can then use
these properties and this method against any object, since any object features them. All collections
derive from the Collection abstract object which supplies in addition the Count property.
The Application property returns the application to which an object belongs. When running in-pro-
cess macros, there is only one application named CATIA. The Name properties allows any object to
be assigned a name. The Parent property allows the parent object to be retrieved, the parent object
being the object which aggregates the current one. The Count property of the Collection object
returns the number of items in the collection. In addition, a Collection object can supply an Item, an
Add, and a Remove method.
45
2
Application
Application Collection
Documents
Windows Object
ActiveDocument
ActiveWindow Abstract Object
...
Help() Object To Expand
Quit()
1 Expanded Object
Documents
1
Windows
1
SystemService
The root object for all CATIA macros is Application. This corresponds to the CATIA frame win-
dow. The CATIA application is always named CATIA for in-process access, and you should only
refer to it since it already exists when you run an in-process macro. The application aggregates, or
includes, a document collection accessed using the Documents property, and a window collection
accessed using the Windows property. The document collection stores the currently opened docu-
ments and the window collection stores the currently opened windows for these documents. The
active document is the document opened in the active window, that is the window in which the end-
user is currently working. They are accessed using the ActiveDocument and the ActiveWindow
properties respectively.
The Application object has other properties, such as FileSearchOrder which allows a pathname
concatenation searched for when opening files to be set or retrieved. As the application represents
the frame window, you can set the frame dimensions and location using the properties Width,
Height, Left and Top respectively, with values expressed in screen pixels.
The Application object aggregates also a SystemService object which provides the Environ method
to get the value of a given environment variable.
Documents
Documents
Collection
Add()
Item() Object
Open() PartDocument
Abstract Object
* Document ProductDocument
Selection Object To Expand
Cameras Drawing
... Expanded Object
Activate()
Close()
NewWindow()
Save()
SaveAs()
1
Selection
1
Cameras
The Document is the object which stores your application data on disk. A document is either created
empty using the File->New command or using the Add method of the Documents collection, or
opened from a file using the File->Open command or using the Open method of the Documents
collection. CATIA provides access to three document types: the PartDocument, the ProductDocu-
ment, and the DrawingDocument. The Document abstract object gathers the properties and methods
common to all actual document types. When a document is created or opened, it is automatically
set as the active document and displayed in a window which automatically becomes the active win-
dow. A document aggregates the current object or set of objects in the Selection object, and Cam-
eras, a camera collection.
47
2
Windows
Windows Collection
Arrange()
Item() Object
The Windows collection gathers Window objects which make the link with the windowing system
and display documents in a viewable form, mainly in 3D or 2D modes, or as a specification tree in
graph or tree mode. Windows in a collection can be arranged in the frame. A Viewers collection
enables the window to display the application data in the appropriate modes using viewers. A Spec-
sAndGeomWindow object features altogether a 2D or a 3D viewer and a specification tree viewer. A
window can be activated, that is becomes the active one, using the Activate method. This implies
that the document displayed is this window is also activated if it was not, and that subsequent inter-
actions will affect it until another window is activated instead. The Viewers property returns the
aggregated Viewers collection, and the ActiveViewer property returns the active viewer in the
window.
1
LightSources
Item()
Add()
Remove()
* LightSource
GetDirection()
PutDirection()
A Viewer is used to display a document according to a given viewpoint and display options.
Depending on the document type, the following viewers can be found in a window:
• PartDocument: a Viewer3D for the part 3D objects and/or a SpecsViewer for the part specifica-
tion tree
• ProductDocument: a Viewer3D for the assembly 3D objects and/or a SpecsViewer for the
assembly specification tree
49
2
• DrawingDocument: a Viewer2D for the drawing sheets and/or a SpecsViewer for the drawing
specification tree.
When the window displays both a Viewer3D and a SpecsViewer, or one or several Viewer2Ds and a
SpecsViewer, it is a SpecsAndGeomWindow. You can activate a given viewer in a multi-viewer win-
dow, fit all the scene in the viewer, update the display, zoom in and out, and capture the contents of
the viewer as an image file.
Display options depend on the viewer type. All viewers share display options such as the back-
ground color and the display on the whole screen or in a smaller window. In addition, Viewer3Ds
allow for different lighting modes and for modifying lighting intensity, and for depth effects, navi-
gation styles, rendering modes, and clipping modes.
A viewpoint holds complementary data for viewers. A Viewpoint2D defines the origin of the scene
to display, expressed in model units, and a zoom factor to apply for display. A Viewpoint3D holds in
addition the sight and up directions, the target, the field of view, and projection modes.
UpDirection
SightDirection
Origin
FieldOfView Target
NearLimit
FocusDistance
FarLimit
Cameras
Expanded Object
Camera3D
Viewpoint3D
1
Viewpoint3D
Zoom
ProjectionMode
FocusDistance
FieldOfView
GetOrigin()
PutOrigin()
GetSightDirection()
PutSightDirection()
GetUpDirection()
PutUpDirection()
A Camera is the persistent form of a viewpoint. You can create a camera from the current viewpoint
using the NewCamera method of the Viewer object. The camera name is assigned by CATIA:
Camera00, Camera01, and so forth, and the created camera is placed at the end of the camera col-
lection of the active document and is displayed in the Named Views dialog box of the View menu.
You can rename the cameras you create with your own names using the Name property. A created
camera can then be assigned to a viewer to make its own viewpoint change to this of the camera.
Two kinds of cameras exist: the Camera2D for 2D viewpoints, that is for DrawingDocument
objects, and the Camera3D for 3D viewpoints representing the real world, that is for PartDocument
and ProductDocument objects. A Camera2D stores a Viewpoint2D object and a Camera3D stores a
Viewpoint3D object.
51
2
The resulting macro can be run in-process only. Refer to Running Out-process Macros to run it
out-process with Windows NT.
This task shows how to create a new document. It is the programming equivalent of the File-
>New command.
To address the application from an in-process macro, use the name CATIA.
Language = “VBScript”
2. Create the new document. To do this, use the Add method of the Documents collection which
creates the document and adds it as the last item of the collection. You must specify its type.
It can be a part, an assembly, or a drawing. Use then Part, Product, or Drawing type
respectively as argument of the Add method.
This single statement creates a new part document that can be further referenced using the
NewDocument variable, adds it to the Documents collection, creates and displays a window
for this document, and makes it the active document and its window the active window.
53
2
Opening a Document
The resulting macro can be run in-process only. Refer to Running Out-process Macros to run it
out-process with Windows NT.
This task shows how to open a document. It is the programming equivalent of the File->Open
command.
To address the application from an in-process macro, use the name CATIA.
Language = “VBScript”
2. Open the document. To do this, use the Open method of the Documents collection which
opens a document given its full pathname and adds it as the last item of the collection.
This single statement opens the document stored in the file whose pathname is e:\Parts\Doc-
umentToOpen.CATPart that can be further referenced using the Doc variable, adds it to the
Documents collection, creates and displays a window for this document, and makes it the
active document and its window the active window.
Closing a Document
The resulting macro can be run in-process only. Refer to Running Out-process Macros to run it
out-process with Windows NT.
This task shows how to close a document. It is the programming equivalent of the File->Close
command.
To address the application from an in-process macro, use the name CATIA.
Language = “VBScript”
2. Close the document. To do this, use the Close method of the Document object. To close a
document, you need to designate it. Use one of the three following ways:
a. The document to be closed is the active one. Use the ActiveDocument property of the
CATIA application
CATIA.ActiveDocument.Close()
b. You already assigned a variable to handle the document. Assume this variable is Doc.
You simply use this variable
Doc.Close()
c. You have assigned a name to the document using the Name property. You can retrieve
this document from the document collection using the Item method with the name you
assigned as argument
CATIA.Documents.Item(“TheNameIAssignedToTheDocument”).Close()
You could also replace the name by the rank of the document in the collection.
Each of these statements closes the designated document. This means that the document is
removed from the Documents collection, and that all the windows that contain it are also
closed and removed from the Windows collection.
If the document has been modified and thus needs to be saved, a prompt is issued before closing and
freezes the macro, requesting a user input to save or not the document. To prevent from this, save the
document beforehand, or test if the document needs to be saved using the Saved property of the Docu-
ment object and save it if appropriate. To close a document even if it needs to be saved without saving
it, set the DisplayFileAlerts property of the Application object to False. This prevents from issuing the
saving prompt. Setting DisplayFileAlerts to False make the macro strictly apply the method, such as
Close closes and doesn’t save, Save overwrites the existing document, and so on.
55
2
This example uses the Close method of the Document object, the ActiveDocument and the
Documents properties of the Application object, and the Item method of the Documents collec-
tion.
Saving a Document
The resulting macro can be run in-process only. Refer to Running Out-process Macros to run it
out-process with Windows NT.
This task shows how to save a document. It is the programming equivalent of the File->Save
command.
To address the application from an in-process macro, use the name CATIA.
Language = “VBScript”
2. Save the document. To do this, use the Save method of the Document object. To save a doc-
ument, you need to designate it. Use one of the three following ways:
a. The document to be saved is the active one. Use the ActiveDocument property of the
CATIA application
CATIA.ActiveDocument.Save()
b. You already assigned a variable to handle the document. Assume this variable is Doc.
You simply use this variable
Doc.Save()
c. You have assigned a name to the document using the Name property. You can retrieve
this document from the document collection using the Item method with the name you
assigned as argument
CATIA.Documents.Item(“TheNameIAssignedToTheDocument”).Save()
You could also replace the name by the rank of the document in the collection.
Each of these statements saves the designated document. If the document was newly created
and was never saved, use the SaveAs method instead. This is detailed in Saving As a Docu-
ment.
This example uses the Save method of the Document object, the ActiveDocument and the
Documents property of the Application object, and the Item method of the Documents collec-
tion.
57
2
Saving As a Document
The resulting macro can be run in-process only. Refer to Running Out-process Macros to run it
out-process with Windows NT.
This task shows how to save the active document with a new name or location. It is the program-
ming equivalent of the File->SaveAs command.
To address the application from an in-process macro, use the name CATIA.
Language = “VBScript”
2. Save the active document with a new name. To do this, use the SaveAs method of the Docu-
ment object. To save a document, you need to designate it. Use one of the three following
ways:
a. The document to be saved is the active one. Use the ActiveDocument property of the
CATIA application
CATIA.ActiveDocument.SaveAs(“e:\Users\Part\NewName.CATPart”)
b. You already assigned a variable to handle the document. Assume this variable is Doc.
You simply use this variable
Doc.SaveAs(“e:\Users\Part\NewName.CATPart”)
c. You have assigned a name to the document using the Name property. You can retrieve
this document from the document collection using the Item method with the name you
assigned as argument
CATIA.Documents.Item(“TheNameIAssignedToTheDocu-
ment”).SaveAs(“e:\Users\Part\NewName.CATPart”)
You could also replace the name by the rank of the document in the collection.
Each of these statements saves the designated document in specified the folder with the
NewName name.
59
2
This example uses the SaveAs method of the Document object, the ActiveDocument and the
Documents property of the Application object, and the Item method of the Documents collec-
tion.
The resulting macro can be run in-process only. Refer to Running Out-process Macros to run it
out-process with Windows NT.
This task shows how to set the frame window size and location. It is the programming equivalent
of interactions you perform with the mouse by dragging a side of the window to extend or reduce
it, or by dragging the window top strip to move it.
To address the application from an in-process macro, use the name CATIA. Values are expressed
in screen pixels. The window location is determined by the location of its upper left corner, and
the origin is located at the screen upper left corner.
Language = “VBScript”
2. Set the window width to 500 pixels and the window height to 400 pixels
CATIA.Width = 500
CATIA.Height = 400
CATIA.Left = 150
CATIA.Top = 50
This example uses the Width, Height, Left and Top properties of the Application object.
61
2
The resulting macro can be run in-process only. Refer to Running Out-process Macros to run it
out-process with Windows NT.
This task shows how to open a part and print it on the default printer. It is the programming
equivalent of File->Open plus Immediate Print
You need to know the part name you want to print, and have a default printer defined. We assume
here to print the part named PartToPrint contained in e:\Parts
Language = “VBScript”
As soon as the part is opened, it is automatically set as the active document and displayed in
the active window. This active window is stored as a property of the application, named
ActiveWindow.
3. Request printing the part, that is the active window contents, on the default printer
CATIA.ActiveWindow.PrintOut()
CATIA.ActiveDocument.Close()
This example uses the Open method of the Documents collection object, the PrintOut method
of the Window object, and the ActiveWindow and ActiveDocument properties of the Applica-
tion object.
The resulting macro can be run in-process only. Refer to Running Out-process Macros to run it
out-process with Windows NT.
This task shows how to create a new part, save it with a given name, get some of its properties,
and close it. It is the programming equivalent of File->New , File->SaveAs , and File-
>Close .
We assume here to save the part we name PartToSave in e:\Parts
Language = “VBScript”
CATIA.Documents.Add(“Part”)
As soon as the part is created, it is automatically set as the active document and displayed in
the active window. This active window is stored as a property of the application, named
ActiveWindow.
3. Query if the part needs to be saved and save it if necessary to the disk file Part-
ToSave.CATPart.
If (CATIA.ActiveDocument.Saved)
CATIA.ActiveDocument.SaveAs(“e:\Parts\PartToSave.CATPart”)
End If
6. Retrieve whether or not the document is read only and print it in a message box
CATIA.ActiveDocument.Close()
63
2
This example uses the Add method of the Documents collection object, the ActiveDocument
properties of the Application object, the Saved, FullName, Path, and ReadOnly properties,
and the SaveAs, and Close methods of the Document object.
Using Cameras
The resulting macro can be run in-process only. Refer to Running Out-process Macros to run it
out-process with Windows NT.
This task shows how to open a part, save the active viewpoint, and display the part according to
the viewpoints stored in the provided cameras, then restore the stored viewpoint. It is the pro-
gramming equivalent of File->Open plus View->Named Views, and successively selecting
the supplied cameras and applying their viewpoints from the corresponding dialog box.
You need to know the part name you want to open. We assume here that the part is named
MyPart.CATPart and is contained in e:\Parts
Language = “VBScript”
MyViewer.NewCamera()
The camera created is named camera000 by default, if no other camera was created before.
You can rename it:
MyDoc.Cameras.Item(“camera000”).Name = “MyCamera“
4. Apply the different cameras. This consists in successively assigning the cameras’ 3D view-
points to this of the active viewer
MyViewer.Viewpoint3D = MyDoc.Cameras.Item(“MyCamera”).Viewpoint3D
65
2
This example uses the Open method of the Documents collection object, the ActiveWindow and
ActiveDocument properties of the Application object, the NewCamera method of the Viewer
object, the Viewpoint3D property of the Viewer3D object, and the Item method of the Cameras
collection object.
The resulting macro can be run in-process only. Refer to Running Out-process Macros to run it
out-process with Windows NT.
This task shows how to open a part, and modify the different characteristics of the 3D viewpoint,
that is the origin, the sight direction, and the up direction. It is the programming equivalent of
File->Open plus the programming equivalent of interactions you perform with the mouse by
zooming, panning, and rotating, and/or modifying the viewpoint by using View->Modify.
You need to know the part name you want to print. We assume here that the part is named
MyPart.CATPart and is contained in e:\Parts
Language = “VBScript”
67
2
This example uses the Open method of the Documents collection object, the ActiveWindow and
ActiveDocument properties of the Application object, the PutOrigin, PutUpDirection, and
PutSightDirection properties of the Viewpoint3D object, the Viewpoint3D property and the
Update method of the Viewer3D object, this method being inherited from the Viewer object.
69
3
PartDocument Collection
1 CurrentShape
Part CurrentBody Object
XYPlane 1
1 YZPlane 1 Abstract Object
OriginElements ZXPlane 1 Plane
1 Object To Expand
GeometricElements
* Expanded Object
GeometricElement
1 MainBody
Bodies
1
* Body
1
1
Sketches
* Sketch
1
Shapes
1
* Shape
1
Constraints
* Constraint
1
Relations
* Relation
1
Parameters
* Parameter
1
Factory3D
1
ShapeFactory
The PartDocument object aggregates, or includes, the part tree structure starting with the Part
object located at the top of the part specification tree. Among these objects, we find first objects and
collections you can also find in the part specification tree. These objects are:
• the three planes XY, YZ, and ZX you can retrieve from the OriginElement object using the
Part’s OriginElement property
• the 3D elements you can create as reference to position your 3D objects and stored in a Geo-
metricElements collection you can retrieve using the GeometricElements property
• the bodies you create, starting with the main body and stored in the Bodies collection you can
retireve using the Part’s Bodies property. These bodies contains the part’s geometry
The following diagram details the main properties and methods of these objects.
71
3
Item()
1 OriginElements
Current Shape * Shape
1 1
PlaneXY XYPlane
YZPlane 1
PlaneYZ
ZXPlane 1 Plane
PlaneZX
1
GeometricElements
* GeometricElement
1
Constraints
* Constraint
1
Relations
* Relation
1
Parameters
* Parameter
1
Factory3D
1
ShapeFactory
The Bodies collection includes Body objects, one being the main body returned by the MainBody
property of the collection. The part has in addition a current body and a current shape, returned or
set using the CurrentBody and the CurrentShape properties of the Part object respectively. The cur-
rent body is the body in which a new shape is added when using the ShapeFactory object. The cur-
rent shape is the shape of the current body after which a new shape is added in the specification tree
when using the shape factory. You then need to make current the appropriate body and shape before
using the shape factory.
73
3
Sketch
The Sketch object is described in the the following diagram.
Sketch Collection
GeometricElements
Constraints Object
Factory2D
... Abstract Object
OpenEdition()
CloseEdition()
Object To Expand
Factory2D
Factory2D
Expanded Object
CreatePoint()
CreateLine()
1 CreateCircle()
...
1
GeometricElements
* GeometricElement
1
Constraints
* Constraint
Centerline
Line2D
AbsoluteAxis
Axis2D
The Sketch object contains 2D geometric elements that define the sketch. These elements are cre-
ated using the Factory2D object and contained in a GeometricElements collection aggregrated by
the sketch. To create 2D geometric elements, you need first to “open the sketch edition” using the
OpenEdition method that returns the Factory2D object which supplies the appropriate methods to
create 2D geometric elements. Once you have finished creating 2D geometric elements, “close the
sketch edition” using the CloseEdition method. These two methods correspond to the commands
that let you interactively enter and leave the sketch. You can set constraints to the 2D
geometric elements using the methods supplied by the Constraints collection aggregated to the
sketch.
Geometric Elements
The geometric elements are described in the the following diagram.
GeometricElement
GeometricType
Plane
Ellipse2D
Curve2D
Hyperbola2D
Parabola2D
StartPoint
EndPoint
Geometry2D Spline2D
Points
1 1 Control
2..*
Point2D ControlPoint2D
Axis2D
VerticalReference
HorizontalReference Line2D
The GeometricElement object is the abstract object from which derive all the others. It provides the
GeometricType property which returns the type of the geometric element to which it is applied. The
Geometry2D and Geometry 3D objects are abstract objects without any property.
The 3D geometric elements available are the Plane, the Line and the Point, and can be created to be
used as reference elements in the for the part and retrieved using its GeometricElements property.
The 2D geometric elements are used in sketches. The Curve2D object gathers the curve common
properties and methods.
75
3
Constraints
Constraints
BrokenConstraintsCount
UnUpdatedConstraintsCount
AddMonoEltCst()
AddBiEltCst()
AddTriEltCst()
Item()
Remove()
* Constraint
Type
Dimension
Mode
Side
Orientation
DistanceConfig
ReferenceAxis
Status
AngleSector
GetConstraintVisuLocation()
SetConstraintVisuLocation()
0..1
Dimension
Dimension
The Constraints collection provides methods to create constraints. A constraint can constrain one,
two or three elements. The number of broken and unupdated constraints can be retrieved from the
collection. A given constraint is defined using properties to set its type, its mode, its side and orien-
tation, its dimension and configuration, its reference axis, and its status. The type of a constraint
defines its nature, that is how the constraint works, and how many elements can be involved in
defining the constraint. The constraint status indicates if the constraint is valid, if something goes
wrong with the constraint, or if the constraint is broken. Other properties make sense for certain
types of constraints only (DistanceConfig or AngleSector for example). The constraint visualiza-
tion location can be set or retrieved in the 3D space using the two methods GetConstraintVisuLoca-
tion and SetConstraintVisuLocation.
Shapes
Shape
SketchBasedShape
Sketch
BooleanShape
Body
DressUpShape
TransformationShape
Shapes are classified into those built on a sketch, such as a pad or a hole, those which represent
boolean operations, such as a split or an intersection, those which are used to dress-up sketch-based
shapes, such as a fillet or a chamfer, and finally those which transform an original shape, transform
meaning here duplicates, such as mirror and pattern.
77
3
Sketch-Based Shapes
SketchBasedShape
Sketch
Relies on
Sketch
Prism
Hole
Revolution
Stiffener
Sweep
Sketch-based shapes rely obviously on sketches, and the Sketch property sets or retrieves the sketch
associated with the shape. The Prism abstract object federates properties and methods for the Pad
and the Pocket objects.
Prism
Extrusion
Pad direction orientation
Prism
DirectionType Pocket First limit
DirectionOrientation
IsSymmetric Extrusion
FirstLimit direction
SecondLimit
GetDirection
SetDirection Sketch to extrude
Is limited by 2 Normal or not
Limit
{ordered}
FirstLimit Second limit
SecondLimit
The Prism object provides to the Pad or to the Pocket the extrusion direction set or retrieved thanks
to the SetDirection or GetDirection methods. This extrusion direction can be normal to the sketch
plane or not. This is expressed using the CatPrismExtrusionDirection enumeration in the Direction-
Type property. The extrusion direction has an orientation expressed using the CatPrismOrientation
enumeration in the DirectionOrientation property. The Pad or the Pocket object can be symmetric to
the skecth plane. This is stored in the IsSymmetric property. Finally, the pad or the pocket has two
limits stored in the FirstLimit and SecondLimit properties as Limit objects. The Pad and the Pocket
objects do not hold specific properties or methods.
Hole
79
3
Revolution
Groove
Revolution
FirstAngle Shaft
SecondAngle
Is limited by 2
Angle
{ordered}
Stiffener
Stiffener
Thickness
IsSymmetric
ReverseDepth()
Is thick of 1
Length
Sweep
Rib
Sweep
CenterCurve Slot
Is centered on 1
Sketch
Boolean Shapes
BooleanShape
BooleanShape
Body
Is inserted 1
Body
Add
Assemble
Intersect
Remove
Split
SplittingPlane
Splits along
Plane
81
3
Dress Up Shapes
DressUpShape
Chamfer
Draft
Fillet
Scaling
Shell
Thickness
Chamfer
Chamfer
Mode
Propagation
Orientation
Angle
Length1
Length2
ElementsToChamfer
AddElementToChamfer()
WithdrawElementToChamfer()
Chamfer angle 1
Angle
Chamfer lengths 2
{ordered}
Length
Collection of 1
elements to chamfer References
* Reference
Draft
Draft
Mode
PartingElement
DraftDomains
Parting element 1
Reference
Collection of 1
draft domains DraftDomains
* DraftDomain
83
3
Fillet
Fillet
FaceFillet
Radius
FirstFace
SecondFace
Fillet radius 1
Length
Faces to fillet 2
Reference
{ordered}
TritangentFillet
FirstFace
SecondFace
FaceToRemove
Faces to fillet 3
Reference
{ordered}
ConstRadEdgeFillet
ObjectToFillet
EdgesToKeep
Radius
AddObjectToFillet()
EdgeFillet ...
Builds on 2
References
ObjectToFillet
EdgesToKeep * Reference
Fillet radius 1
Length
Radius
VarRadEdgeFillet
EdgesToFillet
ImposedVertices
FilletVariation
ImposedVertexRadius()
...
Builds on 2
References
EdgesToFillet
ImposedVertices * Reference
Scaling
Scaling
Mode
Factor
ScalingSupport
Scaling factor 1
RealParam
Scaling support 1
Reference
Shell
Shell
InternalThickness
ExternalThickness
FaceToRemove
AddFaceToRemove()
WithdrawFaceToRemove()
Thicknesses 2
{ordered}
Length
Collection of 1
faces to remove References
* Reference
85
3
Thickness
Thickness
Offset
FacesToThicken
AddFaceToThicken()
WithdrawFaceToThicken()
Offset 1
Length
Collection of 1
faces to thicken References
* Reference
Transformation Shapes
TransformationShape
Mirror
MirroringPlane
Mirrors in 1
Plane
RectPattern
FirstDirectionRepartition
SecondDirectionRepartition
FirstDirection
SecondDirection
FirstDirectionRow
Pattern SecondDirectionRow
ItemToCopy ...
RotationAngle Direction repartitions 2
LinearRepartition
Directions 2
Reference
Direction rows 2
IntParam
CircPattern
RadialRepartition
AngularRepartition
RotationAxis
Rotationcenter
AngularDirectionRow
RadialDirectionRow
...
Radial repartition 1
LinearRepartition
Agular repartition 1
AngularRepartition
Rotation axis 1
Reference
Rotation center 1
Reference
Direction rows 2
IntParam
Pattern to reproduce
CATIABase
Rotates
Angle
87
3
Repartition
AngularRepartition
AngularSpacing
Repartition Angular spacing 1
Angle
InstancesCount
LinearRepartition
Spacing
Spacing 1
Length
Count 1
IntParam
Limit
Limit
LimitingElement
Dimension
LimitMode
LimitingElement 1
Reference
Dimension 1
Length
89
3
Draft Domain
DraftDomain
DraftAngle
Support
NeutralElement
...
AddSupportToDraft
RemoveSupportToDraft
Draft angle 1
Angle
Neutral element 1
Reference
Support 1
References
* Reference
Relations
Relation
Value
Comment
Family
Activated
Activate()
Deactivate()
Check
Formula
Program
91
3
Literal Objects
Parameter
OptionalRelation
ReadOnly
Is constrained by
Relation
Length
RealParam Dimension
Value ValuateFromString Angle
IntParam
Value
BoolParam
Value
StrParam
Value
93
3
Creating Parameters
The resulting macro can be run in-process only. Refer to Running Out-process Macros to run it
out-process with Windows NT.
Language = “VBScript“
2. Retrieve the active document and the collection of parameters associated with the part
3. Create an empty string parameter to store the material of the part, name it and value it
4. Create a dimension parameter set to 0 to store the height of the pad, name it and value it
5. Create an integer parameter set to 0 to store the part number, name it and value it
6. Create a boolean parameter set to True to store the part number, name it and value it
95
3
Creating a Formula
The resulting macro can be run in-process only. Refer to Running Out-process Macros to run it
out-process with Windows NT.
This task shows how to create a formula which computes the height of a pad by dividing by two
a length constraint set on one of the element of the sketch on which the pad is built.
You need a plane.
Language = “VBScript“
2. Retrieve the main body of the active document and the pad named Pad.1 in this main body
3. Create a formula named Formula.1 with an empty comment, which output value is the
pad height (its first limit dimension). The height is computed using half of the value of a dis-
tance constraint set to the sketch on which the pad is built, named PadLength
Modifying a Formula
The resulting macro can be run in-process only. Refer to Running Out-process Macros to run it
out-process with Windows NT.
This task shows how to modify the formula created in Creating a Formula to now compute the
height of the pad by adding the values of two length constraints set on two elements of the sketch
on which the pad is built.
You need a plane.
Language = “VBScript“
2. Retrieve the main body of the active document and the pad named Pad.1 in this main body
4. Modify the formula. The new output value is computed by adding the values of two distance
constraints set to the sketch on which the pad is built, named PadLength and PadWidth
97
3
The resulting macro can be run in-process only. Refer to Running Out-process Macros to run it
out-process with Windows NT.
This task shows how to deactivate a formula, then set a parameter previously computed by the
formula, and possibly activate then formula again. The same could apply to a program or a
check.
The formula is assumed to exist already and controls the height of a pad contained in the active
part document.
Language = “VBScript“
2. Retrieve the formula named Formula.1 from the part of the active document
3. Deactivate the formula. From now on, the formula is not used any more to compute its out-
put parameter
myFormula.Deactivate
4. Retrieve the pad and set the height of the pad named Pad.1 to a value of 35. The pad height is
no longer controlled by the formula, but has the constant value you set. Nevertheless the for-
mula remains in the part.
5. Deactivate the formula. From now on, the formula is not used any more to compute its out-
put parameter
myFormula.Deactivate
99
3
Creating a Program
The resulting macro can be run in-process only. Refer to Running Out-process Macros to run it
out-process with Windows NT.
Language = “VBScript“
2. Retrieve the main body of the active document and the pad named Pad.1 in this main body
3. Create a program named Program.1 with an empty comment, which computes the pad
height (its first limit dimension) and mass. The height of the pad is computed by adding the
values of two length constraints set on the sketch (a rectangle), named PadLength and
PadWidth, on which the pad is built.
Creating a Check
The resulting macro can be run in-process only. Refer to Running Out-process Macros to run it
out-process with Windows NT.
Language = “VBScript“
2. Retrieve the main body of the active document and the pad named Pad.1 in this main body
3. Create a check named Check.1 with a comment, which checks that the pad length is
greater than 10mm. The pad length is a distance constraint set to the sketch on which the pad
is built
101
3
103
4
ProductDocument Collection
1
Product * Object
1 Abstract Object
Products
1 Object To Expand
Constraints
1
Position
1
Move
The ProductDocument object aggregates, or includes, a product tree structure starting with a single
product, named the root product, which includes a collection of products. Each of the products of
this collection can itself include a collection of products, and so forth.
Each product is positioned in the 3D space thanks to the Position object which represents the prod-
uct’s 3D-axis system expressed with respect to the assembly’s 3D-axis system. The Move object
allows the object moving. Constraints can be set to constrain the product’s position and move.
The following diagram shows such a tree structure for a (simple) car.
Roof
Products that can
LeftFrontDoor also have each
its own collection
Bonnet of products
PowerTrain
PowerTrainParts
Engine
EngineParts
Cylinderhead
Products that can
Cylinder also have each
its own collection
of products
Carter
Coupling
Products that can
GearBox also have each
its own collection
Rear Axle of products
RearAxleParts
Products that can
LeftRearWheel also have each
its own collection
RightRearWheel of products
A given product, such as the cylinder head or the gear box, is in fact a product component of a prod-
uct reference. This product reference is neither accessible using macros nor from interactive com-
mands. It is nevertheless created when you create a product component. Products that appear
105
4
duplicated, such as the wheels, can be product components pointing to the same product reference.
In this example, the LeftRearWheel and RightRearWheel objects can be two product components of a
single wheel product reference. Creating references enables consistency management. When a
modification is brought to a product, such as its part number, or its master shape representation
which we’ll see below, the modification is brought through a component to the reference, and is
propagated to all the components which point to this reference.
The following diagram gives additional details about the Assembly Design objects.
ProductDocument Collection
Product
Object
Root Product 1
Product *
Abstract Object
Contained Products
Products
Connections
Position Object To Expand
Move
...
Expanded Object
AddMasterShapeRepresentation()
RemoveMasterShapeRepresentation()
GetMasterShapeRepresentation()
...
Contains Product 0..1
Collection
Products
AddNewProduct()
AddComponent()
AddExternalComponent()
...
Positioning Constraints 1
Constraints
* Constraint
Is positioned at 1
Position
GetComponents()
SetComponents()
Can be moved by 1
Move
MovableObject
Apply()
The root product is retrieved by the ProductDocument object using its Product property. Each
product, starting with the root product, may include a Products collection which gathers all the
products just below this product in the product tree structure. This collection is built using the Add-
NewProduct, AddComponent and AddExternalComponent methods:
• AddNewProduct creates both a reference to the product and a component in the ProductDocu-
ment
• AddComponent creates a product component from a product reference already existing in the
ProductDocument, that is a product component of a product already created in any of the Prod-
ucts collection of the ProductDocument using the AddNewProduct method
• AddExternalComponent creates a product component using the root product of another Pro-
ductDocument.
Each product reference can have a master shape representation which defines its geometry, material
properties, and so forth, and used to display or print it, and maybe more, for example to analyze or
manufacture it. This is optional, but is often required to represent actual products. This master
shape representation is shared by all the components pointing to this product reference, and can be
a CATIA Version 4 model, a CATIA Version 5 part, a VRML file, or whatever format supported by
CATIA Version 5. The methods AddMasterShapeRepresentation, RemoveMasterSha-
peRepresentation, and GetMasterShapeRepresentation manage the master shape repre-
sentation.
Each product component in the tree structure is positioned in the space according to the position of
its own 3D-axis system with respect to the product document’s 3D axis-system, this position being
possibly determined according to positioning constraints relative to the product above it in the tree
structure. This means that each product component is positioned with respect to the root product
according to a cascading position combination from the root product to the current product across
the product tree structure. Its position can be set or retrieved using the Position property, what-
ever the constraints applied. The Move property allows a movable object retrieval to move the prod-
uct as required by a move operation while ensuring that the positioning constraints are matched.
The movable object returned is the product object itself, meaning that a product is movable, but
with some other applications, this could be different. For example, the movable object returned
from an edge in a pad is the whole pad, since the edge cannot be moved alone and is linked to the
other edges and faces in the pad. The actual move is performed using the Apply method. This
method takes a table with twelve items as input which define the move. This table contains the
move matrix elements and has the following structure, assuming that M is the table identifier:
The first nine items represent an axis rotation, and the last three a translation. It expresses the prod-
uct 3D-axis system (T,U,V,W) with respect to the root product 3D-axis system(O,xy,z), where:
• Ux, Uy and Uz are the components of the U vector with respect to (O,x,y,z)
• Vx, Vy and Vz are the components of the V vector with respect to (O,x,y,z)
• Wx, Wy and Wz are the components of the W vector with respect to (O,x,y,z)
• Tx, Ty and Tz are the coordinates of the new origin T with respect to (O,x,y,z)
107
4
V
U
z
O
x y
109
4
The resulting macro can be run in-process only. Refer to Running Out-process Macros to run it
out-process with Windows NT.
This task shows how to create an assembly in a product document using two parts. The product
tree structure is as follows:
ProductDoc The part document
The two parts should exist before running this macro. Assume that Part1.CATPart contains a
cuboid and is the master representation of ChildProduct1, and that Part2.CATPart contains a
cylinder and is the master representation of ChildProduct2. Note that there is no master represen-
tation for the root product.
Language = “VBScript”
2. Create the ProductDocument object by adding a document with the Product type to the doc-
ument collection of the CATIA application
RootProduct.PartNumber = “Root”
RootProduct.Name = “The_Root_Product”
6. Add a new product in the collection. This adds both a product reference and a product com-
ponent.
ChildProduct1.PartNumber = “Child_001”
ChildProduct1.Name = “1st_Child”
8. Add a representation to this product using Part1.CATPart and reframe the viewer to display
the part completely
ChildProduct1.AddMasterShapeRepresentation(“e:\Parts\Part1.CATPart”)
CATIA.ActiveWindow.ActiveViewer.Reframe()
9. Add another product to the root product’s collection. This adds both a product reference and
a product component
10. Declare the part number and name for this product
ChildProduct2.PartNumber = “Child_002”
ChildProduct2.Name = “2nd_Child”
11. Add a representation to this product using Part2.CATPart and reframe the viewer
ChildProduct2.AddMasterShapeRepresentation(“e:\Parts\Part2.CATPart”)
CATIA.ActiveWindow.ActiveViewer.Reframe()
Note that we don’t add any positioning information. The parts are then located at the place
where they were designed, and the root product’s axis system and the parts’ axis systems
coincide.
111
4
This example uses the Add method of the Documents collection to create the product document,
the Product property of the ProductDocument object to retrieve the root product, the Part-
Number property of the Product object to create a part number for the two products, the Name
property of the AnyObject object from which the Product object inherits to assign them a
name, the AddMasterShapeRepresentation method of the Products object to associate a
part to each of the products and enable their display, the Products property of the Product
object to retrieve the product collection of the root product, and the AddNewProduct method of
the Products object to add the child product to the root product’s collection. Here is the result.
For each product, its part number, such as Child_001, is displayed first and its name, such as
1st_Child, is displayed between parentheses in the product tree. The product’s master representa-
tion, such as Part1, is displayed attached to the product at a lower level.
113
4
The resulting macro can be run in-process only. Refer to Running Out-process Macros to run it
out-process with Windows NT.
This task shows how to create an assembly in a product document using two parts. The root prod-
uct is the steam ship Titanic, comprising five products: the hull and the four identical funnels.
The first funnel is added as a new product and the three others are created from it.The product
tree structure is as follows:
Hull
Funnel1
Funnel3
Funnel4
This task shows you in addition how to position components in the 3D space.
The two parts should exist before running this macro. Assume that Hull.CATPart is the mas-
ter representation for the hull, and Funnel.CATPart the one of the funnel.
Language = “VBScript”
2. Create the ProductDocument object by adding a document with the Product type to the doc-
ument collection of the CATIA application
Titanic.PartNumber = “Titanic”
Titanic.Name = “Steam_Ship_Titanic”
6. Add the hull as a new component in the collection with its part number and name
7. Add a master shape representation to the hull using Hull.CATPart and reframe the
viewer
Hull.AddMasterShapeRepresentation(“e:\Parts\Hull.CATPart”)
CATIA.ActiveWindow.ActiveViewer.Reframe()
Note that we don’t add any positioning information. The part is then located at the place
where it was designed.
8. Add the first funnel to the Titanic’s product collection, with part number and name
Funnel1.AddMasterShapeRepresentation(“e:\Parts\Funnel.CATPart”)
115
4
Dim Matrix(11)
Matrix(0) = 1.0
Matrix(1) = 0.0
Matrix(2) = 0.0
Matrix(3) = 0.0
Matrix(4) = 1.0
Matrix(5) = 0.0
Matrix(6) = 0.0
Matrix(7) = 0.0
Matrix(8) = 1.0
Matrix(9) = 110.0
Matrix(10) = 20.0
Matrix(11) = 20.0
We just translate Funnel1 using the vector (110,20,20) to place the fore funnel on top of the
hull and in with its bottom center on the longitudinal axis of the hull.
Funnel1.Move.Apply(Matrix)
117
4
This example uses the Add method of the Documents collection to create the product document,
the Product property of the ProductDocument object to retrieve the root product, the Part-
Number property of the Product object to create a part number for the root product and the
Name property of the AnyObject object from which the Product object inherits to assign the
root product a name. Then the hull is added as a component using the AddNewProduct method
of the Products collection, and a master shape representation is assigned to it using the
AddMasterShapeRepresentation method of the Products collection. The same applies to
the first funnel. It is positioned in the space using the matrix defined and the Move property of the
Product object which retrieves a Move object to which the Apply method is applied. Then the
three other funnels are created as components using the reference created by the first funnel
thanks to the AddComponent method of the Products collection. For each funnel, the matrix is
modified and the funnel is positioned as the first one.
The resulting macro can be run in-process only. Refer to Running Out-process Macros to run it
out-process with Windows NT.
This task shows how to include in an existing assembly a new component which is already the
root product of another product document.
The product document is assumed to be the active document. The product document to add is
already opened. The added component is added to the root product collection.
Language = “VBScript”
5. Add a new component from the already opened product document ExtDoc
119
4
This example uses the ActiveDocument method of the Application object to retrieve the
active document, the Product property of the ProductDocument object to retrieve the root
product, and the Products property of the Product object to retrieve the collection of product
of the root product, and the AddExternalComponent method of the Products collection to
add the root product of the already opened product document ExtDoc as a component of the root
product collection.
The resulting macro can be run in-process only. Refer to Running Out-process Macros to run it
out-process with Windows NT.
This task shows how to extract a bill of materials from a product document.
This macro should be applied to the product document created using the macro described in Cre-
ating an Assembly with Components of the Same Product.
Language = “VBScript”
Titanic.ExtractBOM(catFileTypeText, e:\BOM\TitanicBOM.txt)
121
4
This example uses the ActiveDocument method of the Application object to retrieve the
active document, the Product property of the ProductDocument object to retrieve the root
product, and the ExtractBOM method of the Product object to extract the bill of materials. The
extracted bill of materials is as follows
=======================================================================
=========
= Bill of Material :
Titanic =
=======================================================================
=========
+----------+----------------------+-------+---------------------+------
--------+
| Qty | Part Number | type | Nomenclature |
Revision |
+----------+----------------------+-------+---------------------+------
--------+
| 1 | Titanic’s_Hull |
part | | |
| 4 | Titanic’s_Funnel |
part | | |
+----------+----------------------+-------+---------------------+------
--------+
===================================
= Recapitulation Of : Titanic =
= Different Parts : 2 =
= Total Parts : 5 =
===================================
+----------+----------------------+
| Qty | Part Number |
+----------+----------------------+
| 1 | Titanic’s_Hull |
| 4 | Titanic’s_Funnel |
+----------+----------------------+
123
5
Collection
Object
Document to draw 1
Document
The Drawing objects build a cascading aggregation architecture. The DrawingDocument object
includes a DrawingSheets collection. Each DrawingSheet of this collection includes a DrawingViews
collection to store its DrawingView objects. A DrawingView object handled by the Generative Draft-
ing is generated from a document and aggregates a DrawingViewGenerativeBehavior object which
contains the appropriate data to generate the drawing view, such as the document that the drawing
view represents, and possibly another drawing view called the parent view and used to define addi-
tional useful information. For example, a left view is not a left view alone, but is a left view with
respect to another view called the front view. This front view is the parent view for the left view. It
defines the contents of the left view, and how to see this contents, that is as if the user looked the
scene represented by this front view from the left.
The drawing view can also be linked to its parent view for alignment purpose, and this link is called
reference. This is the case of a left view linked to a front view. This reference is always and only an
alignment reference to help position the drawing view with respect to its reference drawing view.
For example, the left view is positioned at the right of the front view according to the ISO standard,
and to the left of the front view according to the ANSI standard, in both cases on a horizontal line
with respect to the front view. This alignment reference can be deactivated.
DrawingDocument Collection
Sheets
1
Object
DrawingSheets
ActiveSheet Abstract Object
Add()
Remove() Object To Expand
Item()
Expanded Object
* DrawingSheet
Views
Activate()
Update()
GenerateDimensions()
1
DrawingViews
ActiveView
Add()
Remove()
Item()
* DrawingView
The DrawingDocument object aggregates its DrawingSheets collection and you can retrieve it thanks
to the Sheets property. When a drawing document is active, it has always an active sheet you can
retrieve from the DrawingSheets collection using the ActiveSheet property. The active sheet is
the sheet you are working in. Like many collections, the drawing sheet collection supplies the Add,
Remove, and Item method to manage the sheets in the collection. The DrawingSheet object aggre-
gates its DrawingViews collection and you can retrieve it thanks to the Views property. In the active
drawing sheet, there is always an active drawing view. This is the one you are working in, or in
which you can work, and is surrounded using a red dashed frame. You can activate the drawing
view you want using the Activate method. The Update method updates all the drawing views of
the drawing sheet according to the modification brought to the document(s) represented in these
drawing views. The GenerateDimensions method generates dimensions, in all the views of the
drawing sheet which contains documents with constraints, such as constraints in sketches, in 3D
parts, between 3D primitives, and assembly constraints, for each constraint of the following type:
distance, length, angle, radius, and diameter. The drawing view collection lets you retrieve the
active view using the ActiveView property. Like many collections, the drawing view collection
supplies the Add, Remove, and Item methods to manage the views in the collection.
125
5
Reference View
DrawingView DrawingView
x 1
y
Scale
Angle
GenerativeBehavior Collection
ReferenceView
Activate() Object
AlignedWithReferenceView()
UnAlignedWithReferenceView()
IsGenerative() Abstract Object
1 Object To Expand
DrawingViewGenerativeBehavior
Document
ParentView Expanded Object
HiddenLineMode
SetProjectionPlane()
GetProjectionPlane()
GetProjectionPlaneNormal()
DefineFrontView()
DefineIsometricView()
DefineProjectionView()
DefineSectionView()
DefineCircularDetailView()
DefineAuxiliaryView()
Update()
ParentView
Document to draw 1
Document
The drawing view is placed in the drawing sheet using the following properties:
y
Angle
The x, y, and Angle properties are used to place the drawing view in the drawing sheet. The draw-
ing view has also a Scale property which determines its size in the drawing sheet with respect to
the 3D document represented. The GenerativeBehavior property retrieves the DrawingViewGen-
erativeBehavior object associated with the drawing view, and you can get or set the reference view
thanks to the ReferenceView property.
Using the Activate method, you can make the drawing view the active one. The AlignedWith-
ReferenceView and UnAlignedWithReferenceView methods enable you to align and deacti-
vates the alignment with respect to the reference view. The IsGenerative methods returns
whether the drawing view is generated from a document.
The DrawingViewGenerativeBehavior object includes additional parameters to fully define the draw-
ing view. First, it includes a link to the represented document using its Document property. Then it
includes a link to the parent view, if any, thanks to the ParentView property. It also includes the
DefinexxxView methods to define views according to the different available types. The Set-
ProjectionPlane, GetProjectionPlane, and GetProjectionPlaneNormal methods man-
age the drawing view projection plane. The drawing view projection plane is usually defined when
the drawing view is created, either by setting it explicitly for a front view or an isometric view, or
by deducing it from the one of the parent view for the other views.
A drawing view can be used as a parent view for other drawing views. When you create a drawing
view, for example from a part, you first create a front view, and then you can create a left, right, top,
or bottom drawing view from this front view. The left, right, top, or bottom view is called a projec-
tion view. The front view is used as a parent view to determine how the document is projected in the
projection view. For example, left means projecting the part on a vertical plane which is perpendic-
ular to the front view projection plane, and which is seen from the left.
A drawing view is strongly linked to its parent view. If the parent view is updated because the doc-
ument it displays has changed, or if you change its scale, all the drawing views which have this
view as parent view are changed accordingly.
127
5
left view
projection plane
left
front
front view left view
The front view is also used as a reference by the left view for positioning. If you want to move the
left view, it is constrained to move horizontally to remain a left view of the front view. The left view
can access its reference view by means of the ReferenceView property.
The following table summarizes the different view types along with their ability to have a parent
view and if this parent view can also be a reference view.
A front view or an isometric view are defined using the components of the two vectors defining its
projection plane in the 3D space.
The other views are all defined by giving the DrawingViewGenerativeBehavior object of their parent
view, and additional information:
• a projection view is defined using a view type which can be left, right, top, or bottom using the
CatProjViewType enumeration.
• a section view or section cut is defined using a section profile in the parent view and passed as
an array of point coordinates expressed with respect to the parent view axis system. Other
information is required, namely the section type, that is whether the section is a section cut or a
section view, the profile type, that is whether the section is aligned or offset, and the drawn side
of the section. This drawn side is determined as follows: the parent view is rotated clockwise or
counterclockwise around the first segment of the section profile oriented from its start point to
its end point.
• a detail view is defined from a parent view and using a clipping circle
• an auxiliary view is defined from a parent view and using a line which defines the trace of the
auxiliary view projection plane in the parent view.
129
5
Updating All the Sheets of all the Drawings Contained in VB Script only
a Folder
Printing All the Sheets of all the Drawings Contained in VB Script only
a Folder
The resulting macro can be run in-process only. Refer to Running Out-process Macros to run it
out-process with Windows NT.
This task shows how to create a front view in the XY plane from a part, and then a projection
view.
The part document is opened in the macro.
Language = “VBScript“
MyFrontViewGB.Document = PartToDraw
8. Define this view as an actual front view with the XY plane as projection plane
MyFrontViewGB.DefineFrontView 1, 0, 0, 0, 1, 0
131
5
MyLeftView.GenerativeBehavior.DefineProjectionView MyFrontViewGB,
catLeftView
The resulting macro can be run in-process only. Refer to Running Out-process Macros to run it
out-process with Windows NT.
This task shows how to create a section view from an existing view.
Language = “VBScript“
4. Retrieve the view you want to use as reference for the section view
133
5
8. Define the profile to use for sectioning the reference view with four points
Dim SectionProfile(7)
SectionProfile(0) = -50
SectionProfile(1) = 160
SectionProfile(2) = -50
SectionProfile(3) = 30
SectionProfile(4) = 75
SectionProfile(5) = 30
SectionProfile(6) = 75
SectionProfile(7) = -50
9. Define the view named Section View as an actual section view of the reference view
The resulting macro can be run in-process only. Refer to Running Out-process Macros to run it
out-process with Windows NT.
This task shows how to create a section view from an existing view.
Language = “VBScript“
4. Retrieve the view you want to use as reference for the detail view, for example the front view
8. Define the view named Detail View as an actual detail view of the reference view by giving a
point by its two coordinates, a radius, and the generative behavior object of the reference
view
135
5
The resulting macro can be run in-process only. Refer to Running Out-process Macros to run it
out-process with Windows NT.
This task shows how to create a drawing using two different documents.
Language = “VBScript“
MyFrontView1GB.Document = PartToDraw
137
5
9. Define this view as an actual front view with the XY plane as projection plane
MyFrontViewGB1.DefineFrontView 1, 0, 0, 0, 1, 0
MyFrontView2GB.Document = ProductToDraw
13. Define this view as an actual front view with the ZX plane as projection plane
MyFrontView2GB.DefineFrontView 0, 0, 1, 1, 0, 0
The resulting macro can be run in-process only. Refer to Running Out-process Macros to run it
out-process with Windows NT.
This task shows how to generate dimensions in a drawing document from the constraints set in
the referenced document(s).
The dimensions are generated in the active sheet of the active document, supposed to be a draw-
ing document.
Language = “VBScript“
MySheet.GenerateDimensions()
139
5
The resulting macro can be run in-process only. Refer to Running Out-process Macros to run it
out-process with Windows NT.
This task shows how to update all the sheets of all the drawing documents contained in a given
folder according to the modifications performed in the documents they refer to since their cre-
ation or last update.
The folder scanned contains any documents, and only drawing documents are processed.
Language = “VBScript“
CATIA.DisplayFileAlerts = False
3. Request the end user to enter the appropriate folder name using an input box
141
5
The resulting macro can be run in-process only. Refer to Running Out-process Macros to run it
out-process with Windows NT.
This task shows how to print all the sheets of all the drawing documents contained in a given
directory on the default printer.
The folder scanned contains any documents, and only drawing documents are printed.
Language = “VBScript“
CATIA.DisplayFileAlerts = False
3. Request the end user to enter the appropriate folder name using an input box
143
5
145
6
Glossary
A
application The root object that aggregates all the others in the CATIA object model
exposed for scripting.
C
collection An object that contains a set of objects of the same type.
D
document A common unit of data (typically a file) used in user tasks and exchanged
between users.
document window A window that provides a primary view of a document (typically its content).
J
journalling Recording user command sequences as macros coded using a scripting lan-
guage such as Visual Basic, to make it possible to replay them when required,
or to modify them to create other replayable macros.
M
macro A block of instructions that can be run. Synonym of script.
147
O
object The basic component of the CATIA exposed model for scripting. An object
stands for an entity you are used to handle through the end user interface, such
as a document, a window, a pad, a hole, or a circle. An object can expose prop-
erties and methods.
P
property A named attribute of an object.
S
script A block of instructions that can be run. Synonym of macro.
scripting engine A program that allows for scripting. Visual Basic Scripting Engine is hosted by
CATIA to allow for in-process access.
V
variable A named storage location that contains data a script or macro can modify.