Académique Documents
Professionnel Documents
Culture Documents
m
Al ple
lc p
op ro
yi vid
ng e
d
an b
d yA
re S
Cover Page
us C
2nd Edition
e EN
Student Guide
st T
ric fo
tly r
CATIA V5-6R2016:
fo rev
rb ie
Visual Basic Automation
id w
de o
n. nly
Sa
m
Al ple
lc p
op ro
yi vid
ng e
d
an b
d yA
re S
us C
e EN
st T
ric fo
tly r
fo rev
rb ie
id w
de o
n. nly
ASCENT - Center for Technical Knowledge®
CATIA V5-6R2016: Visual Basic Automation
2nd Edition
Prepared and produced by:
ASCENT Center for Technical Knowledge
n. nly
630 Peter Jefferson Parkway, Suite 175
Charlottesville, VA 22911
de o
866-527-2368
www.ASCENTed.com
id w
Copyright
rb ie
ASCENT - Center for Technical Knowledge is a division of Rand Worldwide, Inc., providing custom
developed knowledge products and services for leading engineering software applications. ASCENT is
fo rev
focused on specializing in the creation of education programs that incorporate the best of classroom
learning and technology-based training offerings.
We welcome any comments you may have regarding this student guide, or any of our products. To contact
tly r
ric fo
us please email: feedback@ASCENTed.com.
st T
All rights reserved. No part of this guide may be reproduced in any form by any photographic, electronic,
e EN
mechanical or other means or used in any information storage and retrieval system without the written
permission of ASCENT, a division of Rand Worldwide, Inc.
us C
CATIA and ENOVIA are registered trademarks of Dassault Systèmes.
re S
All other brand names, product names, or trademarks belong to their respective holders.
d yA
General Disclaimer:
Notwithstanding any language to the contrary, nothing contained herein constitutes nor is intended to
constitute an offer, inducement, promise, or contract of any kind. The data contained herein is for
an b
informational purposes only and is not represented to be error free. ASCENT, its agents and employees,
expressly disclaim any liability for any damages, losses or other expenses arising in connection with the use
d
of its materials or in connection with any failure of performance, error, omission even if ASCENT, or its
representatives, are advised of the possibility of such damages, losses or other expenses. No consequential
ng e
damages can be sought against ASCENT or Rand Worldwide, Inc. for the use of these materials by any third
yi vid
professional advice, nor does it constitute a comprehensive or complete statement of the issues discussed
thereto. ASCENT does not warrant that the document or information will be error free or will meet any
lc p
particular criteria of performance or quality. In particular (but without limitation) information may be rendered
inaccurate by changes made to the subject of the materials (i.e. applicable software). Rand Worldwide, Inc.
Al ple
specifically disclaims any warranty, either expressed or implied, including the warranty of fitness for a
particular purpose.
m
Sa
AS-56CAT16-VBA2-SG // RS-56CAT16-VBA2-SG
Sa
m
Al ple
lc p
op ro
yi vid
ng e
d
an b
d yA
re S
us C
e EN
st T
ric fo
tly r
fo rev
rb ie
id w
de o
n. nly
C o n t e n ts
n. nly
de o
id w
rb ie
fo rev
Preface ........................................................................................................... vii
tly r
ric fo
Practice Files .................................................................................................. xi
st T
Chapter 1: Fundamentals............................................................................. 1-1
e EN1.1 Visual Basic Evolution.................................................................... 1-2
CATIA Automation Platforms ............................................................ 1-2
us C
1.2 VB6 ................................................................................................... 1-3
re S
n. nly
3.2 Macro Libraries ............................................................................... 3-3
de o
3.3 Recording or Replaying Macros .................................................... 3-4
id w
3.4 Viewing or Editing Macros ............................................................. 3-5
Interpreting Macro Recordings.......................................................... 3-6
rb ie
Replaying a Macro ............................................................................ 3-7
fo rev
Executing a Macro on CATIA startup................................................ 3-7
Macros with Parameters ................................................................... 3-8
3.5 Assigning a Macro to a Toolbar..................................................... 3-9
tly r
ric fo
Practice 3a Square Pad with Parameters........................................... 3-10
st T
Practice 3b Series of Round Pads ...................................................... 3-16
e EN
Chapter 4: Introduction to VBA ................................................................... 4-1
4.1 Overview .......................................................................................... 4-2
us C
4.10 Late Binding when Calling some CATIA Methods ..................... 4-12
Practice 4a Simple User Form with Controls..................................... 4-13
m
n. nly
6.4 HybridBodies Collection ................................................................ 6-5
Practice 6a Working with Part Infrastructure ...................................... 6-6
de o
id w
Chapter 7: Part Design Automation ............................................................ 7-1
rb ie
7.1 Part Design Object Diagram........................................................... 7-2
Types of Shape Objects.................................................................... 7-3
fo rev
7.2 Sketch Object Diagram................................................................... 7-4
7.3 Creating Sketches........................................................................... 7-5
tly r
ric fo
Creating Sketch Geometry................................................................ 7-5
Creating Sketch Constraints ............................................................. 7-6
st T
7.4 Creating Solid Features.................................................................. 7-7
e EN
7.5 Reference Object............................................................................. 7-8
7.6 In Work Object and Part Update .................................................... 7-9
us C
n. nly
10.3 Drawing View Object Diagram ..................................................... 10-5
de o
10.4 GenerativeBehaviour Object........................................................ 10-6
id w
10.5 Creating Generative Views........................................................... 10-7
rb ie
View Projection Plane and Direction ............................................... 10-8
View Positioning.............................................................................. 10-9
fo rev
10.6 Creating Dimensions .................................................................. 10-10
10.7 Creating Annotations.................................................................. 10-11
tly r
Drawing Text Object...................................................................... 10-12
ric fo
Drawing Table Object.................................................................... 10-13
st T
10.8 Creating Non-Generative Geometry .......................................... 10-15
e EN
10.9 Creating Frame and Title Block ................................................. 10-16
Frame and Title Block Macros ...................................................... 10-16
us C
Creating Frame and Title Block..................................................... 10-17
re S
n. nly
Practice 13a Copying and Pasting between Parts ............................ 13-5
de o
Chapter 14: Parameters and Formulas..................................................... 14-1
id w
14.1 Parameters and Relations Collections........................................ 14-2
rb ie
14.2 Parameters Object Model ............................................................. 14-3
fo rev
14.3 Creating Parameters ..................................................................... 14-4
14.4 Valuating Parameters ................................................................... 14-5
tly r
14.5 Working with Units........................................................................ 14-6
ric fo
14.6 Relations Object Model ................................................................ 14-7
st T
14.7 Creating Relations ........................................................................ 14-8
e EN
Practice 14a Measuring Spline Length using Formula..................... 14-9
us C
Chapter 15: Communication with Microsoft Office ................................. 15-1
re S
n. nly
Practice A16 Practice A16 ................................................................... A-42
Practice A17 Practice A17 ................................................................... A-44
de o
Practice A18 Practice A18 ................................................................... A-46
id w
rb ie
fo rev
tly r
ric fo
st T
e EN
us C
re S
d yA
an b
d
ng e
yi vid
op ro
lc p
Al ple
m
Sa
n. nly
de o
id w
rb ie
fo rev
The CATIA V5-6R2016: Visual Basic Automation student guide provides you a
good understanding of the different ways to automate tasks using CATIA macros
and Visual Basic programming. Using hands-on practices, you will use VB
tly r
programming to work with parts, assemblies, drawings, selections, parameters
ric fo
and formulas, graphic properties, and to exchange data with Microsoft Excel.
st T
Topics Covered:
e EN
• CATIA V5 Object Model
us C
• Creating Part Design and Shape Design features
re S
d yA
• Interactive Selections
yi vid
This student guide assumes a standard installation of the software using the
Al ple
default preferences during installation. Lectures and practices use the standard
software templates and default options for the Content Libraries.
m
n. nly
de o
id w
rb ie
fo rev
tly r
ric fo
st T
e EN
us C
re S
d yA
an b
d
ng e
yi vid
op ro
lc p
Al ple
m
Sa
n. nly
de o
id w
rb ie
fo rev
The following images highlight some of the features that can be found in this
Student Guide.
tly r
ric fo
st T
e EN
us C
Practice Files
re S
Chapters
Sa
n. nly
Instructional Content
Each chapter is split into a
series of sections of
de o
instructional content on specific
id w
topics. These lectures include
the descriptions, step-by-step
rb ie
Side notes procedures, figures, hints, and
Side notes are hints or information you need to achieve
fo rev
additional information for the chapter's Learning
the current topic. Objectives.
tly r
ric fo
st T
e EN
us C
Practice Objectives
re S
Practices
d yA
Files page.
op ro
lc p
Al ple
m
Sa
n. nly
de o
id w
rb ie
fo rev
Fundamentals
tly r
ric fo
Learning Topics in this Chapter
st T
•
•
e EN
Visual Basic Evolution
VB6
• VBA
us C
• VBScript and CATScript VB.NET
re S
• VB.NET
d yA
n. nly
de o
id w
rb ie
Figure 1–1
fo rev
• The B.A.S.I.C. (Beginner's All-purpose Symbolic
Instruction Code) is a programming language that was
originally designed in 1963.
tly r
ric fo
• Visual Basic is Microsoft's dialect of BASIC including
controls, events, and IDE. It was very popular in 1980s
st T
and 1990s. CATIA V5 Automation was originally designed
e EN for VBScript, VBA, and VB6.
• VB.NET is a completely reworked version of VB. It
replaces VB6, which Microsoft no longer officially
us C
supports. However, it does not replace VBA or VBScript,
re S
obsolete.
d
ng e
CATIA
yi vid
Automation
op ro
Platforms
lc p
Al ple
m
Sa
Figure 1–2
1.2 VB6
Visual Basic 6 (VB6) is an event-driven programming platform
and an associated integrated development environment (IDE) for
building graphical user interfaces (GUI) in the Microsoft
n. nly
Component Object Model (COM) programming model.
de o
Event-driven In event-driven programming, the flow of the program is
id w
determined by user actions (i.e., mouse clicks, key presses,
Programming
rb ie
etc.), or messages from other programs, as shown in Figure 1–3.
fo rev
tly r
ric fo
st T
e EN
us C
re S
d yA
an b
d
ng e
yi vid
Figure 1–3
op ro
lc p
Al ple
m
Sa
n. nly
de o
id w
rb ie
fo rev
tly r
ric fo
st T
e EN
us C
Figure 1–4
re S
d yA
in Figure 1–5.
ng e
yi vid
op ro
lc p
Al ple
m
Sa
Figure 1–5
GUI (Graphical GUI (Graphical User Interface) is a type of user interface that
enables you to interact with the computer using graphical
User Interface) elements (i.e., toolbars, icons, visual indicators, texts, labels,
etc.), which represent the available information and actions. The
actions are usually performed through direct manipulation of the
n. nly
graphical elements, as shown in Figure 1–6.
de o
id w
rb ie
fo rev
tly r
ric fo
st T
e EN
us C
re S
d yA
an b
d
ng e
yi vid
op ro
Figure 1–6
lc p
Al ple
Figure 1–7
n. nly
Codes for COM objects or components are stored in DLL
libraries and registered in the Windows registry. Therefore, they
de o
can be called, initiated, or created at any time.
id w
For example, if object A calls object B, object A is then the client
rb ie
and object B is the server (the one that provides services to the
fo rev
client). The client does not have to know the functions or
methods (i.e., interface) that the server contains in advance.
COM provides for a way to figure that out during the runtime.
tly r
This is called late binding. If the client is made aware of the
ric fo
server's interface before it is run, this is called early binding.
st T
e EN
us C
re S
d yA
an b
d
ng e
yi vid
op ro
lc p
Al ple
m
Sa
1.3 VBA
The VB6 environment can be hosted in another application, such
as Excel, Word, CATIA, etc. and is event-driven and
GUI-oriented. It has full IDE (i.e., it contains an editor, debugger,
n. nly
type checker, object browser, etc.) as shown in Figure 1–8.
However, it cannot run without the host application running. The
de o
software can only be interpreted (i.e., executed line-by-line), and
might be slower than a compiled VB application.
id w
rb ie
fo rev
tly r
ric fo
st T
e EN
us C
re S
d yA
an b
d
ng e
yi vid
Figure 1–8
op ro
lc p
Al ple
m
Sa
n. nly
limited tool. It does not contain IDE, debugging etc., and regular
text editors are used for coding. It is non-GUI-oriented and only a
de o
couple of very simple interactive dialog boxes are available. It is
non-event-driven and its code represents a flow with a sequence
id w
of actions that is determined by the programmer.
rb ie
fo rev
• CATScript is a portable version of VBScript. CATScript
macros can run on Unix, as shown in Figure 1–9.
tly r
ric fo
st T
e EN
us C
re S
d yA
an b
d
ng e
yi vid
op ro
lc p
Al ple
m
Figure 1–9
Sa
1.5 VB.NET
VB.NET is the latest incarnation of the popular Microsoft
programming environment. It is also event-driven, has an
integrated development environment (IDE), and is used for
n. nly
building graphical user interfaces (GUI). However, it is not based
on COM (although it can call COM objects) and the syntax is
de o
quite different from VB6.
id w
The following difficulties are normally encountered when
rb ie
switching from VB6 to VB.NET:
fo rev
• New syntax
• New IDE
tly r
ric fo
• New GUI controls
st T
• New InstallShield
e EN When using VB.NET for CATIA automation, CATIA V5 is still a
us C
COM application. There is no change to how CATIA objects are
called and used.
re S
d yA
an b
d
ng e
yi vid
op ro
lc p
Al ple
m
Sa
n. nly
communicate with CATIA: as an in-process or out-of-process
application.
de o
id w
In-process The VB application runs within the CATIA process in the
rb ie
computer memory. No inter-process communication is involved.
Applications CATIA freezes while the VB application is running. The VB
fo rev
application's allocation memory is wiped out after each run.
Therefore, passing data between two subsequent runs is not
possible.
tly r
ric fo
• Use the Tools>Macros interface (VBScript, CATScript, or
VBA).
st T
e EN
Out-of-process The VB application runs in its own process in the computer
memory. It communicates with CATIA using inter-process
us C
Applications messaging. CATIA is fully active while the VB application is
re S
n. nly
CATIA. A VB application or macro can also locate and
communicate with CATIA objects.
de o
Since CATIA libraries might change from release to release, a
id w
VB application that is developed or compiled with one CATIA
rb ie
release might or might not run correctly with another CATIA
fo rev
release. For example, a VB application developed for V5R21
might not work correctly with V5-6R2012, etc. Therefore, it is
recommended that you have the correct CATIA release
tly r
registered before the VB application is used.
ric fo
If several CATIA releases are installed on a computer, registering
st T
a specific release can be done by executing the following
e EN command from the Command Prompt:
"C:\Program Files\Dassault
Systemes\B22\win_b64\code\bin\
d
ng e
n. nly
de o
id w
rb ie
fo rev
tly r
ric fo
st T
e EN
us C
re S
d yA
an b
d
ng e
yi vid
op ro
lc p
Al ple
m
Sa