How to: Simple User Interface WMCUG 13 th Jan 2010 Gord Vander Vliet Enterprise Tool & Die, LLC Jeff Roark Johnson Controls
Two Example CATIA VBA Form Excel Design Table
VBA Forms Pros No Links to maintain Executed from Macro No Synchronization Cons Used by CATIA expert VBA knowledge required Requires naming convention
Design Table Example Pros Does not require CATIA to change values Everyone knows Excel Cons Requires CATIA to update the model
VBA User Interface Create a Parametric Part Define Parameters required for the UI Create a VBA form
VBA User Interface Create a VBA Project Create New or Add an Existing catvba project
VBA User Interface Insert – UserForm Design the UI TextBox Buttons Coding – Module Run form the Macro function in CATIA Coding Load the UI
VBA User Interface View UI Code
VBA User Interface View UI Object
VBA User Interface Insert – Object resolution Select a CATIA Parameter to insert the needed VBA code
VBA User Interface Free VBA code!
VBA User Interface Add an “TextBox” Name it – Block_LengthTextBox
VBA User Interface Assign the Parameter value to the TextBox When the VBA UI is started it will get the Parameter Value from CATIA and assign the value to the TextBox in VBA UI. Should look like this. VBA has will provide popup dialog boxes to help you along the way
VBA User Interface Ready to Test the UI with CATIA Parameter value is assigned to the TextBox Next step is to be able to change the value from the TextBox and assign that value to the CATIA Parameter.
VBA User Interface Original Code -Remove the length1 form the Private Sub UserForm1 -Added length1 as a Public variable so it’ s value can be used in both Subs
VBA User Interface Ready to Test the UI with CATIA Parameter value is assigned to the TextBox Change the TextBox Value and Click the Button After the Part is updated the Parameter value shows the new value form the TextBox
VBA User Interface Sub CATMain() MsgBox "Hello CATIA Users" UserForm1.Show End Sub Final Example with copy/paste code Module1
VBA User Interface Public length1 As Length Private Sub enterBtn_Click() length1.ValuateFromString Block_LengthTextBox.Value Unload UserForm1 End Sub Private Sub UserForm_Activate() '---- Begin resolution script for object : Block_Length Dim partDocument1 As PartDocument Set partDocument1 = CATIA.ActiveDocument Dim part1 As Part Set part1 = partDocument1.Part Dim parameters1 As Parameters Set parameters1 = part1.Parameters Set length1 = parameters1.Item("Block_Length") Block_LengthTextBox.Value = length1.ValueAsString '---- End resolution script End Sub UserForm1
Excel UI Form
Create CATPart with required Parameters Create a Design Table Create a Excel VBA Form
Excel UI Form Double Click on the Design Table Click Edit Table Access the Excel File
Excel UI Form Make a Button
Excel UI Form Create a Macro – View Tab – Click Macro – Type a Name – Click Create
Excel UI Form Rt Click on the Button to assign it to a Macro
Excel UI Form Insert a Module Insert a UserForm
Excel UI Form Add the code in the Module to Show the Form UserForm1.Show will display the form when the macro is launched.
Excel UI Form Add the TextBox, Button, and Image
Excel UI Form Add a Background image Add Textbox and Button using the Toolbox
Excel UI Form Add this code to the UserForm
Excel UI Form When the form is Activated assign Cell values to TextBox
Excel UI Form Click the Enter Button to assign TexBox values to Cell