EaBIM一直以来积极响应国家“十二五”推进建筑业信息化的号召,对建筑领域的信息技术开展深入技术交流和探讨!致力于打造“BIM-建筑师-生态技术”三位一体综合资源交流共享平台,希望为BIM与可持续设计理念及技术的普及做出微小的贡献!!!

EaBIM

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
查看: 3069|回复: 42
打印 上一主题 下一主题

读取Inventor文件导入/导出选项(NameValueMap)

[复制链接]

1514

主题

7465

帖子

1万

积分

admin

Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10

积分
12404

社区QQ达人

跳转到指定楼层
楼主
发表于 2014-1-14 10:25:21 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

Inventor提供了与很多文件格式(比如DWF, DWG, DXF, IGES, STEP, SAT等)的导入/导出的功能。我们的二次开发人员可能会遇到需要对其中一些参数进行修改/设置的情况。

对于文件导入,你可以通过访问TranslatorAddin.HasOpenOptions方法来读取这些参数。对于文件导出(对应文件->另存为命令),你可以通过访问TranslatorAddin.HasSaveCopyAsOptions方法来读取这些参数。

下面是对应的VBA范例:

获取文件导入选项:(运行之前需要用你自己的.igs文件路径替换代码中的FileName的值)

  1. <p> </p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">Public Sub getImportOptions()</span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">    Dim app As Application</span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">    Set app = ThisApplication</span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">    Dim addins As ApplicationAddIns</span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">    Dim addIn As TranslatorAddIn</span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">    Set addins = app.ApplicationAddIns</span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">   </span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">    Dim i As Integer</span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; "> </span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">    'get the addin</span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">    On Error Resume Next</span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">    For i = 1 To addins.Count</span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">        If addins(i).AddInType = kTranslationApplicationAddIn Then</span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">            If addins(i).ClassIdString = "{90AF7F44-0C01-11D5-8E83-0010B541CD80}" Then</span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">                Set addIn = addins.Item(i)</span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">            End If</span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">        End If</span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">    Next i</span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">   </span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">    'Activate AddIns</span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">    addIn.Activate</span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">   </span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">    Dim dm As DataMedium</span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">    Set dm = app.TransientObjects.CreateDataMedium</span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">    dm.FileName = "C:/My Documents/Inventor/Assembly1.igs"</span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">   </span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">    Dim context As TranslationContext</span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">    Set context = app.TransientObjects.CreateTranslationContext</span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">    context.Type = kFileBrowseIOMechanism</span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">    </span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">    Dim nvm As NameValueMap</span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">    Set nvm = app.TransientObjects.CreateNameValueMap</span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">   </span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">  </span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">    'you can get the options now...</span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">    If addIn.HasOpenOptions(dm, context, nvm) Then</span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">        For i = 1 To nvm.Count</span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">            Debug.Print "[Option Name] " & nvm.Name(i) & " = " & nvm.Value(nvm.Name(i))</span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">        Next</span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">    End If</span></p><p class="MsoNormal" style="margin: 0in 0in 0pt; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">End Sub</span> </p><p><span style="font-size: small; "> </span></p>
复制代码

