第二种方式是Attribute。我们叫做属性,和iPRoperties以示区别。很多Inventor对象都提供了添加属性的功能,包括文档。属性的操作也有大量文章,本文推荐两个材料:
第一是帮助文档。专门有个章节讲解:

另外就是Brian的博客文章。我还没来得及翻译。

http://modthemachine.typepad.com/my_weblog/2009/07/introduction-to-attributes.html

简单讲:

创建属性集(AttributeSet)和 属性(Attributes)需要用的方法:

- 通过对象的AttributeSets集合添加属性集

Public Function Add( 
             ByVal AttributeSetName As String,     
             Optional ByVal CopyWithOwner As Boolean = False ) 
              As AttributeSet

- 通过属性集添加属性:

Public Function Add( 
              ByVal AttributeName As String, 
              ByVal ValueType As ValueTypeEnum, 
              ByVal Value As Variant ) As Attribute

目前属性可以添加以下类型:

ValueTypeEnum:  
    kIntegerType  整形
    kDoubleType  实数
    kStringType  字串
    kByteArrayType  字节
    kBooleanType 布尔值

查询属性 
每个文档都有一个属性管理对象AttributeManager。它支持多种灵活的方式查询。而且比起遍历快很多。可以基于属性集名,属性名或属性值查找。

FindAttributes 
   FindAttributeSets 
   FindObjects

Public Function FindObjects( 
    Optional ByVal AttributeSetName As String = "*",     
    Optional ByVal AttributeName As String = "*",     
     Optional ByVal AttributeValue As Variant ) As ObjectCollection

和上一篇文章类似,以下代码添加了自定义属性集和属性,并演示如何访问。

VBA

Sub AddCustomAttribute()

' open a document invisible 
    Dim oDoc As Document 
     Set oDoc = ThisApplication.Documents.Open("c:\testpart.ipt", False)

' name of new attribute set 
    Dim oNameOfNewPS As String 
    oNameOfNewPS = "myNewSet" 
    ' new attribute set 
    Dim oNewPS As AttributeSet 
    If oDoc.AttributeManager.FindAttributeSets(oNameOfNewPS).Count > 0 Then 
       ' if the set exists aleady 
       Set oNewPS = oDoc.AttributeSets(oNameOfNewPS) 
       ' you can clean up the existing attributes 
    Else 
        ' add a new one 
         Set oNewPS = oDoc.AttributeSets.Add(oNameOfNewPS) 
     End If

'the values of the attributes 
    Dim oIntProV As Integer 
    oIntProV = 100 
    Dim oByteProV() As Byte 
    oByteProV = StrConv("ABCDEFG", vbFromUnicode) 
     Dim oDoubleProV As Double 
    oDoubleProV = 3.1415926 
    Dim oDateProV As String 
    oDateProV = "2013-3-1 15:25"

' add these attributes with the meaningful name 
    ' assume they do not exist in the attribute set 
    Call oNewPS.Add("ModelCount", kIntegerType, oIntProV) 
    Call oNewPS.Add("ModelByte", kByteArrayType, oByteProV) 
    Call oNewPS.Add("ModelBasicLength", kDoubleType, oDoubleProV) 
    Call oNewPS.Add("ModelUpdateDate", kStringType, oDateProV) 
    oDoc.Save 
    oDoc.Close 
End Sub

Sub ReadCustomAttribute()

' open a document invisible 
    Dim oDoc As Document 
    Set oDoc = ThisApplication.Documents.Open("c:\testpart.ipt", False) 
    ' name of new attribute set 
    Dim oNameOfNewPS As String 
    oNameOfNewPS = "myNewSet" 
    ' new attribute set 
    Dim oNewPS As AttributeSet 
    If oDoc.AttributeManager.FindAttributeSets(oNameOfNewPS).Count > 0 Then 
       ' if the set exists aleady 
       Set oNewPS = oDoc.AttributeSets(oNameOfNewPS) 
      ' you can clean up the existing attributes 
    Else 
        MsgBox "no attribute set named myNewSet" 
        Exit Sub 
    End If 
    Dim oShowStr As String 
    oShowStr = ""

