heres my code as well.
Imports System.IO
Imports System.Runtime.InteropServices
Imports System.Runtime.InteropServices.ComTypes
Imports System.Windows.Forms
Imports Inventor
Namespace d
Module Module1
Sub Main()
Dim invApp As Inventor.Application = GetInventorInstance()
If invApp Is Nothing Then
' MessageBox.Show("Autodesk Inventor is not running.")
Return
End If
Dim oDoc As Document = invApp.ActiveDocument
Dim folderPath As String = BrowseForFolder("Please select an input folder")
If String.IsNullOrEmpty(folderPath) Then
Return
End If
Dim oFSO As Object = CreateObject("Scripting.FileSystemObject")
Dim oFolder As Object = oFSO.GetFolder(folderPath)
Dim setFilePath As String = BrowseForFolder("Please select an output folder")
If String.IsNullOrEmpty(setFilePath) Then
Return
End If
For Each oFile As Object In oFolder.Files
If LCase(oFSO.GetExtensionName(oFile.Name)) = "iam" Then
Dim sFilename As String = folderPath & "\" & oFile.Name
Dim oAsmDoc As AssemblyDocument = invApp.Documents.Open(sFilename, False)
' MessageBox.Show(oAsmDoc.FullFileName)
Dim oRefDocs As DocumentsEnumerator = oAsmDoc.AllReferencedDocuments
For Each oRefDoc As Document In oRefDocs
If oRefDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
Dim oSheetMetDoc As PartDocument = invApp.Documents.Open(oRefDoc.FullFileName, True)
Dim oCompDef As SheetMetalComponentDefinition = oSheetMetDoc.ComponentDefinition
Dim oDef As FlatPattern = oCompDef.FlatPattern
If oDef Is Nothing Then GoTo NextOcc
Dim sOut As String = "FLAT PATTERN DXF?AcadVersion=2018" &
"&OuterProfileLayer=IV_INTERIOR_PROFILES" &
"&InvisibleLayers=IV_TANGENT;IV_ROLL_TANGENT"
Dim prevName As String = oSheetMetDoc.DisplayName
Dim arr() As String = prevName.Split("."c)
prevName = arr(0)
Dim sFname As String = setFilePath & "\" & prevName & ".dxf"
Dim oDataIO As DataIO = oCompDef.DataIO
oDataIO.WriteDataToFile(sOut, sFname)
oCompDef.FlatPattern.ExitEdit()
End If
NextOcc:
Next
If oDoc IsNot oAsmDoc Then
oAsmDoc.Close(True) ' True = skip save
End If
End If
Next
' MessageBox.Show("Flat patterns exported to " & setFilePath)
End Sub
Private Function GetInventorInstance() As Inventor.Application
Try
Return DirectCast(Marshal.GetActiveObject("Inventor.Application"), Inventor.Application)
Catch ex As Exception
Return Nothing
End Try
End Function
Private Function BrowseForFolder(prompt As String) As String
Using dialog As New FolderBrowserDialog()
dialog.Description = prompt
If dialog.ShowDialog() = DialogResult.OK Then
Return dialog.SelectedPath
End If
Return String.Empty
End Using
End Function
End Module
End Namespace