获取文件导出选项:Public Sub getDWFOptions()

  1. <p style="color: rgb(0, 0, 0); font-family: Arial; line-height: 26px; "><span style="font-size: small; "><span style="font-family: 宋体; "><strong></strong></span></span></p><p style="color: rgb(0, 0, 0); font-family: Arial; line-height: 26px; "><span style="font-size: 10pt; "><span style="font-family: arial, helvetica, sans-serif; ">    Dim app As Application
  2.     Set app = ThisApplication
  3.     Dim addins As ApplicationAddIns
  4.     Dim DWFAddIn As TranslatorAddIn
  5.     Set addins = app.ApplicationAddIns
  6.    
  7.     Dim i As Integer
  8.   On Error Resume Next
  9.     'Find the DWFAddIn
  10.     For i = 1 To addins.Count
  11.         If addins(i).AddInType = kTranslationApplicationAddIn Then
  12.             If addins(i).ClassIdString = "{0AC6FD95-2F4D-42CE-8BE0-8AEA580399E4}" Then
  13.                 Set DWFAddIn = addins.Item(i)
  14.             End If
  15.         End If
  16.     Next i
  17.    
  18.     'Activate AddIns
  19.     DWFAddIn.Activate
  20.    
  21.     Dim SourceObject As Object
  22.     Dim Context As TranslationContext
  23.     Dim Options As NameValueMap
  24.    
  25.     Dim transientObj As TransientObjects
  26.     Set transientObj = app.TransientObjects
  27.    
  28.     Set Context = transientObj.CreateTranslationContext
  29.     Context.Type = kUnspecifiedIOMechanism
  30.    
  31.     Set Options = transientObj.CreateNameValueMap
  32.    
  33.     Set SourceObject = ThisApplication.ActiveDocument</span></span></p><p style="color: rgb(0, 0, 0); font-family: Arial; line-height: 26px; "><span style="font-size: small; "><span style="font-family: arial, helvetica, sans-serif; ">    <span style="font-size: x-small; ">'Check whether the translator has 'SaveCopyAs' options</span></span></span></p><p style="color: rgb(0, 0, 0); font-family: Arial; line-height: 26px; "><span style="font-size: small; "><span style="font-family: arial, helvetica, sans-serif; "><span style="font-size: x-small; ">    If DWFAddIn.HasSaveCopyAsOptions(SourceObject, Context, Options) Then
  34.         For i = 1 To Options.Count
  35.             Debug.Print "[Option Name] " & Options.Name(i) & " = " & Options.Value(Options.Name(i))
  36.         Next
  37.     End If
  38. End Sub</span></span></span></p>
复制代码


如果你搞不清楚上面提到的TranslatorAddin(插件)的ClassIdString,请运行下面的代码快速读取:Public Sub getInfoForAddins()

  1. <p style="color: rgb(0, 0, 0); font-family: Arial; line-height: 26px; "><span style="font-size: small; "><span style="font-family: 宋体; "></span></span></p><p style="color: rgb(0, 0, 0); font-family: Arial; line-height: 26px; "><span style="font-size: small; "><span style="font-family: 'courier new', courier; "><span style="font-size: x-small; "><span style="font-family: arial, helvetica, sans-serif; ">    Dim addins As ApplicationAddIns
  2.     Set addins = ThisApplication.ApplicationAddIns
  3.     Dim i As Integer
  4.     For i = 1 To addins.Count
  5.         If addins(i).AddInType = kTranslationApplicationAddIn Then
  6.             Debug.Print addins(i).DisplayName & addins(i).ClassIdString
  7.         End If
  8.     Next i
  9. End Sub</span></span></span></span></p>
复制代码

文章来源:http://blog.csdn.net/barbarahan


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
收藏收藏 转播转播 分享分享 分享淘帖 支持支持 反对反对
工作时间:工作日的9:00-12:00/13:30-18:00,节假日不在线,请勿留言

4

主题

708

帖子

1142

积分

BIM项目负责人

Rank: 5Rank: 5Rank: 5Rank: 5Rank: 5

积分
1142
推荐
发表于 2014-2-18 12:26:12 | 只看该作者
路过!!!
不发表意见……

4

主题

852

帖子

1381

积分

BIM经理

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

积分
1381
推荐
发表于 2014-6-9 16:00:01 | 只看该作者
(*^__^*) 嘻嘻……

12

主题

821

帖子

1427

积分

BIM经理

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

积分
1427
推荐
发表于 2014-6-9 15:57:14 | 只看该作者
(*^__^*) 嘻嘻……

8

主题

836

帖子

1364

积分

BIM经理

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

积分
1364
8F
发表于 2014-2-18 12:25:30 | 只看该作者
(*^__^*) 嘻嘻……

6

主题

870

帖子

1737

积分

BIM经理

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

积分
1737
9F
发表于 2014-5-19 14:51:44 | 只看该作者
(*^__^*) 嘻嘻……

16

主题

893

帖子

1485

积分

BIM经理

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

积分
1485
14F
发表于 2014-5-27 11:12:59 | 只看该作者
(*^__^*) 嘻嘻……

7

主题

888

帖子

2054

积分

BIM经理

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

积分
2054
16F
发表于 2014-6-6 12:11:17 | 只看该作者
(*^__^*) 嘻嘻……
*滑块验证:
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|EaBIM网 ( 苏ICP备2020058923号-1  苏公网安备32011502011255号

GMT+8, 2024-11-23 11:28

Powered by Discuz! X3.2 Licensed

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表