0 ratings0% found this document useful (0 votes) 660 views5 pagesCatia Macro Programming With Visual Basic Script689
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
‘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
@ 1.1 Definition of CATScript and CATVBS
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 VS. Up to VSR7, CATVBS only ran on Windows machines. From VSR8
on, Dassault Systémes have expanded their programming so that CATVBS also operates
on UNIX workstations
CATSeript 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 VSRB.
CATScript and CATVBS are interpreter languages that serve as the foundation for pro-
gramming macros in CATIA VS. Macros that are written in CATScript or CATVBS can be
used on Windows 7, Vista, XP, NT, 98 and 2000, and UNIX operating systems.—
Nk
TABLE 1.1. Overview of the Macro Languages in CATIA VS
Pe TTT: (CAML IL LLL cs SL et
CATScript —*.CATScript Reduced VBScript Macros (Win and UNIX), Ce
Interpreter (Windows, UNIX) Knowledgeware
CATVBS — *.calvbs. Complete VBScript Interpreter Macros (Win and UNIX), CA
(Windows, UNIX, since 5R8) Knowledgeware
CATVBA —*.catvba Visual Basic for Applications Menu-based
Compiler (Win) Applications (Win)
Programming CATIA macros with Visual Basic for Applications (CATVBA) offers
capabilities for CATIA V5. CATVBA has a compiler and provides many tools for desig
user interfaces. These two points distinguish it from CATScript and CATVBS. An
view of all three languages is shown in Table 1.1.
‘The program syntaxes of CATScript, CATVBS, and CATVBA are very similar. By mz
slight changes, program components are very easily transferred from one platfor:
another, as long as other methods and objects in that platform are available. In 1
cases, the three languages differ only in the way that variables, functions, and proced
are defined. An overview of these differences is illustrated with a small sample progra
Table 1.2. The differences are highlighted in bold.
TABLE 1.2 Differences between CATScript, CATVBA, and CATVBS
CATScript and CATVBA
Sub CATMain ()
* Create New CATPart -------~
Dim D As Document
Set D = CATIA.Documents.Add (“Part”)
* Create Open Body
He Dim As Hybridsody
Set HB = HBodyCreate(D)
Set W2k30 = D.Part.HybridShapeFactory
Create Points --------------
Dim I As Integer
For i - 1 To 100
Dim P As HybridShapePointCoord
Set P = W2k3D.AddNewPointCoord (I *
10. 0. 0)
HB.AppendiybridShape P
Next.
D.Part Update
End Sub
Function HBodyCreate (D As Document) As
HybridBody
HB Dim As HybridBody
Set HB = HB = D.Part.HybridBodies.Add
Set HBodyCreate = HB
End Function
CEs
Sub CATMain ©
* Create New CATPart -------
Dim D
Set D = CATIA.Documents.Add (“Part”)
* Create Open Body
Dim HB
Set HB = HBodyCreate(D)
Set W2k30 = D.Part.HybridShapeFactory
* Create Points -
Dim I
For I= 1 To 100
Dim P
Set P = W2k3D.AddNewPointCoord (1
#10, 0, 0)
HB. AppendHybridshape P
Next
D.Part Update
End Sub
Function HBodyCreate (D)
Dim HB
Set HB = D.Part.HybridBodies.Add
Set HBodyCreate = HB
End FunctionSince CATScript through its history has the closest connection with CATIA VS, 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.
# 1.2 Definition of Nomenclature
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
Ageneral description provides all the capabilities of the commands in an instruction. One
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, acomma,
ora space. Important words in a general description and in examples are highlighted in
bold.
Example 1.1: Highlighting Important Words
Line. Length ~ 100
Additional information of a general description can be enclosed in square brackets or
braces.
Asquare bracket encloses words that can be defined by a programmer. A self-defined word
can be a name or the contents of memory location. If the memory location is defined by a
programmer, it is called a Variable. A memory location for an object or a subroutine is
called a Parameter. ‘The information following a square bracket with the keyword “As”
determines the type of variable or parameter. If several variables or parameters have the
same type, they can be listed within the same square bracket.
Example 1.2: Description of Variables and Parameters
General Description
Definition.TwoLines [Line 1, Line 2] As Line
Code in the macro:
Definition.TwoLines Cente
Line, Drawing Direction
A.cutly brace encloses optional words that do not need to be written. A programmer can
determine the number of words that are shown by a comma and three periods.
Tetea)
Word
[Self-defined word)
{Optional word)Example 1.3: Optional Words
General Description:
DeFinition.Lines [{Line 1(, Line 2, ...1] As Line
Code in the macro:
Definition.Lines Center_Line
@ 1.3 Definition of Object, Class, and Object Path
CATScript is an object-oriented programming language, so in order to program CATScript
it is necessary to understand a few basic principles of an object-oriented language.
1.3.1 Object and Class
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).
Example 1.4: Properties and Methods of the “Line” Class
Properties: Start Point, End Point, Length (Read Only)
Methods: Sub Set _Start Point, Sub Set _End Point
Each object of the “Line” class hasa start point and an end point that can be assigned. The
length of a line can be read but not written. Both methods do not have an output parame
ter because they are subroutines.
1.3.2 Object Path
The classes of CATScript are hierarchically structured. A hierarchical structure has
parent and child classes. A parent class summarizes a group of child classes and provi-
des the basic methods and properties available for these classes. The deeper a class is.Tee eat omer
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:
ass hierarchy 0.Class hierarchy 1. ... .Class hierarchy n
Example 1.5: Object Path of Pads and Pockets
Class hierarchy n: Solid
Class hierarchy n+1: Contour-based Solid
Class hierarchy n+2: Pad, Pocket
Object Paths: . Solid.Contour-based Solid.Pad
.. Solid.Contour-based Solid. Pocket
‘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.
‘TABLE 1.3 Example of a Class Hierarchy
Ginger
fcc
Hierarchy n Solid
Hierarchy n+1 Contour-based Solid
Hierarchy n+2 Pad Pocket
1.3.3 Root Class and Base Classes
Accomplete 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.
TABLE 1.4 Root Class and Base Classes of CATScript,
Cine
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.
ee eee
5