蒹葭苍苍,白露为霜。
所谓伊人,在水一方。

Inventor Bom集中导出

Imports System.Windows.Forms
Imports System.IO

Public Sub Main
    Dim oPath As String
    
    ' Search for the folder
    Dim Dialog = New FolderBrowserDialog()
    Dialog.ShowNewFolderButton = True
    Dialog.Description = "Jef_E Bom's export tool"

    ' Show dialog box
    If DialogResult.OK = Dialog.ShowDialog() Then
        ' User clicked 'ok' on dialog box – capture the export path
        oPath = Dialog.SelectedPath & "\"
    
    Else
        ' User clicked 'cancel' on dialog box – exit
        Return
    End If

    ' Make a reference to a directory.
    Dim oDirectoryInfo As New DirectoryInfo(oPath)
    
    ' Get a reference to each file in that directory.
    Dim oFileArray As FileInfo() = oDirectoryInfo.GetFiles()
    
    ' Display the names of the files.
    Dim oFileInfo As FileInfo
    
    ' Loop through all files in the directory (not in the sub directories.)
    For Each oFileInfo In oFileArray
        If oFileInfo.Name.contains(".iam") Then
        
            ' Open the file
            ThisApplication.Documents.Open(oFileInfo.FullName, True) 
            
            ' Export the BOM
            
            ' Set a reference to the assembly document.
            ' This assumes an assembly document is active.
            Dim oDoc As AssemblyDocument
            oDoc = ThisApplication.ActiveDocument
            
            ' Set a reference to the BOM
            Dim oBOM As BOM
            oBOM = oDoc.ComponentDefinition.BOM
            
            ' Set the structured view to 'all levels'
            oBOM.StructuredViewFirstLevelOnly = False
        
            ' Make sure that the structured view is enabled.
            oBOM.StructuredViewEnabled = True
        
            ' Set a reference to the "Structured" BOMView
            Dim oStructuredBOMView As BOMView
            oStructuredBOMView = oBOM.BOMViews.Item("Structured")
            
            Dim oExcelPath As String
            oExcelPath = oPath & System.IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName)& ".xls"
            
            ' Export the BOM view to an Excel file
            oStructuredBOMView.Export(oExcelPath, kMicrosoftExcelFormat)
            
            ' Close the document
            oDoc.Close
        
        End If
    Next
End Sub

赞(0) 打赏
未经允许不得转载:酷居科技 » Inventor Bom集中导出
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

酷居科技 更专业 更高效

联系我们插件开发

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