RAND North America RAND North America: Exploring CATIA V5 Macros
RAND North America RAND North America: Exploring CATIA V5 Macros
1
© 2008 RAND North America. All rights reserved. rand-na.com
rand-na.com
Macros in CATIA V5
• CATIA V5 on Windows
• Can be automated with a with any application which can connect to
Windows COM Objects:
• VBA (Excel,
(Excel Word
Word, CATIA
CATIA, etc.)
etc )
• VBScript
• JavaScript
• Vi
VisuallB
Basic
i 6
6.0
0
• Microsoft Visual Studio.NET
• others
• CATIA V5 on UNIX
• Emulators allow for VBScripts to be run (no interface building tools)
rand-na.com
2
Introduction
Action
VB/External Type libraries Dynamic Link
p
performed in
Application (* tlb)
(*.tlb) Libraries (*.dll)
(* dll)
CATIA
rand-na.com
3
Introduction
• Rules
• Visual Basic (or other applications) MUST
reference type library files that make the
application “aware” of all of the CATIA
functions that have been exposed.
• Th
There are currently
tl over 40 off th
these ttype
libraries – they are broken up by discipline (i.e.
surface design, part design, etc.).
• Only the type library for the discipline that you
are going to use should be created.
• The type libraries are changed with each
release of CATIA V5, so the correct type
libraries MUST be used with the correct
version of CATIA V5.
• Not all CATIA V5 functions have been exposed
in the type libraries.
rand-na.com
4
Object Oriented Programming
• Definitions
• COM (Component Object Model) – The Microsoft standard
technology to share objects between applications.
• Object – An entity (in CATIA or VB). Points, Pads, Parameters,
etc. are all examples of CATIA objects.
• Property – A characteristic of an object. For example, the name
of a PartDocument is a property of that object.
• Method – An action that an object can perform. For example
PartDocument.SaveAs() is an action that the object can perform.
• Collection – A group or list of similar objects which are put
together for a specific reason.
rand-na.com
5
Object Oriented Programming
• Declaring variables
• All objects that are used in VB need to be “declared”
declared .
• “Dim objPartDoc As PartDocument”
• Setting variables
• Once an object is declared, it must also be “Set” to an instance of
the object before it can be used.
• “Set objPartDoc = CATIA.ActiveDocument”
• To give a value to a variable that is not an “object”, you cannot
use the “Set” keyword
Dim intCounter As Integer
intCounter = 32
rand-na.com
6
Developing new code
rand-na.com
7
Creating Macros
• In-process
• The script interpretation is performed using the
scripting engine(s) hosted by CATIA
• MS VBScript
• CATScript
• VBA (intelli-sense)
• Out-process
• Performed from another application running in
another
th process (MS Word/Excel,
W d/E l VB.Net,
VB N t etc.)
t )
• Must access CATIA through tlb’s
• Example: CATIA Caption
rand-na.com
8
Recording Macros
• In-process only
• DON’T: Switch workbenches while recording a
macro.
• DON
DON’T:
T: Record more than is absolutely necessary.
• DON’T: Use the UNDO button when recording a
macro.
• DO:
DO Be
B aware off CATSettings
CATS tti when
h recording.
di
• DO: Exit sketches before stopping recording.
O C
• DO: Check
ec eac
each macro
ac o a
after
te it’s
t s recorded.
eco ded
• Example: “New Part” Dialog box
rand-na.com
9
Simplifying Macros
• Powercopies
• Macros can reference and use powercopies
• Many powercopies can be used together
Dim oFact
Set oFact = oPart.GetCustomerFactory("InstanceFactory")
rand-na.com
10
Extending Capabilities
• Powercopies
• Powercopies/Reactions can run macros
• Knowledge advisor Rules, Reactions, Checks,
etc can be included in powercopies
etc.
Tips & Tricks
rand-na.com
12
RAND North America
Thank you!
13
© 2008 RAND North America. All rights reserved. rand-na.com
rand-na.com