
Transcription
CATIA V5 AutomationCATIA V5 TrainingStudent Notes:FoilsCopyright DASSAULT SYSTEMESCATIA V5AutomationCopyright DASSAULT SYSTEMESVersion 5 Release 19January 2009EDU CAT EN VBA AF V5R191
CATIA V5 AutomationAbout this courseStudent Notes:Objectives of the courseUpon completion of this course, you will be able to create automationscripts, programs, and macros in CATIA V5, using Visual Basic and otherautomation tools available in CATIA V5.Targeted audienceApplication developersPrerequisitesCopyright DASSAULT SYSTEMESStudents attending this course should have knowledge of CATIA V5Interactive and Visual BasicCopyright DASSAULT SYSTEMES8 hours2
CATIA V5 AutomationStudent Notes:Table of Contents (1/4)Introduction to CATIA V5 AutomationCATIA V5 Automation & Scripting: PresentationKnowledgeware, VB Automation, and CAASkills Required for CATIA V5 AutomationCATIA V5 Automation: Presentation (Windows only)Language Used for AutomationVB ScriptVBAVisual BasicCommunication Chart on WindowsDocumentationsInterface DocumentationCATIA V5 Association with File ExtensionCATIA V5 OLE (Object Linking and Embedding)CATIA V5 Scripting CapabilitiesCopyright DASSAULT SYSTEMESIn-Process MarcosWhat is an 'In-Process' MacroCATIA V5 Visual Basic EditorCopyright DASSAULT SYSTEMES7891011121315161718192122232425263
CATIA V5 AutomationStudent Notes:Table of Contents (2/4)Macro LibrariesRecording a MacroRunning a MacroExecution of a Macro from another MacroExecution of a Macro which Require ParametersAdding a Macro as a command in a ToolbarMacros Options InterfaceCopyright DASSAULT SYSTEMESOut-Process ProgramsRunning Out-Process Programs (On Windows only)Running Out-Process from VBA or Visual BasicExample: Bolt from ExcelRunning Out-Process using the Windows Scripting HostVBScript under Windows Scripting HostBoltVBSript.vbs ExampleJavaScript under Windows Scripting HostBoltJavaSript.js ExampleOut-Process in HTML (Windows & Microsoft IE Only)Out-Process in HTML with VBScriptCopyright DASSAULT SYSTEMES2728293132333435363740434445464748494
CATIA V5 AutomationStudent Notes:Table of Contents (3/4)Out-Process in HTML with JavaScriptVBA / VB Programming Basics51Programming GeneralitiesVBA / VB Common ControlsVB Programming Techniques525770Scripting with CATIA V5CATIA V5 Object ArchitectureScripting Infrastructure FeaturesScripting SketchesScripting Part Design FeaturesScripting Shape Design FeaturesScripting Assembly Design FeaturesScripting Drafting FeaturesAccessing ElementsCopyright DASSAULT SYSTEMES50Automatic SelectionsScanning the ContainersAccess to a Specific ElementGraphic SelectionsCopyright DASSAULT SYSTEMES7778951041071101131181221231241251265
CATIA V5 AutomationStudent Notes:Table of Contents (4/4)Graphic Selection using 'Selection'Graphic Selections using SelectElement2Creating Panels from MacrosInput boxPanels in an ActiveX component (Windows Only)Miscellaneous InformationObfuscating and Converting MacrosObfuscate VBScript MacrosMulti-Product SupportRegistering CATIA and Type LibrariesConverting a Macro to a Visual Basic ProgramConverting a Visual Basic programm to a CATIA MacroMacros on UNIX / WindowsCalling an other Automation Server137138142144145146147148149151152Copyright DASSAULT SYSTEMESCalling WSH from VBScriptCalling ExcelDrawing a Chart in EXCEL127129130131132133Copyright DASSAULT SYSTEMES6
CATIA V5 AutomationIntroduction to CATIA V5 AutomationStudent Notes:Copyright DASSAULT SYSTEMESYou will be introduced to various tools and capabilities related to CATIA V5 Automation.Copyright DASSAULT SYSTEMES7
CATIA V5 AutomationCATIA V5 Automation & Scripting: PresentationStudent Notes:On both Windows and UNIXThe scripting allows you to program CATIA in a very simple way with macros onboth Windows and UNIX platforms.CATIA uses the common part on MS-VBScript to have the same macros runningon both the platforms.Copyright DASSAULT SYSTEMESOn Windows platformsAutomation allows CATIA to share objects with other external applications suchas Word/Excel or Visual Basic programs.CATIA can use the Word/Excel objects as well as Word/Excel can use the CATIAObjects.Copyright DASSAULT SYSTEMES8
CATIA V5 AutomationKnowledgeware, VB Automation, and CAAStudent Notes:VB AutomationKnowledgewareNeeds CATIA licensesLow interaction with final user (no window interface)Based on geometryMay be integrated to VB AutomationCopyright DASSAULT SYSTEMESCAA V5Need licensesHigh skills in programming (C )Usually for specific-domain solutionCopyright DASSAULT SYSTEMES9
CATIA V5 AutomationSkills Required for CATIA V5 AutomationStudent Notes:VBA (Visual Basic for Applications) or Visual Basic 6 basicsBasic languageObject programmingEvent programmingKnowledge of the CATIA workbench in which you are going to programCopyright DASSAULT SYSTEMESInfrastructureSurfacesAnalysis etc.Copyright DASSAULT SYSTEMES10
CATIA V5 AutomationCATIA V5 Automation: Presentation (Windows only)Student Notes:Automation allows communication between several process.Visual Basic Script (for Macros)CATIA V5On WindowsInterfacesCOMVisual Basic ForApplications (for ex:Word/Excel)Visual BasicCOM (Component Object Model) is the “Microsoft” standard to share objects betweenseveral applications.Automation is a “Microsoft” technology to use COM objects in an interpreted environment.Copyright DASSAULT SYSTEMESActiveX component is a “Microsoft” standard to share objects between severalapplications even in an interpreted environment.OLE (Object Linking and Embedding) means that the document can be linked in thedocument of an other application OLE and can be edited in that other application (In placeediting).Copyright DASSAULT SYSTEMES11
CATIA V5 AutomationLanguage Used for AutomationStudent Notes:Copyright DASSAULT SYSTEMESThree possible languages:Visual Basic 6VBAVB Script / CATScriptCopyright DASSAULT SYSTEMES12
CATIA V5 AutomationVB Script (1/2)Student Notes:VBScript (Visual Basic Script) is a subset of VBA. It is a simple interpreted Basic languageOnly Windows/Unix « compatible » languageCan call CATIA ObjectsDirectly launchable from a saved macroCopyright DASSAULT SYSTEMESWeak help to programmingVery ‘light’ internal editorNo type is used. The system tries dynamically to call methods and properties ofobjects.Sequential programmingPoor User Interface toolsCopyright DASSAULT SYSTEMES13
CATIA V5 AutomationVB Script (2/2)Student Notes:Copyright DASSAULT SYSTEMESPoor User Interface : ExamplesMessage boxInput boxFile Selection BoxNo more Copyright DASSAULT SYSTEMES14
CATIA V5 AutomationStudent Notes:VBAVBA (Visual Basic for Applications) is a subset of Visual Basic. VBA is hosted inapplications such as Word, Excel or CATIA.Programming help« Event » ProgrammingCATIA drive from another VBAapplication (Excel, Word )Rich User Interface(buttons, lists, )Copyright DASSAULT SYSTEMESWeak protectionNot easy to export programNo « InstallShield » toolCopyright DASSAULT SYSTEMES15
CATIA V5 AutomationVisual BasicStudent Notes:Visual Basic is the full versionAll the advantages of VBA More extended set of instructionsCode protection (compiled program)Can create ActiveX and Serversprovides an added documentation called “Books on line” (VB 5.0)Packaging and deployment assistantCopyright DASSAULT SYSTEMESNeeds an additional installationMicrosoft licensed softwareCopyright DASSAULT SYSTEMES16
CATIA V5 AutomationStudent Notes:Communication Chart on WindowsMacros(VBScript)Panels in ActiveX(Windows)CATIA V5Copyright DASSAULT SYSTEMES*.VBS or *.JSVisual BasicIn-ProcessOut-ProcessCopyright DASSAULT SYSTEMESHTML-WSH Internet/IIS(VBScript- JavaScript)Word/Excel (VBA)17
CATIA V5 AutomationStudent Notes:DocumentationsJournaling guides for eachworkbenchesArchitectureConcepts, rules, samples .Copyright DASSAULT SYSTEMESUnderstandCopyright DASSAULT SYSTEMES18
CATIA V5 AutomationStudent Notes:Interface Documentation (1/2)Public InterfacesCopyright DASSAULT SYSTEMESUseCopyright DASSAULT SYSTEMES19
CATIA V5 AutomationInterface Documentation (2/2)Student Notes:Copyright DASSAULT SYSTEMESAdditional InformationThe documentation is also available in the CATIA code installation directory.Look for \Bxx\intel a\code\bin\V5Automation.chmand create a shortcut on your Desktop.In the documentation, you will find helpful ‘Use cases’.Copyright DASSAULT SYSTEMES20
CATIA V5 AutomationCATIA V5 Association with File ExtensionStudent Notes:A double-click in Windows Explorer on a ”.CATPart” file opens it in CATIA V5. On Windows,If CATIA V5 is not running, it is launched automatically.Copyright DASSAULT SYSTEMESDouble-click,Open, or press EnterIn the Windows Explorer, the “Details” section shows a preview for all CATIA Documents.Copyright DASSAULT SYSTEMES21
CATIA V5 AutomationCATIA V5 OLE (Object Linking and Embedding)Student Notes:Copyright DASSAULT SYSTEMESDrag and Drop inan OLE containerCopyright DASSAULT SYSTEMESA double-click on thepicture lets you edit thebolt in CATIA V522
CATIA V5 AutomationCATIA V5 Scripting CapabilitiesStudent Notes:IN process application:This is done from the Tools Macro in CATIA menu. When the Macro is running, CATIA isdeactivated. You cannot store variables in a macro between two calls. Access with VBScript(Microsoft) and VBA on Windows, and with VBScript (Winsoft) on Unix.OUT process application (Windows only)Copyright DASSAULT SYSTEMESThis is based on AUTOMATION. A foreign process can call CATIA, create or modifygeometry, decode, measure or pilot CATIA. CATIA is still running. For each action of theapplication, we have to check if CATIA is in the good state to synchronize the twoprocesses. This kind of applications can be developed in:Visual BasicWindows Scripting Host (VBScript , JScript)Windows Explorer HTML (VBScript , JScript)or Any other COM applications.Copyright DASSAULT SYSTEMES23
CATIA V5 AutomationIn-Process MacrosStudent Notes:Copyright DASSAULT SYSTEMESYou will learn how to record and run the In-Process macros.Copyright DASSAULT SYSTEMES24
CATIA V5 AutomationWhat is an ‘In-Process’ MacroStudent Notes:Copyright DASSAULT SYSTEMESWe call In-process because the script interpretation is performed in the sameprocess as CATIA.A list shows the Macro available. We can run, edit, rename or delete existing script, or create a newone.The list of libraries of script proposed into the panel above is modifiable through the window oflibraries.Copyright DASSAULT SYSTEMES25
CATIA V5 AutomationCATIA V5 Visual Basic EditorStudent Notes:Copyright DASSAULT SYSTEMESWith CATIA Visual BasicEditor, We can edit existingmacro or create a new one,Insert graphic form, debug andRun VBA project.Copyright DASSAULT SYSTEMES26
CATIA V5 AutomationMacro LibrariesStudent Notes:Copyright DASSAULT SYSTEMESThe interface of the dialog “Tools Macro Macros ” allows to choose a library of macro(a directory of macro or a VBA project) or a document on which we wish to work.From this window, we can close an already opened library, open a library, or create a library.Libraries are shown by type (directory, VBA project.).Every type of library supports different languages. VBA supports only the language MS-VBA,while in a directory we can write in MS-VBScript or in CATScript.Copyright DASSAULT SYSTEMES27
CATIA V5 AutomationRecording a MacroStudent Notes:Copyright DASSAULT SYSTEMESThe panel of recording VBA allows to choose the container in which we are going torecord, the used language and the name of the macro to be recorded.The syntax of the recorded script is going to differ according to the menu chosen.Recording a Macro generates a script corresponding to the creation or modification of theobjects in the recorded sequence. After stopping the recording, we can store, edit or replay thisscript (called macro).As a rule, recording a macro helps you to learn how to program something.Copyright DASSAULT SYSTEMES28
CATIA V5 AutomationRunning a Macro (1/2)Student Notes:You can execute a macro as soon as CATIA is started CATScriptE:\Users\Macros\MacroToRun.CATScriptYou can start CATIA in batch mode to execute a n.CATScriptCopyright DASSAULT SYSTEMESYou can run a macro interactively from the “Macro” menuYou can run a macro interactively from an icon in a toolbarCopyright DASSAULT SYSTEMES29
CATIA V5 AutomationStudent Notes:Running a Macro (2/2)The syntax to execute macros in text files using the CNEXT -macro command line, hasbeen expanded to allow replaying macro which are in VBA projects, in V5 documents,and are written in VBScript, CATScript or VBA.Here is a complete summary of the Supported Syntax:Previously available options:CNEXT -macro X.CATScript// Replays file X.CATScript (CATScript file)CNEXT -macro X.catvbs// Replays file X.catvbs (pure VBScript file)// Replays macro Y in the VBA project X.catvba// Replays macro Y in the V5 document X.CATPartCopyright DASSAULT SYSTEMESNew options:CNEXT -macro X.catvba YCNEXT -macro X.CATPart YCopyright DASSAULT SYSTEMES30
CATIA V5 AutomationExecution of a Macro from another MacroStudent Notes:CATIA V5 offer the capability through an Automation function to execute a Macro from anotherMacro. The function lets the user invoke another scripted function, contained in another macrolibrary, potentially written in another scripting language. A support enum CATSysLibraryType isused to let the developer describe the kind of library the function to call is contained in.(Example from VBScript)To call an Add function that is defined in a “E:\Macros\Math” directory library, in a file“IntegerMath.catvbs”, one would write:Copyright DASSAULT SYSTEMESDimDimargs2(1)args2(1)args2(0)args2(0) 33args2(1)args2(1) 22DimDimaddResultaddResultaddResultaddResult ce.ExecuteScript( rgs2args2) )MsgBoxMsgBoxaddResultaddResultTo call an PrintReport() sub that is defined in a “E:\Parts\Part1.CATPart” V5 document library,in a file “Statistics.catvbs”, one would tvbs", "PrintReport", argsCopyright DASSAULT SYSTEMES31
CATIA V5 AutomationExecution of a Macro which Require ParametersStudent Notes:CATIA V5 gives the possibility to add parameters to the CATMain function.When the function is executed, an interactive window pops up which lets the user value theparameters by selecting V5 objects or typing the values directly. Parameters of type string, int,float, boolean and object can be entered.If the user writes the following VBScript eight)SetpartDocument1Set partDocument1 1part1 tory1shapeFactory1 part1.ShapeFactorypart1.ShapeFactorySetpad1Set pad1 EndEndSubSubCopyright DASSAULT SYSTEMESand runs it, the following window pop up automaticallyto let him/her enter the value of the sketch and heightparameters.Copyright DASSAULT SYSTEMES32
CATIA V5 AutomationAdding a Macro as a command in a ToolbarStudent Notes:Select the macro you want to add in Tools Customize Commands Tab page Macros:Drag and Drop the macro nameto the toolbar you wish :Copyright DASSAULT SYSTEMESTo select another icon than the default one,click on Show Properties.Copyright DASSAULT SYSTEMES33
CATIA V5 AutomationMacros Options InterfaceStudent Notes:Copyright DASSAULT SYSTEMESThe panel of the dialog “Tools Options Macros” allows to choose according to the language,the Editor who will be launched to edit a macro, and to specify external typelibs to take intoaccount in the replay of scripts.With the new interface, all the typelibs V5 of the runtime view are automatically taken intoaccount. This option serves only for declaring typelibs except runtime view (Excel for example).Copyright DASSAULT SYSTEMES34
CATIA V5 AutomationOut-Process ProgramsStudent Notes:Copyright DASSAULT SYSTEMESYou will learn methods to create and execute Out-Process programs for CATIA V5Automation.Copyright DASSAULT SYSTEMES35
CATIA V5 AutomationRunning Out-Process Programs (On Windows only)Student Notes:The script is running in another application running in another process, such as:Visual BasicVBA (in Excel or Word)Using WSH (Windows Scripting Host) with VBScript or JavaScriptUsing HTML with VBScript or JavaScriptCopyright DASSAULT SYSTEMESCATIA can be scripted from any other COM Application.Copyright DASSAULT SYSTEMES36
CATIA V5 AutomationRunning Out-Process from VBA or Visual Basic (1/3)Student Notes:Copyright DASSAULT SYSTEMESVBA and Visual Basic provide useful tools :For this, you can declare all the typelib files (*.tlb) provided by Dassault Systemes.The typelib files contain the declarations of all the objects, methods and properties of theExposed objects.Copyright DASSAULT SYSTEMES37
CATIA V5 AutomationRunning Out-Process from VBA or Visual Basic (2/3)Student Notes:Copyright DASSAULT SYSTEMESType definition allows type checking and “early binding”.Helpful completion gives you all the properties and methods of an object and givesyou the argument types of a method.Browser Object describes all the exported objects.Copyright DASSAULT SYSTEMES38
CATIA V5 AutomationRunning Out-Process from VBA or Visual Basic (3/3)Student Notes:Here are the statements to launch CATIA V5 from VBA or Visual Basic.If CATIA is already running :[.][.]DimDimCATIACATIAasasObjectObjectSetCATIA GetObject(,Set CATIA ation”)[.][.]First arg. is left blankCopyright DASSAULT SYSTEMESIf CATIA is not already running :[.][.]DimDim CATIACATIA asas ObjectObjectSetSet CATIACATIA “CATIA.Application”)CATIA.VisibleCATIA.Visible TrueTrueThis macro starts CATIA[.][.]If the typelib INFITF.tbl is referenced, we can declare CATIA as INFITF.Application.Copyright DASSAULT SYSTEMES39
CATIA V5 AutomationStudent Notes:Example: Bolt from Excel (1/3)1Start a New ExcelDocument and activate thetoolbars:Forms and Visual Basic.2Activate theDesign mode.3Copyright DASSAULT SYSTEMESCreate a new Button and click on“New” button to “Assign Macro”.Copyright DASSAULT SYSTEMES40
CATIA V5 AutomationExample: Bolt from Excel (2/3)Student Notes:1You go automatically inVisual Basic.Insert the Code from the file“BoltFromExcel.txt”2Copyright DASSAULT SYSTEMESClose Visual Basic and return toExcel.Click on Button1CATIA will be launched and abolt will be created.Copyright DASSAULT SYSTEMES41
CATIA V5 AutomationExample: Bolt from Excel (3/3)Student Notes:Have a look on the code:This tries to retrieve CATIA and if not successful starts orResumeNextOn Error Resume NextSetSetCATIACATIA pplication")IfIfErr.NumberErr.Number 00ThenThenSetSetCATIACATIA IA.Application")CATIA.VisibleCATIA.Visible t DASSAULT SYSTEMESBoth functions GetObject and CreateObject are provided by VBA (as well as Visual Basic).Copyright DASSAULT SYSTEMES42
CATIA V5 AutomationRunning Out-Process using the Windows Scripting HostStudent Notes:WSH enables scripts written in different languages such as VBScript and JavaScript.You can use a standard Editor to write your application. Ifyour program fails, you will be able to use the WindowsDevelopment environment.It is possible to develop an application in Visual Basic, thenput the types in comment and run it with WSH.Copyright DASSAULT SYSTEMESTo run a VBScript (*.vbs) or JavaScript (*.js) file, you can usecscript or wscript commands.Usually, wscript.exe is already associated with thoseextensions.Copyright DASSAULT SYSTEMES43
CATIA V5 AutomationVBScript under Windows Scripting HostStudent Notes:You can write a VBScript program in a simple ASCII text file with the extension “.vbs” forVisual Basic Script.Under WSH, GetObject and CreateObject are provided by the object Wscript.The following code launches CATIA V5.OnOn ErrorError ResumeResume NextNextSetCATIA Wscript.GetObject(,"CATIA.Application")Set CATIA Wscript.GetObject(,"CATIA.Application")IfIf Err.NumberErr.Number 00 ThenThenSetCATIA Wscript.CreateObject("CATIA.Application")Set CATIA ibleCATIA.Visible TrueTrueEndIfEnd IfCopyright DASSAULT SYSTEMESVBScript !Copyright DASSAULT SYSTEMES44
CATIA V5 AutomationBoltVBSript.vbs ExampleStudent Notes:Have a look on the source code.To run the “BoltVBScript.vbs” example , you can double–click on it.To run the example on a Command prompt Window you can also use :Copyright DASSAULT .vbsCopyright DASSAULT SYSTEMES45
CATIA V5 AutomationJavaScript under Windows Scripting HostStudent Notes:In the same way as VBScript, you can write a JavaScript program in a simple ASCII text filewith the extension “.js” for JavaScript.Under WSH, GetObject and CreateObject are provided by the object Wscript.The following code launches CATIA V5.CATIACATIA tObject(,"CATIA.Application");ifif( (CATIACATIA null)null){ {CATIACATIA IA.Visible true;true;}}Copyright DASSAULT SYSTEMESJava Script !Copyright DASSAULT SYSTEMES46
CATIA V5 AutomationBoltJavaSript.js ExampleStudent Notes:Have a look on the source code.To run the “BoltJavaScript.js” example, you can double–click on it.To run the example on a Command prompt Window you can also use :Copyright DASSAULT cript.jsCopyright DASSAULT SYSTEMES47
CATIA V5 AutomationOut-Process in HTML (Windows & Microsoft IE Only)Student Notes:Copyright DASSAULT SYSTEMESIn HTML, you can include VBScript or JavaScriptroutines.Microsoft explorer provides ActiveXObject (inJavaScript) and CreateObject(in VBScript) functions to Launch AutomationServers.So, it is possible to call CATIA V5 this way.You can access to the Microsoft DevelopmentEnvironment to debug your Application.You can launch the “Microsoft DevelopmentEnvironment from Explorer by :“Script Debugger” “ Open”Copyright DASSAULT SYSTEMES48
CATIA V5 AutomationOut-Process in HTML with VBScriptStudent Notes:Copyright DASSAULT SYSTEMESLoad the “BoltVBScript.html” example in Microsoft Internet Explorer. You will be able toClick on the “Bolt” button to create a Bolt in CATIA V5.You can view the source code by View Source menus.Due to security reasons, some warning messages for running the script, may appear dependingon the configuration and if the server is local or not.Copyright DASSAULT SYSTEMES49
CATIA V5 AutomationOut-Process in HTML with JavaScriptStudent Notes:Copyright DASSAULT SYSTEMESLoad the “BoltJavaScript.html” example in Microsoft Internet Explorer. You will beable to Click on the “Bolt” button to create a Bolt in CATIA V5.You can view the source code by View Source menus.Copyright DASSAULT SYSTEMES50
CATIA V5 AutomationVBA / VB Programming BasicsStudent Notes:Copyright DASSAULT SYSTEMESYou will be introduced to the Visual Basic and Visual Basic for Automationprogramming techniques.Copyright DASSAULT SYSTEMES51
CATIA V5 AutomationProgramming Generalities (1/5)Student Notes:Copyright DASSAULT SYSTEMESSequential ProgrammingThe program is read from top to bottom, sometimes with loops and tests.12 : If A O then GOTO 67User interface (windows, buttons, ) has to be « manually » built, withprogramming instructionsTypical of « old » programming languagesFortran, Basic, GWBasicVBScript may be considered as a sequential languageCopyright DASSAULT SYSTEMES52
CATIA V5 AutomationProgramming Generalities (2/5)Student Notes:Copyright DASSAULT SYSTEMESEvent-driven ProgrammingThe program execution will depend of events (mouse click on a button,typing characters in a text form )Graphic interface is drawn using a toolbox.This interface is the program «skeleton»Nowadays programming languages are event-basedVBA, Visual Basic, Visual C Copyright DASSAULT SYSTEMES53
CATIA V5 AutomationProgramming Generalities (3/5)Student Notes:Copyright DASSAULT SYSTEMESObject ProgrammingIn the application, all is ObjectThese Objects have Properties that you can read or setThese Objects have Methods which will modify their behaviorAn example Copyright DASSAULT SYSTEMES54
CATIA V5 AutomationProgramming Generalities (4/5)Student Notes:An example : Bernard owns a garage in Suresnes As we have to work with its garage, we need to assign it to a «type», and a «variablename» :Dim myGarage As Garageset myGarage Bernard.GarageTo get its address (Proprerty of myGarage Object), I can get this :myGarage.AddressBernard has a Collection of carsTo get one special car :Set myCar myGarage.Cars.Item(2)Copyright DASSAULT SYSTEMESSet myCar myGarage.Cars.Item(’Golf 2’)Copyright DASSAULT SYSTEMES55
CATIA V5 AutomationProgramming Generalities (5/5)Student Notes:To select a fuel, I get a Property :myCar.Fuel ‘Petrol’If I do not remember its colour :Colour myCar.ColourTo accelerate, I have a method which has the speed I want to reach (the speed is anargument) :myCar.Accelerate (110)Copyright DASSAULT SYSTEMESThe same method may return an object or an information(here the fuel consumption) :myConsumption myCar.Accelerate (110)Copyright DASSAULT SYSTEMES56
CATIA V5 AutomationVBA / VB Common ControlsStudent Notes:Copyright DASSAULT SYSTEMESYou will learn the user-interface related controls of Visual Basic and Visual Basic forApplication.Copyright DASSAULT SYSTEMES57
CATIA V5 AutomationStudent Notes:The « userform » ControlIcon : Interest :It is your window, on whichyou are going to insert controlsUseful Properties / MethodsfrmForm.CaptionfrmForm.StartUpPositionto inform the titleto control its positionCopyright DASSAULT SYSTEMESUserForm Initialize() is read when project is run (VBA)UserForm Load() is read when project is run (VB)Copyright DASSAULT SYSTEMES58
CATIA V5 AutomationStudent Notes:The « label » ControlIcon :Interest :The text label allows you to display a textthat cannot be modified by userto control the textto control its fontto control its dimensionsto control its alignmentCopyright DASSAULT SYSTEMESUseful Properties / lblText.TextAlignCopyright DASSAULT SYSTEMES59
CATIA V5 AutomationThe « textbox » ControlStudent Notes:Icon :Interest :The textbox allows user to enter a textCopyright DASSAULT SYSTEMESUseful Properties / MethodstxtBox.Textto get the texttxtBox.Fontto control its fontCopyright DASSAULT SYSTEMES60
CATIA V5 AutomationThe « commandbutton » ControlStudent Notes:Icon :Interest :The command button allows user to run an action byselecting a buttonCopyright DASSAULT SYSTEMESUseful properties / methodscmdButton.Captionto control the button textCopyright DASSAULT SYSTEMES61
CATIA V5 AutomationThe « image » ControlStudent Notes:Icon :Interest :The image control allows you to display abitmap imageCopyright DASSAULT SYSTEMESUseful properties / MethodsimgImage.Pictureto select the image to displayimgImage.Autosizeto resize it automaticallyCopyright DASSAULT SYSTEMES62
CATIA V5 AutomationStudent Notes:The « listbox » ControlIcon :Copyright DASSAULT SYSTEMESInterest :The listbox control allows you to display a list, fromwhich an element can be selectedUseful Properties / MethodslstBox.Additem “Text”lstBox.ClearlstBox.RemoveItem x.List(i)Copyright DASSAULT SYSTEMESto add an itemto clear the listto remove an itemto get the item countto get the selected itemto get item #i63
CATIA V5 AutomationThe «checkbox» and «optionbutton» ControlsStudent Notes:Icons :Interest :The checkbox allows the user to pick an option.The optionbutton allows the user to pick only oneamong a set of options.Copyright DASSAULT SYSTEMESUseful Properties / MethodschkBox.Captionto control the textlstBox.Valueto get its value (true/false)Copyright DASSAULT SYSTEMES64
CATIA V5 AutomationManaging Data/Variables (1/3)Student Notes:Naming variablesIt must be less than 255 charactersSpecial characters are forbidden : space ‘.’ & .It must not begin with a number‘myCar’ and ‘intRadius3’ are ok‘my Car’ and ‘2Radius’ are not okDeclaring variables with “Dim” is helpful for programming (it allows‘completion’), and saves memory at runningDim myCar as StringDim myCar Dim A1 as IntegerCopyright DASSAULT SYSTEMESDim A1%Copyright DASSAULT SYSTEMES65
CATIA V5 AutomationStudent Notes:Managing Data/Variables (2/3)Main types of rue or FalseIntegerNumeric-32768 to 32767%LongNumeric-2 147 483 648 to 2 147 483 648 (integer)&DoubleNumeric-1.79769313486232e 308 to-4.94065645841247E-324 for ‘-’ values4.94065645841247E-324 to 1.79769313486232e 308 for ‘ ’ values#StringNon-numericVariable Variantboth-Copyright DASSAULT SYSTEMESTypeCopyright DASSAULT SYSTEMES66
CATIA V5 AutomationManaging Data/Variables (3/3)Student Notes:Initializing Variab
CATIA uses the common part on MS-VBScript to have the same macros running on both the platforms. On Windows platforms Automation allows CATIA to share objects with other external applications such as Word/Excel or Visual Basic programs. CATIA can use the Word/Excel objects as well