'iterate the attributes 
    Dim oEachAtt As Attribute 
    For Each oEachAtt In oNewPS 
       oShowStr = oShowStr & " [Attribute Name]  " & oEachAtt.Name 
       If oEachAtt.Name = "ModelByte" Then 
        oShowStr = oShowStr & " [Attribute Value]  " & StrConv(oEachAtt.Value, vbUnicode) & vbCr 
       Else 
        oShowStr = oShowStr & " [Attribute Value]  " & oEachAtt.Value & vbCr 
       End If 
    Next 
    MsgBox oShowStr 
    oDoc.Close 
End Sub

VB.NET

Sub AddCustomAttribute()

Dim m_inventorApp As Inventor.Application = Nothing

m_inventorApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")

' open a document invisible

Dim oDoc As Document

oDoc = m_inventorApp.Documents.Open("c:\testpart.ipt", False)

' name of new attribute set

Dim oNameOfNewPS As String

oNameOfNewPS = "myNewSet"

' new attribute set

Dim oNewPS As AttributeSet

If oDoc.AttributeManager.FindAttributeSets(oNameOfNewPS).Count > 0Then

' if the set exists aleady

oNewPS = oDoc.AttributeSets(oNameOfNewPS)

' you can clean up the existing attributes

Else

' add a new one

oNewPS = oDoc.AttributeSets.Add(oNameOfNewPS)

End If

'the values of the attributes

Dim oIntProV As Integer

oIntProV = 100

Dim oByteProV() As Byte

oByteProV = System.Text.Encoding.Default.GetBytes("ABCDEFG")

Dim oDoubleProV As Double

oDoubleProV = 3.1415926

Dim oDateProV As String

oDateProV = "2013-3-1 15:25"

' add these attributes with the meaningful name

' assume they do not exist in the attribute set

Call oNewPS.Add("ModelCount", ValueTypeEnum.kIntegerType, oIntProV)

Call oNewPS.Add("ModelByte", ValueTypeEnum.kByteArrayType, oByteProV)

Call oNewPS.Add("ModelBasicLength", ValueTypeEnum.kDoubleType, oDoubleProV)

Call oNewPS.Add("ModelUpdateDate", ValueTypeEnum.kStringType, oDateProV)

oDoc.Save()

oDoc.Close()

End Sub

Sub ReadCustomAttribute()

Dim m_inventorApp As Inventor.Application = Nothing

m_inventorApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")

' open a document invisible

Dim oDoc As Document

oDoc = m_inventorApp.Documents.Open("c:\testpart.ipt", False)

' name of new attribute set

Dim oNameOfNewPS As String

oNameOfNewPS = "myNewSet"

' new attribute set

Dim oNewPS As AttributeSet

If oDoc.AttributeManager.FindAttributeSets(oNameOfNewPS).Count > 0Then

' if the set exists aleady

oNewPS = oDoc.AttributeSets(oNameOfNewPS)

' you can clean up the existing attributes

Else

MsgBox("no attribute set named myNewSet")

Exit Sub

End If

Dim oShowStr As String

oShowStr = ""

'iterate the attributes

Dim oEachAtt As Attribute

For Each oEachAtt In oNewPS

oShowStr = oShowStr & " [Attribute Name]  " & oEachAtt.Name

If oEachAtt.Name = "ModelByte" Then

oShowStr = oShowStr & " [Attribute Value]  " & System.Text.Encoding.Default.GetString(oEachAtt.Value) & vbCr

Else

oShowStr = oShowStr & " [Attribute Value]  " & oEachAtt.Value & vbCr

End If

Next

MessageBox.Show(oShowStr)

oDoc.Close()

End Sub

Apprentice

Sub AddCustomAttribute_Apprentice()

Dim m_ApprenticeApp As Inventor.ApprenticeServerComponent =

New Inventor.ApprenticeServerComponent()

' open a document invisble

' open a document

Dim oDoc As ApprenticeServerDocument

oDoc = m_ApprenticeApp.Open("c:\testpart.ipt")

