Code:
Option ExplicitConst strIniFile = "C:\TEMP\dxf_2018.ini" '<-------- GGF. ANPASSEN !!!!!!!!!!!
Private Sub MultiExport()
Dim oApp As Inventor.Application
Set oApp = ThisApplication
If (oApp.Documents.Count = 0) Or Not (oApp.ActiveDocument.DocumentType = kAssemblyDocumentObject) Then
Call MsgBox("Funktion nur in Baugruppen möglich. Abbruch", vbCritical)
Exit Sub
End If
Dim oAssDoc As AssemblyDocument
Set oAssDoc = oApp.ActiveDocument
Dim oRefedDocs As DocumentsEnumerator
Set oRefedDocs = oAssDoc.AllReferencedDocuments
Dim oRefedDoc As Document
Dim sFilename As String
Dim oDrawDoc As DrawingDocument
sFilename = GetFullFileName(oAssDoc)
Set oDrawDoc = HasDrawing(oAssDoc, sFilename)
If Not oDrawDoc Is Nothing Then
Call PublishPDF(oDrawDoc, sFilename)
Call PublishDWF(oDrawDoc, sFilename)
Call PublishDXF(oDrawDoc, sFilename)
oDrawDoc.Close (True)
End If
Call ExportToSTEP(oAssDoc, sFilename)
For Each oRefedDoc In oRefedDocs
sFilename = GetFullFileName(oRefedDoc)
Set oDrawDoc = HasDrawing(oRefedDoc, sFilename)
If Not oDrawDoc Is Nothing Then
Call PublishPDF(oDrawDoc, sFilename)
Call PublishDWF(oDrawDoc, sFilename)
Call PublishDXF(oDrawDoc, sFilename)
oDrawDoc.Close (True)
End If
Call ExportToSTEP(oRefedDoc, sFilename)
Next
End Sub
Private Function GetFullFileName(ByVal oDoc As Document) As String
Dim sFullfilename As String
sFullfilename = oDoc.FullDocumentName
GetFullFileName = Left(sFullfilename, Len(sFullfilename) - 4)
End Function
Private Function HasDrawing(ByVal oDoc As Document, ByVal sFilename As String) As DrawingDocument
On Error Resume Next
Dim oApp As Inventor.Application
Set oApp = ThisApplication
Set HasDrawing = oApp.Documents.Open(sFilename & ".idw")
End Function
Private Sub PublishDWF(ByVal oDoc As Document, ByVal sFilename As String)
Dim DWFAddIn As TranslatorAddIn
Set DWFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD95-2F4D-42CE-8BE0-8AEA580399E4}")
Dim oContext As TranslationContext
Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = kFileBrowseIOMechanism
Dim oOptions As NameValueMap
Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap
Dim oDataMedium As DataMedium
Set oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
If DWFAddIn.HasSaveCopyAsOptions(oDoc, oContext, oOptions) Then
oOptions.Value("Launch_Viewer") = 0
If TypeOf oDocument Is DrawingDocument Then
oOptions.Value("Publish_Mode") = kCustomDWFPublish
oOptions.Value("Publish_All_Sheets") = 1
End If
End If
oDataMedium.FileName = sFilename & ".dwf"
Call DWFAddIn.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)
End Sub
Private Sub PublishDXF(ByVal oDoc As Document, ByVal sFilename As String)
Dim DXFAddIn As TranslatorAddIn
Set DXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")
Dim oContext As TranslationContext
Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = kFileBrowseIOMechanism
Dim oOptions As NameValueMap
Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap
Dim oDataMedium As DataMedium
Set oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
If DXFAddIn.HasSaveCopyAsOptions(oDoc, oContext, oOptions) Then
oOptions.Value("Export_Acad_IniFile") = strIniFile
End If
oDataMedium.FileName = sFilename & ".dxf"
Call DXFAddIn.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)
End Sub
Private Sub PublishPDF(ByVal oDoc As Document, ByVal sFilename As String)
Dim PDFAddIn As TranslatorAddIn
Set PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
Dim oContext As TranslationContext
Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = kFileBrowseIOMechanism
Dim oOptions As NameValueMap
Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap
Dim oDataMedium As DataMedium
Set oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
If PDFAddIn.HasSaveCopyAsOptions(oDoc, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Launch_Viewer") = False
End If
oDataMedium.FileName = sFilename & ".pdf"
Call PDFAddIn.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)
End Sub
Private Sub ExportToSTEP(ByVal oDoc As Document, ByVal sFilename As String)
Dim oSTEPTranslator As TranslatorAddIn
Set oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
If oSTEPTranslator Is Nothing Then
MsgBox "Could not access STEP translator."
Exit Sub
End If
Dim oContext As TranslationContext
Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim oOptions As NameValueMap
Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap
If oSTEPTranslator.HasSaveCopyAsOptions(oDoc, oContext, oOptions) Then
oOptions.Value("ApplicationProtocolType") = 3
oContext.Type = kFileBrowseIOMechanism
Dim oData As DataMedium
Set oData = ThisApplication.TransientObjects.CreateDataMedium
oData.FileName = sFilename & ".stp"
Call oSTEPTranslator.SaveCopyAs(oDoc, oContext, oOptions, oData)
End If
End Sub