Thanks @WCrihfield, that worked a treat.
As you rightly pointed out, a lot of duplicate files will be created using each view, so I swapped that out for a single view.
There were some other modifications I made to accommodate the export code & it's a great result.
Here's the full code, for anyone interested:
Imports System.Windows.Forms
Public Sub Main
Dim drawingDoc As Inventor.DrawingDocument = ThisDoc.Document
Dim strSaveAsSuff As String = " Rev " & iProperties.Value("Custom", "c_Revision_Nº")
' Get current location of this file
Dim ExportPath As String = ThisDoc.Path
' Check that this file has been saved and actually exists on disk
If String.IsNullOrEmpty(ExportPath) Then
MsgBox("This file has not yet been saved and doesn't exist on disk!")
Return
End If
' Browse for location to save file
Dim dialog = New FolderBrowserDialog()
dialog.SelectedPath = ExportPath
If dialog.ShowDialog() = DialogResult.OK Then
For Each sht As Sheet In drawingDoc.Sheets
Dim oView As DrawingView = sht.DrawingViews.Item(1)
' export part if part, export assembly if assembly
Dim refDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
If refDoc.DocumentType = kPartDocumentObject Then
'ExportToStepFile(refDoc, dialog.SelectedPath)
ExportToStepFile(refDoc, dialog.SelectedPath, strSaveAsSuff)
Else If refDoc.DocumentType = kAssemblyDocumentObject Then
'ExportToStepFile(refDoc, dialog.SelectedPath)
ExportToStepFile(refDoc, dialog.SelectedPath, strSaveAsSuff)
End If
Next 'sheet
End If
End Sub
Public Sub ExportToStepFile(docToExport As Document, selectedFolderPath As String, selectedSuffix as String)
' Get the STEP translator Add-In.
Dim stepTranslator As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
Dim translatorContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim translatorOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
Dim newFilename as string = doctoexport.displayname.replace(".ipt","").replace(".iam","")
Dim expPATH as string = selectedFolderPath & "\STP"
newfilename = newfilename & selectedsuffix
if doctoexport.documenttype = kassemblydocumentobject then newfilename = newfilename &".iam" else newfilename = newfilename & ".ipt"
If stepTranslator.HasSaveCopyAsOptions(docToExport, translatorContext, translatorOptions) Then
translatorOptions.Value("ApplicationProtocolType") = 3
translatorContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim translatorData As DataMedium = ThisApplication.TransientObjects.CreateDataMedium
translatorData.FileName = expPATH & "\" & System.IO.Path.ChangeExtension(newFilename, ".stp")
stepTranslator.SaveCopyAs(docToExport, translatorContext, translatorOptions, translatorData)
End If
End Sub
And thanks to @Zach.Stauffer for the original export code.