' name of new attribute set

Dim oNameOfNewPS As String

oNameOfNewPS = "myNewSet"

' new attribute set

Dim oNewPS As AttributeSet

If oDoc.AttributeManager.FindAttributeSets(oNameOfNewPS).Count > 0Then

' if the set exists aleady

oNewPS = oDoc.AttributeSets(oNameOfNewPS)

' you can clean up the existing attributes

Else

' add a new one

oNewPS = oDoc.AttributeSets.Add(oNameOfNewPS)

End If

'the values of the attributes

Dim oIntProV As Integer

oIntProV = 100

Dim oByteProV() As Byte

oByteProV = System.Text.Encoding.Default.GetBytes("ABCDEFG")

Dim oDoubleProV As Double

oDoubleProV = 3.1415926

Dim oDateProV As String

oDateProV = "2013-3-1 15:25"

' add these attributes with the meaningful name

' assume they do not exist in the attribute set

Call oNewPS.Add("ModelCount", ValueTypeEnum.kIntegerType, oIntProV)

Call oNewPS.Add("ModelByte", ValueTypeEnum.kByteArrayType, oByteProV)

Call oNewPS.Add("ModelBasicLength", ValueTypeEnum.kDoubleType, oDoubleProV)

Call oNewPS.Add("ModelUpdateDate", ValueTypeEnum.kStringType, oDateProV)

m_ApprenticeApp.FileSaveAs.AddFileToSave(oDoc, oDoc.FullDocumentName)

m_ApprenticeApp.FileSaveAs.ExecuteSave()

End Sub

Sub ReadCustomAttribute_Apprentice()

Dim m_ApprenticeApp As Inventor.ApprenticeServerComponent =

New Inventor.ApprenticeServerComponent()

' open a document invisble

' open a document

Dim oDoc As ApprenticeServerDocument

oDoc = m_ApprenticeApp.Open("c:\testpart.ipt")

' name of new attribute set

Dim oNameOfNewPS As String

oNameOfNewPS = "myNewSet"

' new attribute set

Dim oNewPS As AttributeSet

If oDoc.AttributeManager.FindAttributeSets(oNameOfNewPS).Count > 0Then

' if the set exists aleady

oNewPS = oDoc.AttributeSets(oNameOfNewPS)

' you can clean up the existing attributes

Else

MsgBox("no attribute set named myNewSet")

Exit Sub

End If

Dim oShowStr As String

oShowStr = ""

'iterate the attributes

Dim oEachAtt As Attribute

For Each oEachAtt In oNewPS

oShowStr = oShowStr & " [Attribute Name]  " & oEachAtt.Name

If oEachAtt.Name = "ModelByte" Then

oShowStr = oShowStr & " [Attribute Value]  " & System.Text.Encoding.Default.GetString(oEachAtt.Value) & vbCr

Else

oShowStr = oShowStr & " [Attribute Value]  " & oEachAtt.Value & vbCr

End If

Next

MessageBox.Show(oShowStr)

oDoc.Close()

End Sub

