A-A+
 在CATIA二次开发中使用VBA(VBS)的TypeName函数获取文档类型
在CATIA二次开发中可以使用VBA(VBS)的TypeName函数获取文档类型,TypeName函数的定义如下:
TypeName(varname)
参数 varname 是一个Variant , 它包含除用户定义类型的变量之外的任何变量。此函数返回一个提供有关变量的信息的 String。由 TypeName 返回的字符串可以为下列任一项:
| 返回的字符串 | 变量 | 
|---|---|
| 对象类型 | 类型为 objecttype 的对象 | 
| Byte | 字节值 | 
| Integer | Integer | 
| Long | 长整数 | 
| Single | 单精度浮点数 | 
| Double | 双精度浮点数 | 
| Currency | 货币值 | 
| Decimal | 小数值 | 
| Date | 日期值 | 
| String | String | 
| Boolean | 布尔值 | 
| Error | 错误值 | 
| 为空 | 即 | 
| NULL | 无有效数据 | 
| Object | 对象 | 
| 未知 | 类型未知的对象 | 
| Nothing | 未引用对象的对象变量 | 
 如果 varname 是一个数组,则返回的字符串可以为任一可能返回的追加了空圆括号的字符串(或 Variant)。 例如, 如果_varname_是一个整数数组, 则TypeName返回"Integer()""。 
示例代码如下:
Dim NullVar, MyType, StrVar As String, IntVar As Integer, CurVar As CurrencyDim ArrayVar (1 To 5) As IntegerNullVar = Null ' Assign Null value.MyType = TypeName(StrVar) ' Returns "String".MyType = TypeName(IntVar) ' Returns "Integer".MyType = TypeName(CurVar) ' Returns "Currency".MyType = TypeName(NullVar) ' Returns "Null".MyType = TypeName(ArrayVar) ' Returns "Integer()".CATIA二次开发应用示例代码:
Sub catmain()Dim DocTypeDocType = TypeName(CATIA.ActiveDocument)MsgBox "The Document Type is" & DocTypeEnd SubTypeName 返回是文档类型的字符串,CATIA中的文档类型共有8种:PartDocument、ProductDocument、DrawingDocument、AnalysisDocument、ProcessDocument、FunctionalDocument、MaterialDocument、CatalogDocument。对文档类型进行判断的VBA(VBS)示例代码如下:
If TypeName(CATIA.ActiveDocument) <> "PartDocument" Then MsgBox ("Please confirm that current active document is a part document") Exit SubEnd If