0% found this document useful (1 vote)
540 views13 pages

RAND North America RAND North America: Exploring CATIA V5 Macros

Uploaded by

Sreedhar Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
540 views13 pages

RAND North America RAND North America: Exploring CATIA V5 Macros

Uploaded by

Sreedhar Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

RAND North America

Exploring CATIA V5 Macros


Jason Curtis, PLM Application Engineer

Professional Services • Training


g Programs
g • Technology
gy Solutions

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

• How do macros work?


• Dassault Systemes has “exposed” several CATIA objects so that
they can be created, manipulated, and deleted by COM
compliant applications
• Understanding this CATIA object structure is the key to being
able to automate many different aspects of CATIA V5

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

• Why all the dots? (.)


• The dot (.) character is simply a way to differentiate an object
from itit’ss properties or methods
methods.
• CATIA.Documents.Item(1).Name

rand-na.com
6
Developing new code

• Copy from existing program that already works.


This is the easiest way…
way
• Record a Macro in CATIA V5.
• Does NOT work for all functions/workbenches.
• Macros need to be “cleaned” because many times extra
code is produced which is not needed.
• If you need “Dim”
Dim statements, use CATScript when you
record, otherwise use MSVBScript.
• Use the Object Browser and other Help to develop
new code
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")

Dim iPoint As Object


Dim oInstance As ShapeInstance
F i = 1 tto oSel.Count2
For S lC t2
oFact.BeginInstanceFactory “Hole", "C:\Templates\Powercopies\Hole.CATPart"
oFact.BeginInstantiate
oFact.PutInputData "Point", iPoint
oFact.PutInputData
p “Surface”,, iSurface
Set oInstance = oFact.Instantiate
oFact.EndInstantiate
oFact.EndInstanceFactory
oPart.Update()
N t
Next

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

• Be sure that you understand how to do something


interactively in CATIA V5 BEFORE you try to
automate it through scripting
• Use some form of “standards” in naming g variables,
either company standards or Microsoft standards –
this will help greatly in debugging code and in
transferring and reusing code for other applications
• Set up and keep a “library” of standard functions
(i.e. starting CATIA, creating a Part Document,
selecting elements, etc.)

rand-na.com
12
RAND North America

Thank you!

Professional Services • Training


g Programs
g • Technology
gy Solutions

13
© 2008 RAND North America. All rights reserved. rand-na.com
rand-na.com

You might also like