1、Agenda,宏录制,修改,录制宏 理解录制的宏 修改宏 运行宏 把宏加入工具条,宏、VBA、VB三种方式,Visual Basic ,VBA,VBScript之间的区别 VBScript(Visual Basic Script):VBScript是VB的一个子集。 1 更简单的VB解释语言。 2 可以调运CATIA对象。 3 没有数据类型的区别。系统总是动态的调用函数和对象属性。(迟绑定调用对象通过他们的dispatch接口) VBA(Visual Basic for Application):VBA是VB的一个子集。 1 VBA是程序中的主机,就象Word,Excel。 2 它提供了一个带
2、有编辑器、除错器、帮助、对象浏览器、完成器的完整的开发环境。 3 利用它的Tools-Reference菜单可以声明使用的对象库。这在完成和对象浏览器之间建立了 一个通道。 Visual Basic(Visual Basic专业版):VB是个完全的版本。 1 可以编制独立的程序。 2 也可以创建ActiveX和程序服务器。 3 可以被编译。 4 VB提供了自己的文档在线帮助,VB获取catia对象,VB基本语言介绍,VB基本语言介绍,Input & output,VB基本语言介绍,a = 2 & Val(“a“),b = Str(20),VB基本语言介绍,Input & output,VB基本
3、语言介绍,If 条件1 Then 语句块1 ElseIf 条件2 Then 语句块2 Else 语句块n+1 End If,Select Case 测试变量 Case 表达式1 语句块1 Case 表达式2 语句块2 Case Else 语句块n+1 End Select,选择结构,VB基本语言介绍,循环结构,For 变量=初值 To 终值 Step 步长 语句块 Next 变量,For Each 对象变量 In 对象集 语句块 Next 对象变量,Do While 条件表达式 语句块 Loop,Do While i 10 CATIA.Application.Caption = i i = i
4、 + 1 Loop,VB基本语言介绍,VB基本语言介绍,CATIA 结构,CATIA 结构,CATIA 结构,CATIA基本操作,CATIA编程基本流程,Documents和Document对象,添加一个文档:Part,Product,DrawingDim document1 As DocumentSet document1 = CATIA.Documents.Add(“Product“) 打开一个已经存在的文档:Set document1 = CATIA.Documents.Open(filename) 当前活动的文档:On Error Resume NextSet document1 =
5、CATIA.ActiveDocumentIf document1 Is Nothing ThenErr.ClearSet document1 = CATIA.Documents.Add(“Part”) document1.activateEnd if,CATIA.Documents. Add CATIA.Documents. Count CATIA.Documents. Name CATIA.Documents. NewFrom CATIA.Documents. Open,Documents和Document对象,示例:依次激活文档Dim count1 As Integercount1 = C
6、ATIA.Documents.CountFor i = 1 To count1CATIA.Documents.Item(i).ActivateNext 输出为其他格式:例如CGRdoc.ExportData “c:aa“, “cgr“,document.Activate document.Save document.SaveAs document.Close document.ExportData,Windows和Window对象,逐个显示窗口名称:Dim document1 As DocumentSet document1 = CATIA.ActiveDocumentDim mywindow As WindowMsgBox CATIA.Windows.CountFor Each mywindow In CATIA.Windowsmywindow.ActivateMsgBox mywindow.NameNext,