Escolar Documentos
Profissional Documentos
Cultura Documentos
12/2/2003
Slide 2
Working with the CATIA / VB Interface
è CATIA V5 Automation Approaches
– Macros / .CATScripts
¬ Free, Rapid Deployment, Easy to Reuse Recorded
macros, Limited Flexibility, Difficult to Debug
– VBA / .CATvba
¬ Free, Graphical User interface (Forms), Editor Provides
Debugging Capability
– VB6 & VB.NET
¬ Runs Outside of CATIA, Increased Implementation of
Components and Type Libraries, Individual Module Files
Makes Collaboration and Sharing Code Easier
– CAA
¬ More Powerful and Faster than VB, Harder to Learn,
Provides Access to Interfaces Not Currently Available to
Visual Basic
12/2/2003
Slide 3
Working with the CATIA / VB Interface
è Automation Versus CATIA V5 Knowledgeware
– Knowledgeware Products
¬ Pros: Integrated Into CATIA, Persistent, Supported and
Documented by Dassault.
¬ Cons: Complex Models Difficult to Maintain, Lacks
Debugging Help, Requires Additional Licenses.
– Automation Using Visual Basic
¬ Pros: External to CATIA, Graphical User Interface,
Coding Editor, Functions Without Existing Seed Model,
Supports Large Complex Applications.
¬ Cons: Not Persistent, All CATIA Functionality Not
Exposed, Limited Applicable Documentation.
– Combining Both Approaches
¬ With Some Creativity, You can Get The Best Of Both
Worlds to Produce Efficient and Powerful Applications.
12/2/2003
Slide 4
Working with the CATIA / VB Interface
12/2/2003
Slide 5
Working with the CATIA / VB Interface
è Recording Macro Demo
– Tools / Macro / Start Recording…
– Macro Libraries:
Directories – folder location to store recorded macros
VBA Products – recorded code inserted into VBA project
– Language Used :
MS VBScript – does not include dim statements
CATScript – includes dim statements (preferred)
12/2/2003
Slide 6
Working with the CATIA / VB Interface
Creating RUG Demo
è Start Recording Macro (CATScript)
– Open New CATPart
– Create Three (3) Closed
Sketches on XY Plane
– Create Three (3) Pads
From Sketches
– Apply Graphic Color To
The Pads
– No Show the Origin Planes
– Apply “Fit-All-In” Button
to Reframe Pads
è Stop Recording Macro
12/2/2003
Slide 7
Working with the CATIA / VB Interface
è Let’s Look At The Recorded Code
– Open text-file using built-in editor or use any simple text editor
(such as WinWord).
– Lines that begin with ‘ have been manually added. These lines
are called comment lines and are skipped during runtime.
– All measurements are in millimeters and not inches (multiply or
divide by 25.4 to convert).
– Lines containing “ReportName” have no discernable function
and can be safely deleted.
– Sometimes the recording of a particular operation will be blank.
This does not necessarily mean that coding is impossible, just
more challenging.
– Tip: You must exit a sketch before stopping the recording or else
the macro will be blank.
12/2/2003
Slide 8
Working with the CATIA / VB Interface
è Let’s Look At The Modified Code
– Additional comment lines have been added.
– The code responsible for creating geometry in all three sketches
have been replaced with new code that creates customized
geometry.
– Lines containing “ReportName” have been deleted.
– A section of code has been re-written (condensed) into more
efficient code.
– Since the as-recorded code did not record applying colors to the
pads and no-showing the origin planes, the appropriate code
has been inserted here.
– To tweak the orientation of each completed pad, the values
assigned to the ‘SetAbsoluteAxisData’ array for each sketch was
modified. (advanced topic).
12/2/2003
Slide 9
Working with the CATIA/ VB Interface
è Introduction to Automation Objects in CATIA V5
Dim documents1 As Documents
Set documents1 = CATIA.Documents
12/2/2003
Slide 10
Working with the CATIA/ VB Interface
è Introduction to Automation Objects in CATIA V5
Dim documents1 As Documents
Set documents1 = CATIA.Documents
12/2/2003
Slide 11
Working with the CATIA/ VB Interface
è Recorded Macro Can Be Coded More Efficiently
Dim reference1 As Reference As Recorded Code:
Set reference1 = part1.CreateReferenceFromName("") Creates Generic Pad;
Dim pad1 As Pad Then Assigns Sketch
Set pad1 = shapeFactory1.AddNewPadFromRef(reference1, 20.000000) and Length Parameters.
Dim reference2 As Reference
Set reference2 = part1.CreateReferenceFromObject(sketch1)
pad1.SetProfileElement reference2
length1.Value = 2.540000
12/2/2003
Slide 12
Working with the CATIA/ VB Interface
è Reference CATIA Automation Documentation
For Shape Factory Methods
12/2/2003
Slide 13
Working with the CATIA/ VB Interface
è Become Familiar With The Selection Object
The Selection Object Has a Property Called VisProperties that manages the
graphical properties of all elements in the current selection.
'APPLY COLORS
CATIA.ActiveDocument.Selection.Clear
CATIA.ActiveDocument.Selection.Add pad1
CATIA.ActiveDocument.Selection.Add pad2
CATIA.ActiveDocument.Selection.VisProperties.SetRealColor 151, 150, 155, 0
CATIA.ActiveDocument.Selection.Clear
CATIA.ActiveDocument.Selection.Add pad3
CATIA.ActiveDocument.Selection.VisProperties.SetRealColor 50, 78, 139, 0
The Selection Object is Extremely Important When Working With User Interfaces
12/2/2003
Slide 14
Working with the CATIA / VB Interface
12/2/2003
Slide 15
Working with the CATIA / VB Interface
12/2/2003
Slide 16
Working with the CATIA / VB Interface
Tools > Macro > Visual Basic Editor (Alt + F11)
12/2/2003
Slide 17
Working with the CATIA / VB Interface
è A VBA Project is made up of a set of
components that eventually compile into a
single application
– Forms
– Modules
– Class Modules
è There must be a CATMain subroutine used as a
start-up procedure
è Expanded power and flexibility – and the best
part…ITS FREE
12/2/2003
Slide 18
Working with the CATIA / VB Interface
è VBA Project - Form
– An encapsulated, visual interface
containing a set of controls which
allow the user to interact with the
application
– Event Driven
¬ Click, DoubleClick, Initialize,
GotFocus Events
¬ Use events to run specific code
and/or change the look and feel of
the form
– Can contain form-level declaration
of Variables, Functions, or
Procedures
– Code in a form is usually specific
to the application using the form
12/2/2003
Slide 19
Working with the CATIA / VB Interface
è VBA Project - Module
– A container for code in the form
of Subroutines or Functions
– Can contain Global or Module-
level declarations of Variables,
Constants, or Procedures
– Code without external
dependencies can be used
regardless of the application
containing the module
12/2/2003
Slide 20
Working with the CATIA / VB Interface
Insert > UserForm Insert > Module Paste Script
into Module1
12/2/2003
Slide 21
Working with the CATIA / VB Interface
è Create an input form
Text Box
Change Name
Property
Command Button
Label
(Double Click Here to add code)
Drag Controls
onto the Form
12/2/2003
Slide 22
Working with the CATIA / VB Interface
è Write the code that executes when the button is clicked
Define a
variable for the
Pad Thickness
12/2/2003
Slide 23
Working with the CATIA / VB Interface
è Modify existing script Create CATMain routine
to display the form
Customize
Name Property
Rename Script
Routine and Add a
Passed in Argument
12/2/2003
Slide 24
Working with the CATIA / VB Interface
è Replace Hard Code thickness values with a variable
Insert Variable
Name (Convert
to mm)
12/2/2003
Slide 25
Working with the CATIA / VB Interface
è Some Variables must be late-bound in a VBA Project
12/2/2003
Slide 26
Working with the CATIA / VB Interface
12/2/2003
Slide 27
Working with the CATIA / VB Interface
Hands On Summary
è Macros / .CATScripts
– Great tools for rapid deployment of simple automation
applications
– Personal time saving operations
– They are limited in scope and flexibility.
è VBA Projects
– Offer increased flexibility and complexity through
implementation of user interface forms and modules
– Requires a short learning curve
12/2/2003
Slide 28
QUESTIONS:
12/2/2003
Slide 29