Catia v5 macro programming tutorial pdfDim prod1 As Product ‘Assume that prod1 gets set to an instance here Dim partDoc1 As PartDocument Set partDoc1 prod1.GetMasterShapeRepresentation(True) Dim part1 as Part Set part1 partDoc1.Part To create a new part in the Assembly, you would use the AddNewComponent method. WS-8 Close the macros libraries window. Close theform by using the “x” button in the top right corner. To create a new UserForm press ALT-F11 to open the VBA editor. In this workshop you have learned to: Create a CATIA VBA program from scratch Use “primitive” variable types such as integers and strings Use a Sub (subroutine) to encapsulate code that is to be called multiple timesthroughout a program Use a Function in a way similar to a Sub, but when a return value is desired Use an array to store a list of primitives (integers in this case) and then iterate through that array using a For loop WS-43 WORKSHOP 4 Objects in CATIA VBA VB Scripting for CATIA V5 – Workshop 4 Nick Weisenberger, February 2012 WS-44Workshop 4 – Introduction Description In this workshop you will explore the basics of objects, their properties, and their methods in CATIA VBA programming. Note that the GeometricElements object is only used to get this Axis2D object. Design Mode If you're working with large assemblies, you may want to automatically set each item in the treeto design mode (individually opened parts are typically automatically opened in design mode already): Dim productDocument1 As Document Dim product1 As Product Dim products1 As Products Set productDocument1 CATIA.ActiveDocument Set product1 productDocument1.Product Set products1 product1.ProductsProducts1.item(i).ApplyWorkMode DESIGN MODE 29 VB Scripting for CATIA V5: Expanded Edition Parts and Products A useful code you may find helpful is to identify whether a file is a CATProduct or a CATPart. The object has to be selected first. Note that the result is that a new sketch is created. Close the macros libraries window. Create a newmacro library and VBA project, called "myVBA". Another property is called “ActiveDocument”. Sub CATMain() Private strMessage As String Property Let Message(MessageIN As String) strMessage MessageIN End Property Dim oMssgr As Messenger Set oMssgr New Messenger oMssgr.Message "Hello" MsgBox oMssgr.Message End Sub WS24 Step 7 Attempt to run “UseTheMessenger” and note that although the Message property can be “set”, it fails when the property is “gotten”. Next End Sub Function DisplaySum(ByVal int1 As Integer, ByVal int2 As Integer) As Integer DisplaySum int1 int2 End Function WS-42 Workshop 3 – Conclusion This concludes Workshop 3. Edit thecode of the Click event of the form like so. No programming experience is required! This information is not featured in the user help documentation. The purpose of this text is to complement and supplement other texts and resources. A blank form should appear over the CATIA window. Click on the red arrow next to the “Shape” box to see a moredetailed view of Shape objects. The GetWorkbench command takes a string as an argument and returns a Workbench object. A macro is a series of functions, written in a scripting language, that you group in a single command to perform the requested task automatically. Create a new class module in a new VBA library named “Messenger”. What is aMacro and why do we use them? Look through the recorded macro. It controls items such as: Are the parts shaded, wireframe, etc? Sub CATMain() Dim strMessage as String CallMe strMessage MsgBox strMessage End Sub Sub Callme(ByRef strMsg As String) strMsg “Hello” End sub Save and Save As The Document object includes the“Save” and “Save As” methods. Grab the Documents collection and display its Count property. Functions “return” a value, subroutines do not. This property is an object itself, and even more specifically, it is a Document object. Rename the newly created module “Workshop2 01” WS-36 Step 2 In the code window, type the code shown below Click Save on the File menu to save the your changes. Dim originElements1 As OriginElements Set originElements1 part1.OriginElements Dim reference1 As Reference Set reference1 originElements1.PlaneYZ The array contains the numerical information that describes a 2D axis system that is positioned in 3D space. A for-each loop can be usedto iterate through most collections in CATIA. VBScript is a subset of the Visual Basic Programming language (VBA). Program cancelled, please retry macro." Else 'Input box to enter name of file Dim partName As String partName Inputbox ("Please enter the file name.") 'Input box to enter file location Dim oLocation As String 'oLocation Inputbox("Please enter the location to save the file. This is because the position of the axis system that is described by the array is the same as the default position. This is because the variable “pdoc1” is “Nothing.” It wasn’t successfully “Set” in the previous line. For instance, it has a property called “FullName” which is a string. Dim sketch1 As Sketch Setsketch1 sketches1.Add(reference1) „ „ Set the axis system of the sketch „ Dim arrayOfVariantOfDouble1(8) arrayOfVariantOfDouble1(0) 0# arrayOfVariantOfDouble1(1) 0#arrayOfVariantOfDouble1(2) 0# arrayOfVariantOfDouble1(3) 0# arrayOfVariantOfDouble1(4) 1# arrayOfVariantOfDouble1(5) 0# arrayOfVariantOfDouble1(6) 0# arrayOfVariantOfDouble1(7) 0# arrayOfVariantOfDouble1(8) 1# Note that a variable that isn‟t dimmed (sketch1Variant) is set to the sketch object, then“SetAbsoluteAxisData” is called on it. You can read more about his adventures at . Look in the second column (“class”). Name it “Create Sketch 01” WS-70 Step 2. Create a sketch on the Y-Z plane that consists of a single line. DO: Exit sketches before stopping recording. To take the image as shown on screen click No.", vbYesNo) vbYes ThenobjViewer3D.Viewpoint3D objCamera3D.Viewpoint3D 'reframe objViewer3D.Reframe() 'zoom in objViewer3D.ZoomIn() 'objViewer3D.ZoomIn() 'clear selection for picture CATIA.ActiveDocument.Selection.Clear() 'increase to fullscreen to obtain maximum resolution objViewer3D.FullScreen True 'MsgBox strname 'take picture with auto ISO viewand reframe ON*** objviewer3D.Capturetofile 4,strname '****take picture as is with NO reframe or iso view**** Else zoom in objViewer3D.ZoomIn() 'clear selection for picture CATIA.ActiveDocument.Selection.Clear() 'increase to fullscreen to obtain maximum resolution objViewer3D.FullScreen True 52 Nick Weisenberger 'take pictureobjviewer3D.Capturetofile 4,strname End If '*******************RESET********************** objViewer3D.FullScreen False 'change background color back objViewer3D.PutBackgroundColor(dblBackArray) 'turn the spec tree back on objSpecWindow.Layout catWindowSpecsAndGeom 'toggle compass CATIA.StartCommand("Compass") End If EndSub Cycle through 3D Annotation Data ‘Script by Nick Weisenberger ‘Last revised December 1, 2011 Sub CATMain() Dim partDocument1 As PartDocument Set partDocument1 CATIA.ActiveDocument partName Left(, Len( - 8) Dim oAnnotationSets As AnnotationSets Set oAnnotationSets nnotat ionSets") 53 VB Scripting for CATIA V5: Expanded Edition Dim Set Dim Set viewer1 As Viewer viewer1 CATIA.ActiveWindow.ActiveViewer viewpoint1 As Viewpoint3D viewpoint1 viewer1.Viewpoint3D Dim ObjViewer3D As Viewer3D Set objViewer3D CATIA.ActiveWindow.ActiveViewer partDocument1.Selection.Clear() numSets oAnnotationSets.Count Dim CurAnnoSet As AnnotationSet Set CurAnnoSet oAnnotationSets.Item(1) numCap CurAnnoSet.Captures.Count msgbox "Number of annotation sets is: "&numSets& " Number of captures is: "&numCap 'error handling On Error Resume NextSet partDoc CATIA.ActiveDocument Set Part partDoc.Part If Err.Number 0 Then 'change text to black Dim oSel As Selection Dim visProperties1 As INFITF.VisPropertySet Set oAnnotationSets Part.AnnotationSets Set oSel CATIA.ActiveDocument.Selection Set objViewer3D CATIA.ActiveWindow.ActiveViewer For Set Set For Set IdxSet 1To oAnnotationSets.Count oAnnotationSet oAnnotationSets.Item(IdxSet) oAnnotations oAnnotationSet.Annotations IdxAnnot 1 To oAnnotations.Count oAnnotation oAnnotations.Item(IdxAnnot) If Not oAnnotation Is Nothing Then 54 Nick Weisenberger With oSel .Clear .Add oAnnotation Call .VisProperties.SetVisibleColor(0, 0, 0, 0) End WithoAnnotation.ModifyVisu End If Next Next For i 1 To numCap Set oCapture CurAnnoSet.Captures.Item(i) oCapture.DisplayCapture() capNamer CurAnnoSet.Captures.Item(i).Name Set objViewer3D CATIA.ActiveWindow.ActiveViewer Set objCamera3D CATIA.ActiveDocument.Cameras.Item(1) 'increase to fullscreen to obtain maximum

