I'm sorry, but I couldn't find a command that directly exits Express mode. I hope this code helps you.
Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim YourFile As String = oDoc.FullFileName
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oOptions.Add("ExpressModeBehavior", "OpenFull")
oDoc.Close()
Dim expressDoc As AssemblyDocument = ThisApplication.Documents.OpenWithOptions(YourFile, oOptions, True)
Just in case you were not familiar with how to use those commands, they are the names of ControlDefinitions, which must be found, then executed, like this:
Imports System.Windows.Forms
Imports System.IO
Imports System.Diagnostics
Sub Main()
Dim oDocument As Document = ThisApplication.ActiveDocument
' CHECK THAT PART OR ASSEMBLY FILE IS OPEN.
If Not (oDocument.DocumentType = kAssemblyDocumentObject Or oDocument.DocumentType = kPartDocumentObject) Then
MessageBox.Show("STEP können nur von 3D Modellen erzeugt werden", "Kein 3D Modell", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
' GET THE FILE NAME FROM ACTIVE DOCUMENT.
Dim oFileName As String = oDocument.DisplayName.Replace(".iam", "").Replace(".ipt", "")
' SET THE DEFAULT FOLDER PATH FOR FILE LOCATION.
Dim sUserName As String = Environ("Username")
Dim iPath As String = "C:\Users\" + sUserName + "\Documents\_Vault\"
' GET THE EXPORT FILE LOCATION FROM USER INPUT.
Dim oFilePath = InputBox("Ordnerpfad angeben:" & vbNewLine & vbNewLine _
& "Dateiname der STEP ist der Anzeigename der Baugruppe im Inventor Browser" _
& vbNewLine & vbNewLine & "Vorschau:" & vbNewLine _
& oFileName & ".stp" & vbNewLine & vbNewLine _
& "Pfad kann mittels STRG+V eingefügt werden!", "Angabe STEP Ablageort", iPath)
' CHECK IF USER INPUT IS VALID
If oFilePath = "" Then
MessageBox.Show("Export Abgebrochen", "Export Abgebrochen", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
' Exiting Express mode, only try if it's an assembly doc
If oDocument.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
Dim oAssemblyDocument As AssemblyDocument = oDocument
If oAssemblyDocument.ComponentDefinition.IsOpenExpress Then
oAssemblyDocument.ComponentDefinition.IsOpenExpress = False
End If
End If
' Change "Ansichtsdarstellung" to Mainview
Dim oCompDef As ComponentDefinition = oDocument.ComponentDefinition
oCompDef.RepresentationsManager.DesignViewRepresentations.Item("Hauptansicht").Activate()
' 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 = IOMechanismEnum.kFileBrowseIOMechanism
Dim oOptions As NameValueMap = transientObj.CreateNameValueMap
Dim oDataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium
' CHECK IF THE TRANSLATOR HAS 'SAVECOPYAS' OPTIONS
If STEP_TranslatorAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
oOptions.Value("ApplicationProtocolType") = 2 ' INTEGER
oOptions.Value("IncludeSketches") = False ' BOOLEAN
' Set application protocol.
' 2 = AP 203 - Configuration Controlled Design
' 3 = AP 214 - Automotive Design
oDataMedium.FileName = oFilePath & "\" & oFileName & ".stp"
' EXPORT STEP WITH PRE-SELECTED SETTINGS IN THE SELECTED FILE LOCATION.
Try
STEP_TranslatorAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
' Fancy Success message box
' Dim message As String = "Export erfolgreich." & vbNewLine & vbNewLine _
' & "Pfad: " & vbNewLine & oFilePath & vbNewLine & vbNewLine & "Name: " & vbNewLine & oFileName & ".stp"
' MsgBox(message, vbInformation, "Export Erfolgreich")
Catch
MessageBox.Show("Bei der STEP Erzeugung scheint etwas schief gelaufen zu sein", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
STEP_TranslatorAddIn.Deactivate()
End Sub