Hello,
I use the follwoig code to export pdf and dwg in the same time.
In Inventor 2017 it's working perfect, but in 2018 I recive an error.
Can you help me?
This is the code:
Public Sub Main()
Dim oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension
oDuctName = iProperties.Value("Project", "Description")
oRevNum = iProperties.Value("Project", "Revision Number")
oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
Dim oDWGAddIn As TranslatorAddIn
oDWGAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")
oDrafstman = ThisApplication.UserName
oDocument = ThisApplication.ActiveDocument
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMediumPDF = ThisApplication.TransientObjects.CreateDataMedium
oDataMediumDWG = ThisApplication.TransientObjects.CreateDataMedium
'Choose Preselected Folder
Dim oChoice
Dim ProjectChoice As New ArrayList
ProjectChoice.Add("Export")
oFolder = "C:\Users\Cosmin\Desktop\"& ProjectChoice(oChoice) &"\"
Dim Proc As String = "Explorer.exe"
Dim Args As String = ControlChars.Quote & IO.Path.Combine("C:\", oFolder) & ControlChars.Quote
'PDF Setup
If oPDFAddIn.HasSaveCopyAsOptions(oDataMediumPDF, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 1200
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
End If
' DWG SETUP - Check whether the translator has 'SaveCopyAs' options
If oDWGAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
Dim strIniFile As String
strIniFile = "C:\folder\INVENTOR\iLogic\Save as DWG aparte sheets.ini"
' Create the name-value that specifies the ini file to use.
oOptions.Value("Export_Acad_IniFile") = strIniFile
End If
'get target folder path
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If
'Set the destination file name
Dim fileName As String
fileName = ThisDoc.FileName(False) & " - " & iProperties.Value ("Project", "Revision Number")
oDataMediumDWG.FileName = oFolder & fileName & ".dwg"
oDataMediumPDF.FileName = oFolder & fileName & ".pdf"
'Ask the User if he wants PDF or PDF+DWG
oQuestion = MessageBox.Show("For PDF select YES for PDF+DWG select NO", "PDF or PDF/DWG", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
'Publish document.
If oQuestion = vbYes Then
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMediumPDF)
Else If oQuestion = vbNo Then
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMediumPDF)
oDWGAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMediumDWG)
Else
'MessageBox.Show("Canceled", "We're doing nothing now...")
End If
If oQuestion = vbYes Or oQuestion = vbNo Then
OpenFolder= MessageBox.Show("Would you open the folder?", "PDF EXPORTED", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
'open the folder where the new files are saved
If OpenFolder = vbYes Then
Process.Start(Proc, Args)
Else
'Return
End If
Else
End If
End Sub
And the error is this:

