rand north america - squarespacewayne-rumsey.squarespace.com/s/macro_automation.pdf · rand north...
TRANSCRIPT
RAND North AmericaRAND North America
Exploring CATIA V5 MacrosJason Curtis, PLM Application EngineerJason Curtis, PLM Application Engineer
Professional Services • Training Programs • Technology SolutionsProfessional Services • Training Programs • Technology Solutionsg g gyg g gy
rand-na.com1
© 2008 RAND North America. All rights reserved. rand-na.com
Macros in CATIA V5
• CATIA V5 on Windows• CATIA V5 on Windows• Can be automated with a with any application which can connect to
Windows COM Objects:
• VBA (Excel Word CATIA etc )VBA (Excel, Word, CATIA, etc.)• VBScript• JavaScript
Vi l B i 6 0• Visual Basic 6.0• Microsoft Visual Studio.NET• others
• CATIA V5 on UNIX• Emulators allow for VBScripts to be run (no interface building tools)
rand-na.com2
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• Understanding this CATIA object structure is the key to being able to automate many different aspects of CATIA V5
VB/External Application
Type libraries (* tlb)
Dynamic Link Libraries (* dll)
Action performed in Application (*.tlb) Libraries (*.dll) p
CATIA
rand-na.com3
Introduction
• Rules• Visual Basic (or other applications) MUST• 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 tl 40 f th t• There are currently over 40 of these type 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.com4
Object Oriented Programming
• Definitions• COM (Component Object Model) – The Microsoft standardCOM (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.com5
Object Oriented Programming
• Declaring variables• All objects that are used in VB need to be “declared”• All objects that are used in VB need to be 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” keywordDim intCounter As IntegerintCounter = 32
• Why all the dots? (.)• The dot (.) character is simply a way to differentiate an object
from it’s properties or methodsfrom it s properties or methods.• CATIA.Documents.Item(1).Name
rand-na.com6
Developing new code
• Copy from existing program that already works. This is the easiest wayThis is the easiest 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” statements, use CATScript when youIf you need Dim statements, use CATScript when you
record, otherwise use MSVBScript.
• Use the Object Browser and other Help to develop new codenew code.
rand-na.com7
Creating Macros
• In-process• The script interpretation is performed using the
scripting engine(s) hosted by CATIA• MS VBScriptMS VBScript• CATScript• VBA (intelli-sense)
• Out-process• Performed from another application running in
th (MS W d/E l VB N t t )another process (MS Word/Excel, VB.Net, etc.)• Must access CATIA through tlb’s
• Example: CATIA Caption• Example: CATIA Caption
rand-na.com8
Recording Macros
• In-process only• DON’T: Switch workbenches while recording a
macro.• DON’T: Record more than is absolutely necessary.DON T: Record more than is absolutely necessary.• DON’T: Use the UNDO button when recording a
macro.DO B f CATS tti h di• DO: Be aware of CATSettings when recording.
• DO: Exit sketches before stopping recording.• DO: Check each macro after it’s recorded.O C ec eac ac o a te t s eco ded
• Example: “New Part” Dialog box
rand-na.com9
Simplifying Macros
• Powercopies• Macros can reference and use powercopies• Many powercopies can be used together
Dim oFactSet oFact = oPart.GetCustomerFactory("InstanceFactory")
Dim iPoint As ObjectDim oInstance As ShapeInstanceF i 1 t S l C t2For i = 1 to oSel.Count2
oFact.BeginInstanceFactory “Hole", "C:\Templates\Powercopies\Hole.CATPart"oFact.BeginInstantiateoFact.PutInputData "Point", iPointoFact.PutInputData “Surface”, iSurfacep ,Set oInstance = oFact.InstantiateoFact.EndInstantiateoFact.EndInstanceFactoryoPart.Update()
N tNext
rand-na.com10
Extending Capabilities
• Powercopies• Powercopies/Reactions can run macros• Knowledge advisor Rules, Reactions, Checks,
etc can be included in powercopiesetc. can be included in powercopies
Tips & Tricks
• Be sure that you understand how to do something interactively in CATIA V5 BEFORE you try tointeractively in CATIA V5 BEFORE you try to automate it through scripting
• Use some form of “standards” in naming variables, geither company standards or Microsoft standards –this will help greatly in debugging code and in transferring and reusing code for other applicationstransferring 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.com12
RAND North AmericaRAND North America
Thank you!
Professional Services • Training Programs • Technology SolutionsProfessional Services • Training Programs • Technology Solutionsg g gyg g gy
rand-na.com13
© 2008 RAND North America. All rights reserved. rand-na.com