Inventor文件中保存自定义数据 - 2相关推荐

  1. Inventor文件中保存自定义数据 - 1

    在一些工作流中,需要对文件本身附加一些数据,对最终用户不可见,便于下游的使用.Inventor API提供了三种方式: 1. iProperties  2. Attribute  3. IStorag ...

  2. AutoCAD .Net 在dwg文件中存储自定义数据

    问题 我需要在 dwg 文件中存储一些信息,以额外描述图形文件并使它能够和其它软件程序集成. 请问怎样才能在 dwg 文件中写入自定义数据并读取? 回答 你可以使用 Named Object Dict ...

  3. ajax从mysql提取数据在html中_Python骚操作,提取pdf文件中的表格数据!

    在实际研究中,我们经常需要获取大量数据,而这些数据很大一部分以pdf表格的形式呈现,如公司年报.发行上市公告等.面对如此多的数据表格,采用手工复制黏贴的方式显然并不可取.那么如何才能高效提取出pdf文 ...

  4. 从pcap文件中解析网络数据包

    pcap文件解析 1:pcap文件格式 2:从pcap文件中读取以太网数据包 3:c语言代码实现 4 参考链接: 1:pcap文件格式 pcap文件主要包含了三个部分,pcap文件头,数据包头,数据包 ...

  5. 【C++】读取 .csv / .xlsx 文件中的指定数据(非常实用)

      说明:如果您的文件是 .xlsx ,需要您先打开 .xlsx 文件,然后另存为 .csv 文件,最后使用下述代码进行读取!!!         注意:直接修改文件后缀不行哦!!!          ...

  6. python 提取pdf表格_用Python提取pdf文件中的表格数据

    本文作者:杨慧琳 本文编辑:周聪聪 技术总编:张学人有问题,不要怕!访问 http://www.wuhanstring.com/uploads/5_aboutus/爬虫俱乐部-用户问题登记表.docx ...

  7. python提取pdf表格数据_Python骚操作,提取pdf文件中的表格数据!

    在实际研究中,我们经常需要获取大量数据,而这些数据很大一部分以pdf表格的形式呈现,如公司年报.发行上市公告等.面对如此多的数据表格,采用手工复制黏贴的方式显然并不可取.那么如何才能高效提取出pdf文 ...

  8. 写文件 —— 将内容按照指定格式写入配置文件(fwrite()函数-》》向指定的文件中写入若干数据块)

    例如 -- 文件中的配置内容格式如下: dat.txt的文件的内容为 [root@localhost tool]# cat dat.txt  aa1213bbcc1415dd 参数说明 size_t ...

  9. c语言实现文件数据删除视频,如何用c语言实现删除文件中指定的数据;例如

    匿名用户 1级 2012-05-21 回答 你的描述不清晰,B1和B2两个结构数组,到底要删除哪个?B[2]是肯定不对的,这两个数组的长度都是2,下标只能是0和1,即B1[0], B1[1], B2[ ...

最新文章

  1. loadClass和forName 的区别
  2. python线性回归预测pm2.5_线性回归--PM2.5预测--李宏毅机器学习
  3. VTK:可视化算法之FilledContours
  4. 解决 ubuntu 14.04.1 下一个sublime text3 3065 中国输入的问题
  5. vim 寄存器 操作_vim指令
  6. 零配置 之 Spring 概述
  7. [js]JavaScript Number.toPrecision() 函数详解
  8. Git上传Github及基本操作
  9. java 方法调用关系_JAVA方法调用
  10. UIAlertView用法
  11. wzplayerEx for android(真正硬解接口,支持加密的 player)
  12. postSQL使用触发器(trigger)分表
  13. 光猫修改html灰色选项,电信光猫怎么设置(修改)wifi密码?
  14. 【参考】MTK线刷工具错误代码大全及解决方法
  15. 2000款学校教师课件培训PPT模板免费下载网址
  16. WIN10系统不小心点击了显示语言栏怎么恢复
  17. html视频顺序播放,三个视频并排显示按顺序播放的效果怎么制作?怎么使同框视频依次播放|视频合成软件...
  18. 如何取消文件关联,恢复文件默认的图标,最简单的办法!!!!!
  19. 使用java做用一张厚度为0.01米的纸折叠多少次,就可以保证厚度不低于珠穆朗玛峰的高度?
  20. 今日头条文章爬虫实战

热门文章

  1. 代理的基本原理 及用Xpath爬取代理网站IP列表 测试并存入数据库
  2. linux启动盘怎样使用,用syslinux制作U盘启动盘
  3. 【安安教具】-【工具】-【绩点计算】模拟器 教你如何用python制作绩点计算器
  4. android 9 电话录音,Android9.0的最大不爽:不能通话录音!国内用户闹情绪
  5. 电脑中字体在哪里下载,常用的几个字体插件下载
  6. linux交叉编译openssl,交叉编译openssl for linux arm-v5te-linux-gnueabi工具链
  7. 你应该考这些证书,特别是在校生
  8. cad二次开发——自动运行dll,加载菜单(收集)
  9. bashrc的作用来原理
  10. Http之libcurl库实现