OK. Here's the iLogic version. This works pretty much the same way as @NachoShaw 's code does, but is in iLogic (vb.net) instead of VBA. The only known option we can deal with for the DXF Translator AddIn is the option to specify a specific 'ini' file to use when exporting the DXF. This is where your previous export settings were likely saved to. If you haven't altered this file's name or location, it should work. Although, you may still need to customize the path to match your computer system and version of Inventor. The default installed path for my computer is shown within the code. I'm using Inventor 2021 though, so you may need to change that.
The code captures the currently active drawing document and active sheet, then creates a new drawing document (silently, in the background), and copies your active sheet to that new drawing file, then deletes all other sheets from that new drawing file.
Then it proceeds to get the DXF Translator AddIn, and create the necessary variables to use its SaveCopyAs methods, then sets the one option mentioned before.
Then it checks to see if there is already an existing DXF file by that name. If there is, it pauses to let you know and ask if you want to overwrite that existing file or not.
If it didn't find an existing file, or if you said yes to the question, it then exports the new copied drawing file as a DXF with the same path and name as the original drawing file, but with the DXF file extension.
Then it closes the new temporary drawing file, without saving it (all in the background).
Here's the code.
'Make sure the active document is a drawing document.
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
MsgBox("This Rule " & iLogicVb.RuleName & " only works on Drawing Documents. Exiting.",vbOKOnly + vbCritical, "WRONG DOCUMENT TYPE")
Return
End If
'Capture the active drawing document, and its active sheet. (make sure the active sheet is the one you want to copy.)
Dim oDDoc As DrawingDocument = ThisDrawing.Document
Dim oSheet As Sheet = oDDoc.ActiveSheet
'Create the temporary drawing file, copy the sheet, then delete all sheets in new drawing.
Dim oTempDDoc As DrawingDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject,,False)
Dim oTempSheet As Sheet = oSheet.CopyTo(oTempDDoc)
For Each oTSheet As Sheet In oTempDDoc.Sheets
If oTSheet IsNot oTempSheet Then
oTSheet.Delete
End If
Next
'Get the DXF Translator AddIn
Dim oDXF_AddIn As TranslatorAddIn
For Each oAddIn As ApplicationAddIn In ThisApplication.ApplicationAddIns
If oAddIn.DisplayName = "Translator: PDF" Then
oDXF_AddIn = oAddIn
End If
Next
Dim oTO As TransientObjects = ThisApplication.TransientObjects
Dim oContext As TranslationContext = oTO.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oOptions As NameValueMap = oTO.CreateNameValueMap
Dim oDataMedium As DataMedium = oTO.CreateDataMedium
Dim oPath As String = IO.Path.GetDirectoryName(oDDoc.FullFileName)
Dim oFName As String = IO.Path.GetFileNameWithoutExtension(oDDoc.FullFileName)
oDataMedium.FileName = oPath & "\" & oFName & ".dxf"
If oDXF_AddIn.HasSaveCopyAsOptions(oTempDDoc, oContext, oOptions) Then
'If your export DXF settings are saved somewhere else or named differently, you will have to change this next line.
oOptions.Value("Export_Acad_IniFile") = "C:\Users\Public\Documents\Autodesk\Inventor 2021\Design Data\DWG-DXF\exportdxf.ini"
End If
'Check to see if the PDF already exists, if it does, ask if you want to over write existing file or not.
If System.IO.File.Exists(oDataMedium.FileName) = True Then
oAnswer = MsgBox("A PDF file with this name already exists." & vbCrLf &
"Do you want to over write it with this new one?",vbYesNo + vbQuestion + vbDefaultButton2, "PDF ALREADY EXISTS")
If oAnswer = vbNo Then Return
End If
'Publish DXF
oDXF_AddIn.SaveCopyAs(oTempDDoc, oContext, oOptions, oDataMedium)
oTempDDoc.Close(True)
Wesley Crihfield

(Not an Autodesk Employee)