Sorry about that had variables declared outside the sub & forget to put them in there, try this.
If it's still having trouble with the windows save as dialog, we can change that to an inventor save as dialog.
Imports System.Windows.Forms
Public Sub Main()
Dim oDocument As Document = ThisApplication.ActiveDocument
Dim oFileName As String = oDocument.DisplayName.Replace(".ipt", "")
Dim oFilePath As String = oDocument.FullFileName.Replace("\" & oFileName & ".ipt", "")
' CHECK THAT PART FILE IS OPEN.
If oDocument.DocumentType <> kPartDocumentObject Then 'DOCUMENTTYPEENUM
MsgBox("The open file is not a part file. The command has been cancelled.")
Exit Sub
End If
' GET THE STEP EXPORT ADDIN USING ID & ACTIVATE IT.
Dim oInvAddIns As ApplicationAddIns = ThisApplication.ApplicationAddIns
Dim STEP_TranslatorAddIn As TranslatorAddIn = oInvAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}") 'TRANSLATOR: STP EXPORT
STEP_TranslatorAddIn.Activate()
Dim transientObj As TransientObjects = ThisApplication.TransientObjects
Dim oContext As TranslationContext = transientObj.CreateTranslationContext
oContext.Type = kFileBrowseIOMechanism
Dim oOptions As NameValueMap = transientObj.CreateNameValueMap
Dim oDataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium
' MsgBox("Before saveas check.")
' CHECK IF THE TRANSLATOR HAS 'SAVECOPYAS' OPTIONS
If STEP_TranslatorAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
oOptions.Value("ApplicationProtocolType") = 3 ' INTEGER
oOptions.Value("IncludeSketches") = False ' BOOLEAN
oOptions.Value("Organization") = "Spraying Systems Co." ' STRING
'oOptions.Value("Author") = ' STRING
'oOptions.Value("Authorization") = ' STRING
'oOptions.Value("Description") = ' STRING
'oOptions.Value("export_fit_tolerance") = ' 0.xxx-xxxxxxxx ' DOUBLE
' SHOW THE OPTIONS DIALOG.
'STEP_TranslatorAddIn.ShowSaveCopyAsOptions(oDocument, oContext, oOptions)
' SET THE STEP TARGET FOLDER PATH. CHECK FOR THE FOLDER. CREATE FOLDER IF IT DOESN'T EXIST.
'If Not System.IO.Directory.Exists(oFilePath) Then
'Try
' System.IO.Directory.CreateDirectory(oFolder)
'Catch ex As Exception
'End Try
'End If
' OPEN FILE DIALOG TO CHOOSE NAME & LOCATION OF EXPORTED STEP FILE.
' DEFAULTS TO 3D PRINTER FILE LOCATION & OPEN FILE NAME.
Dim oSaveFileDialog1 As New SaveFileDialog With
{
.InitialDirectory = oFilePath,
.Filter = "STEP Files (*.stp;*.ste;*.step;*.stpz)|*.stp;*.ste;*.step;*.stpz",
.FileName = oFileName,
.DefaultExt = ".stp"
}
' SET THE STEP TARGET FILE NAME BASED ON THE DIALOG INPUT.
If oSaveFileDialog1.ShowDialog() <> DialogResult.OK Then
Exit Sub
End If
oDataMedium.FileName = oSaveFileDialog1.FileName
' EXPORT STEP WITH PRE-SELECTED SETTINGS IN THE SELECTED FILE LOCATION.
Try
STEP_TranslatorAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
Catch ex As Exception
End Try
End If
STEP_TranslatorAddIn.Deactivate()
End Sub
If this solved your problem or answered your question, please click ACCEPT SOLUTION.
If this helped you, please click LIKE.