resolution objViewer3D.FullScreen True fileloc "M:\Macro Files\" exten ".png" strname fileloc&partName&" "&capNamer&exten 'take picture objviewer3D.Capturetofile 4,strname Next 'i End If 'change text back to white For Set Set For Set IdxSet 1 To oAnnotationSets.Count oAnnotationSet oAnnotationSets.Item(IdxSet) oAnnotations oAnnotationSet.Annotations IdxAnnot 1 To oAnnotations.Count oAnnotation oAnnotations.Item(IdxAnnot) If Not oAnnotation Is Nothing Then 55 VB Scripting for CATIA V5: Expanded Edition With oSel .Clear .Add oAnnotation Call .VisProperties.SetVisibleColor(255, 255, 255, 255) End With oAnnotation.ModifyVisu End If Next Next' 'error handling Else Msgbox "Not a part document! Open in new window." End If End Sub Help Documentation The file B18\intel a\code\bin\V5Automation.chm is a useful source for CATIA “Application Programming Interface” (or API) documentation. Select theWorkShop2 01 macro on the list and click the Run button Note that the value “5” is displayed in the message box. The purpose of declaring and setting variables is to hold the properties of an object. After you have created some macros you will see a list of the .CATscript files here. WS-19 Step 2 Ensure the project and properties boxes are visible bygoing to the top menu bar and clicking View View Project Explorer and View Properties Window Right click on VBAProject (myVBA in this example) Insert Module. If one or more objects are selected then the selection contains those one or more objects. 'row one headers 'Cell A1 Excel.Cells(1,1) "Part Number" 'Cell B1Excel.Cells(1,2) "Fasteners" Excel.Cells(1,3) "Name" Excel.Cells(1,4) "Thickness" Excel.Cells(1,5) "Material" Excel.Cells(1,6) "Mass" Excel.Cells(1,7) "Sorter" 37 VB Scripting for CATIA V5: Expanded Edition You can use a variable to assign a cell number. This means we will only look at the first geometrical set within a part file. It is importantthat there are no constraints in the sketch that was created. strHello is then defined. WS-92 9a. These are all housed in the Documents collection and they contain all geometry, process, and product information. In the Project explorer window (top left side), right-click on the project then select Insert – UserForm. See the next slide for tips on how toinvestigate the purpose of this command. The first way is to use a parameter and the “measure” tools which are a part of the formula editor in V5. More about that later. Note the following: A Messenger object is dimmed. If this is the case you will have to use Chr(34) character representation instead. Sub CATMain() Dim intA As Integer Dim intB AsInteger Dim intC As Integer intA 2 intB 3 DisplaySum intA, intB End Sub Sub DisplaySum(ByVal int1 As Integer, ByVal int2 As Integer) Dim int3 as integer int3 int1 int2 MsgBox “The sum is “ Str(int3) End Sub WS-40 Step 6 Right-click on the myVBA project on the Project tree and select Insert Module. Click the “View Code”button to view the code of the form. Otherwise click No.", vbYesNo) vbYes Then Else End If Working with Parameters Many times a VB application is developed to create, read, or modify Parameters. Sub CATMain() Dim oMssgr As Messenger Set oMssgr New Messenger oMssgr.Message "Hello" oMssgr.Capitalize MsgBox oMssgr.Message EndSub WS-32 Workshop 2 – Conclusion This concludes Workshop 2. Start a new macro recording. Change the “UseTheMessenger” module as shown to the lower right and run it again. The icon browser pops up. Now you can click the Icon to run your macro! You can also setup custom keyboard shortcuts as well from within the same window. Dimviewer1 As Viewer Set viewer1 CATIA.ActiveWindow.ActiveViewer Dim viewpoint1 As Viewpoint3D Set viewpoint1 viewer1.Viewpoint3D Dim ObjViewer3D As Viewer3D Set objViewer3D CATIA.ActiveWindow.ActiveViewer If you want to add ten slides to your ppt, set i 10 and use a For Loop. Some examples: Sleep – insert a delay into theVB application Killing processes (like CNEXT to instantly stop CATIA) Checking for processes (to see if something is running) Complete Macro Examples It’s always a good idea to add some notes at the beginning of your code indentifying who wrote or modified the code, when the last revision was made, what the code actually is supposed to do, etc.WS-38 Step 4 Right-click on the myVBA project on the Project tree and select Insert Module. Chr(34) is for the double quote mark. Standardization Improve efficiency Expand CATIA capabilities Streamline tasks Macros in CATIA are created by two primary methods: 1. It can be accessed like this: Dim oSelection As Selection Set oSelection CATIA.ActiveDocument.Selection If nothing is selected then the selection is empty. Then when you add new slides to the ppt use the i value again to add the new slide to the end of the slideshow. The following are a couple of CATIA macros I wrote and have used throughout my professional career in one form or another. The CATIA object is dimmedor “declared” as it exists by default. Close the form using the “x” button in the top-right corner. Note that the “For each” loop iterates through the Documents collection “documents1”. Function AddNewPad(iSketch As Sketch, iHeaight As Double) As Pad Member of PARTITF.ShapeFactory Where Argument 1 is a sketch and I means input. These“properties” and “methods” make up the “class” called “Person.” Objects of this class can then be used in a program to represent individual people. There is also a special set of On-Line help that is available with the CAA RADE interfaces (it’s on this CD). WS-94 Step 10. This text will cover those core items to help teach beginners important conceptsneeded to create custom CATScript macros. One example of this in VB scripting is the For Loop. To look for all object named “pad”: objSel.Search “Name Pad.*,all” Or objSearch(“Name Weld Center*,all”) To look for all points: objSel.Search “Type Point,all” To look for items colored red: objSel.Search “Color Red,sel” To look for items onlayer 10: objSel.Search “Layer 10,all” The selection object can also be used for a variety of other tasks: Copy elements: objSel.Copy Pasting elements: objSel.Paste Delete elements: objSel.Delete Change graphical properties: 15 VB Scripting for CATIA V5: Expanded Edition Dim VisProps As VisPropertySet Set VisProps objSel.VisProperties‘gets the color VisProps.GetRealColor(255,0,0) ’sets the color visProps.SetRealColor(255,0,0,1) VisProps.SetShow( ) ‘set show or hide Documents versus Windows There are two main collections under the CATIA application object: Documents - There are many types of documents that are used in V5: CATPart, CATProduct, CATProcess, CATDrawing,CATAnalysis, etc. Note that the result is indistinguishable from the last time the macro was run. Click on the form with your mouse and a message box should appear displaying “hello”. To return a single quotation mark which does not indicate a comment, needed in a formula for example, you’ll have to use the Chr function. Add a .Formula after theExcel.Cell(). WS-46 Step 2 Scroll down the Intellisense drop-down and note that the “Windows” property is there as well. Excel.Visible True Entering Cell Values To write text in a specific cell, such as the first row's header values, use Excel.Cell (row #, column #). In this workshop you have learned to: Create a VBA class Define a read-onlyproperty for the class (only provide a “Property Let” method) Define a read-write property for the class (provide both “Property Let” and “Property Get” methods Use the “Class Initialize” subroutine to assign initial values to class variables Define a method for a class that operates on private variables of that class WS-33 WORKSHOP 3 Creating aBasic VBA Program from Scratch VB Scripting for CATIA V5 – Workshop 3 Nick Weisenberger, February 2012 WS-34 Workshop 3 – Introduction Description In this workshop, as opposed to starting a CATIA VBA program by recording a macro, you will instead insert a new module into an existing CATIA VBA library and type the program statementsin manually. Here is an object property example using the FullName property: 11 VB Scripting for CATIA V5: Expanded Edition Sub CATMain() Dim strFullName as String strFullName CATIA.FullName Dim doc1 as Document Set doc1 CATIA.ActiveDocument End Sub The “Dim” command is used to allocate a variable of any type. Dim Excel AsObject Dim workbooks As workbooks Dim workbook As workbook Dim Sheets As Object Dim Sheet As Object Dim worksheet As Excel.worksheet Dim myworkbook As Excel.workbook Dim myworksheet As Excel.worksheet Set workbooks Excel.Application.workbooks Set myworkbook Excel.workbooks.Add Set myworksheet Excel.ActiveWorkbook.Add Set myworksheet Excel.Sheets.Add 35 VB Scripting for CATIA V5: Expanded Edition Launching Excel from CATIA There are several methods to go about launching the Microsoft Excel program from within CATIA. They seem to serve no purpose. Good luck and happy programming! -Nick Weisenberger 57 VB Scripting forCATIA V5: Expanded Edition About the Author Nick Weisenberger grew up in Columbus, Ohio and graduated from the University of Toledo, in Toledo, Ohio, with a degree in Mechanical Engineering. If we determine that the setting of these values isn‟t necessary, we can get rid of this section of code all together. Some CATScripts from this text maywork under UNIX OS but not all due to differences between the two systems. 46 Nick Weisenberger Dim objSlide As PowerPoint.Slide Set objSlide oPPTPres.Slides.Add(i 1, 36) ‘capnamer is the name of the catpart objSlide.Shapes(1).TextFrame.TextRange.Text capNamer Set pic objSlide.Shapes.AddPicture(strName, False, True, 50, 5, 576,350) Adding headers and footer automatically to your presentation is very easy. Here you can see SketchBasedShape, BooleanShape, DressUpShape, and TransformationShape. Enhance the Messenger class so that the “getting” and “setting” of its properties are controlled by “Get” and “Let” methods. WS-93 9b. In the same way that a method is afunction or a subroutine that runs whenever called from within a program, an “event” is a subroutine that runs whenever a user interaction triggers that event. Private Sub Class Initialize() iCount 0 End Sub WS-30 Step 13 Properties have been defined for the messenger class. So “Documents” and “Windows” are both properties of the CATIAobject, but they are also objects themselves. Variables are “dimmed” (declared) and then “set” (given a value). Write custom code with the macro editor For macros recorded in a folder or in a CATPart or CATProduct, Dim statements (declarations) will be recorded for CATScript but not for MSVBScript. Sub CATMain() On Error Resume Next Dimpdoc1 as PartDocument Set pdoc1 CATIA.ActiveDocument If Err.Number 0 Then MsgBox pdoc1.FullName Else MsgBox “Active document is not a part document!” End If End Sub Calling the “Clear” method on the Err object sets the “Number” property of the Err object to zero (“clean slate”, as they say). To see all of the methods available for aparticular class, you should check every class that it inherits from up to “AnyObject”. For example, if I record a macro to zoom in and then zoom out I might get the following code: Dim viewpoint3D As Viewpoint3D Set viewpoint3D viewer3D.Viewpoint3D Viewer3D.ZoomIn Set viewpoint3D viewer3D.Viewpoint3D Viewer3D.ZoomOut Setviewpoint3D viewer3D.Viewpoint3D Notice how the “Set Viewpoint” command appears multiple times? DO: Check each macro after it’s recorded. Often times you might record a macro with a CATPart active and open it in its own window. For macros recoded in a .catvba library, “MS VBA” is the only choice. Edit their properties as indicated. Howclose or far away is the zoom level on the part? This will set the TextBox so that it‟s default text that it contains is “0”. Note that even before you hit the “Create Line” button you are able to interact with CATIA (zoom in, rotate, etc.). Use the (Name) field in the properties box to rename it "Create New Part Document" WS-20 Step 3 Right click onthe “Modules” folder of the VBA project and select Insert Class Module. Give the Messenger class a method called “Capitalize” that serves to manipulate the string information that is stored in its properties. So, to change the view of a document we need to set the 3DViewer viewpoint to the Camera viewpoint: objViewer3D.Viewpoint3D Camera3D.Viewpoint3D Once you access the ActiveViewer of the current window you can also control many other display properties: Dim objViewer As Viewer3D Set objViewer CATIA.ActiveWindow.ActiveViewer ‘Translating the view objViewer.Translate(translationVector) ‘Rotating the view: objViewer.Rotate(axisOfRotation, rotationAngle) 19 VBScripting for CATIA V5: Expanded Edition ‘Creating a new view (or Camera): objViewer.NewCamera() ‘To reframe a window objViewer.Reframe() ‘To Zoom In objViewer.ZoomIn() ‘To Zoom Out objViewer.ZoomOut() Turn off the specification tree: Dim objSpecWindow As SpecsAndGeomWindow Set objSpecWindow CATIA.ActiveWindowobjSpecWindow.Layout WindowGeomOnly ‘This shows both the spec geometry WindowSpecsAndGeom tree and the ‘This shuts off the geometry and shows only ‘the spec tree WindowSpecsOnly Go to the back of the back and walk-through Workshop Tutorial 2. 22 Nick Weisenberger Sub CATMain() On Error Resume Next ‘Insert variousprogramming statements here along with ‘logic and conditionals that deal with errors that are ‘generated. Collection – A group or list of similar objects which are put together for a specific reason. The “New” keyword orders the creation of a Messenger object. WS-97 Step 12a. The CATIA object has many properties. CD to the unload directory of theversion of CATIA you want to register (i.e. “c\program files\Dassault systems\B16\intel a\code\bin”) 7. Learning the syntax of each programming language is crucial to creating successful macros. To stop recording: Tools Macro Stop Recording or click the stop button WS-11 To create an icon for each macro: Go to Tools Customize Commands tab scroll down to Macros click "Show Properties" WS-12 Under Commands, select the macro then click the " " box. Sub CATMain() 'Declaration of variables Dim intA As Integer Dim intB As Integer Dim intC As Integer 'Valuate two of the variables intA 2 intB 3 'Set the value of the third as a sum ' of the first two intC intA intB 'Create a stringto be displayed as output. WS-65 Step 8: Add Code to Count Datum Planes Insert the following code below what we already have. Open a command prompt 3. Sub CATMain() Dim intA As Integer Dim intB As Integer Dim intC As Integer intA 2 intB 3 intC DisplaySum(intA, intB) MsgBox “The sum is “ Str(intC) End Sub FunctionDisplaySum(ByVal int1 As Integer, ByVal int2 As Integer) As Integer DisplaySum int1 int2 End Function WS-41 Step 7 Right-click on the myVBA project on the Project tree and select Insert Module. Text Strings: When a value is entered as a text string, you must add quotation marks before and after the string. Run the command “cnextunregserver” 5. Here are the steps to un-register or reregister a CATIA V5 version: 1. There are two drop-down menus, one that shows which object‟s code you are looking at, the other showing the “event” subroutine you are editing. An avid traveler, one of Nick’s favorite pastimes is visiting amusement parks all over the country. As you can see, theform recognizes the click “event” and it runs the code each time you click it. CD to the unload directory of the version of CATIA you want to unregister (i.e. “c\program files\Dassault systemes\B15\intel a\code\bin”) 4. TIFF 3. WS-69 Step 1: Start Recording a Macro Create a new part document Start recording a new macro. Within the program, thevariable then represents that object unless it is “Set” to a different one. This is a collection of all the geometrical sets of the part, but the programmatic name of a geometrical set is HybridBody. The API documentation shows the inheritance tree, and a listing of the Properties and Methods of the PartDocument class. For example, you could say that aperson is described by his height, weight, and hair color, and that every person has certain actions that they can perform, such as walking, eating, and sleeping. Create a new CATPart in CATIA and create a new CATIA VBA library and module. Run the command “cnext-regserver” 8. The properties of objects can be accessed using the notation:Object.Property. For example: Sub CATMain() 'Count the number of open documents Dim docs1 as Documents Set docs1 CATIA.Documents MsgBox “The number of open documents is “ & docs1.Count 'Accessing the first Document object in the collection Dim doc1 as Document Set doc1 docs1.Item(1) MsgBox “The FullName of the firstdocument is “ & doc1.FullName End Sub 18 Nick Weisenberger Simple Viewer Commands There are a few steps and methods to change the viewpoint of a CATIA document. . Parentheses: To achieve the desired result and to avoid errors, it is important to use parentheses () correctly inany statement. WS-63 WS-64 Step 7: Use the HybridShape Object Diagram There are many classes that inherit from the abstract class HybridShape, as can be seen below. Please feel free to use them for your own purposes and improve upon them! Return the Parent Name 'Script by Nick Weisenberger 'Revised 11/7/11 'This script returns the parentname of a selected object ****** Sub CATMain() Dim SelectedElement Set SelectedElement CATIA.ActiveDocument.Selection On Error Resume Next Dim oSelElem Set oSelElem SelectedElement.Item(1).Value 48 Nick Weisenberger Dim info Set info oSelElem.Parent.Parent If Err.Number 0Then MsgBox "Parent Name " & info.Name Else Msgbox "You must select an object to return the parent name." End If End Sub Export Spec Tree 'Script by Nick Weisenberger 'Revised November 18, 2011 'this script exports the specification tree to Excel or ‘txt file based upon user input' Language "VBSCRIPT" Sub CATMain() Dim productDocument1 As Document Set productDocument1 CATIA.ActiveDocument 'Input box to select txt or xls Dim exportFormat As String exportFormat Inputbox ("Please choose format to export the tree as. A good first step afterrecording a macro is to add comments to clearly call-out the sequence of “stages” of the code. Once the search command has been issued, you then need to loop through the selection object to get the items that have been found. WS-21 Step 4 In the code window enter the line: Public Message As String Create another module on the VBA project.Macros are used to save time and reduce the possibility of human error by automating repetitive processes, standardization, improving efficiency, expanding CATIA’s capabilities, and by streamlining tasks. You can change the size of the picture with this code: Set window CATIA.ActiveWindow H win.Height W win.Width sLF Chr(10) 31 VBScripting for CATIA V5: Expanded Edition win.Height InputBox("Enter height, reference is upper left hand corner", "Change height", win.height) If win.Height "" Then Exit Sub End If Then do the same thing for the width and restore original settings at the end. What color is the background screen? Sub CATMain() On Error Resume Next‘ ‘ If a runtime error occurs here, the program ‘ proceeds ‘ On Error Goto 0 ‘ ‘ Now when a runtime error occurs, the program ‘ will stop End Sub 23 VB Scripting forCATIA V5: Expanded Edition Create a Yes/No Message Box Use the following code to create a pop-up message box with the option to click Yes or No: If MsgBox ("To export results to PowerPoint click Yes. The count of open documents should be displayed. Modify the macro to create additional geometry and rerun it on a new part document. Notethere is no “Close” method listed. Now go back to the “UseTheMessenger” module and make the changes shown below and to the right. Excel.Cells(1,9).Formula " SUMIF(I5:I"&RwNum 2&","&Chr(34)&" 0"&Chr(34)&")" Now let's combine a For Loop with a couple of SUM and IF formulas. A few things to keep in mind when recording a macro:1. Save the VBA project and run the macro Highlight the VBA library on the project tree and save your changes Close the VBA window, open a new part, and open the macros dialog through Tools Macro Macros, and run the “Show CreateLine Form” macro. The cursor should be blinking within the cbCreateLine Click() subroutine. There maybe mistakes within this manual. Move the shortcut to your desktop and double-click on it to open it. Rename the newly created module “Workshop2 03” In the code window, type the code shown below Click Save on the File menu to save the your changes. Activation State The following returns the activ

Catia v5 macro programming tutorial pdf Dim prod1 As Product ‘Assume that prod1 gets set to an instance here Dim partDoc1 As PartDocument Set partDoc1 prod1.GetMasterShapeRepresentation(True) Dim part1 as Part Set part1 partDoc1.Part To create a new part i