A-A+

在CATIA二次开发中使用VBA(VBS)的TypeName函数获取文档类型

2019年06月23日 CAD 阅读 1,026 views 次

在CATIA二次开发中可以使用VBA(VBS)的TypeName函数获取文档类型,TypeName函数的定义如下:

TypeName(varname)

参数 varname 是一个Variant , 它包含除用户定义类型的变量之外的任何变量。此函数返回一个提供有关变量的信息的 String。由 TypeName 返回的字符串可以为下列任一项:

返回的字符串变量
对象类型类型为 objecttype 的对象
Byte字节值
IntegerInteger
Long长整数
Single单精度浮点数
Double双精度浮点数
Currency货币值
Decimal小数值
Date日期值
StringString
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 Sub

TypeName 返回是文档类型的字符串,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
个人公众号“数字化设计CAX联盟”,欢迎关注,共同交流
为您推荐:

给我留言

© 坐倚北风 版权所有 严禁镜像复制 苏ICP备15034888号. 基于 Ality 主题定制 AliCMS
联系邮箱:leanwind@163.con,微信公众号:数字化设计CAX联盟

用户登录

分享到: