Salut @Anonymous
Voici ton code, comme promis. 
J'ai remis en forme et ajouté quelques bonus.
Tu remarqueras les lignes entre "ALL CODE SETUP HERE" et "END CODE SETUP HERE"
Il s'agit de toutes les variables que tu peux configurer pour adapter le fonctionnement 
'check that the active document is a drawing file
If ThisApplication.ActiveDocument.DocumentType <> kDrawingDocumentObject Then
MessageBox.Show("Please run this rule from the drawing file.", "iLogic")
Return
End If
'Define task list
Dim TaskList As New List(Of String)
TaskList.add("DWG")
TaskList.add("DXF")
TaskList.add("DWG & DXF")
TaskList.add("Do nothing")
'Ask task to user
ToDo = InputListBox("Please choose an action above...", TaskList, TaskList, Title := "iLogic", ListName := "Choices :")
If ToDo = "Do nothing" Then
Return
Else
End If
'[ Define the needed variables
Dim oAsmDoc As AssemblyDocument
Dim oDwgDoc As DrawingDocument
Dim oAsmName, DXFIniFile, DWGIniFile, oSheetName, oViewName As String
oAsmDoc = ThisDrawing.ModelDocument
oDwgDoc = ThisApplication.ActiveDocument
oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4)
oPath = ThisDoc.Path
Dim oPoint1 As Point2d
oTG = ThisApplication.TransientGeometry
Dim oScale As Double
Dim oView As DrawingView
']
'[ ------- ALL CODE SETUP HERE -------
'Get target folder path for export
oDWGFolder = oPath & "\" & oAsmName & " DWG"
oDXFFolder = oPath & "\" & oAsmName & " DXF"
'Get target configuration files for export
DWGIniFile = "C:\temp\Config DWG.ini"
DXFIniFile = "C:\temp\Config DXF.ini"
'Set sheet parameters
oScale = 1/1
oSheetName = "Export DWG & DXF"
oSheetSize = DrawingSheetSizeEnum.kA3DrawingSheetSize
oSheetOrientation = PageOrientationTypeEnum.kLandscapePageOrientation
'oPageOrientation = PageOrientationTypeEnum.kPortraitPageOrientation
'Set view parameters
oViewName = "VIEW TO EXPORT"
oViewOrientation = ViewOrientationTypeEnum.kFrontViewOrientation
oViewStyle = DrawingViewStyleEnum.kHiddenLineDrawingViewStyle
'] ------- END CODE SETUP HERE -------
'[ Check the folders and create them if necessary
If Not System.IO.Directory.Exists(oDWGFolder) Then
System.IO.Directory.CreateDirectory(oDWGFolder)
End If
If Not System.IO.Directory.Exists(oDXFFolder) Then
System.IO.Directory.CreateDirectory(oDXFFolder)
End If
']
'[ DWG setup
'Get the DWG translator Add-In.
Dim DWGAddIn As TranslatorAddIn
DWGAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")
'Get the DXF translator Add-In.
Dim DXFAddIn As TranslatorAddIn
DXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")
'Set a reference to the active document (the document to be published).
Dim oDocument As Document
oDocument = ThisApplication.ActiveEditDocument
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = kFileBrowseIOMechanism
' Create a NameValueMap object
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
' Create a DataMedium object
Dim oDataMedium As DataMedium
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
'DWG : Check whether the translator has 'SaveCopyAs' options
If DWGAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
' Create the name-value that specifies the ini file to use.
oOptions.Value("Export_Acad_IniFile") = DWGIniFile
End If
'DXF : Check whether the translator has 'SaveCopyAs' options
If DXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
' Create the name-value that specifies the ini file to use.
oOptions.Value("Export_Acad_IniFile") = DXFIniFile
End If
'] end of DWG setup
'[ ComponentDrawings
'look at the files referenced by the assembly
Dim oRefDocs As DocumentsEnumerator
oRefDocs = oAsmDoc.AllReferencedDocuments
Dim oRefDoc As Document
'this expects that the model has a drawing of the same path and name
For Each oRefDoc In oRefDocs
idwPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "idw"
'check to see that the model has a drawing of the same path and name
If(System.IO.File.Exists(idwPathName)) Then
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.Documents.Open(idwPathName, True)
'If Sheet 2 doesn't exist then create it
If oDrawDoc.Sheets.Count = 1 Then oDrawDoc.Sheets.Add()
oDrawDoc.Sheets(2).Name = oSheetName
oDrawDoc.Sheets(2).Size = oSheetSize
oDrawDoc.Sheets(2).Orientation = oSheetOrientation
oPoint1 = oTG.CreatePoint2d(oDrawDoc.Sheets(2).Width / 2, oDrawDoc.Sheets(2).Height / 2)
'If 1 view doesn't exist then create it
If oDrawDoc.Sheets(2).DrawingViews.Count = 0 Then
oView = oDrawDoc.Sheets(2).DrawingViews.AddBaseView(oRefDoc, oPoint1, oScale, oViewOrientation, oViewStyle, "Master")
End If
'Set view parameters, if view already exists
oDrawDoc.Sheets(2).DrawingViews(1).Name = oViewName
oDrawDoc.Sheets(2).DrawingViews(1).Scale = oScale
oDrawDoc.Sheets(2).DrawingViews(1).Position = oPoint1
oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) -3)
On Error Resume Next ' if DWG exists and is open or read only, resume next
'Write out the documents following choices
If ToDo = "DWG" Or ToDo = "DWG & DXF" Then
'Set the DWG target file name
oDataMedium.FileName = oDWGFolder & "\" & oFileName & "dwg"
Call DWGAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDataMedium)
End If
If ToDo = "DXF" Or Todo = "DWG & DXF" Then
'Set the DXF target file name
oDataMedium.FileName = oDXFFolder & "\" & oFileName & "dxf"
Call DXFAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDataMedium)
End If
'close the file
oDrawDoc.Sheets(1).Activate
oDrawDoc.Save
oDrawDoc.Close
Else
'If the model has no drawing of the same path and name - do nothing
End If
Next
'] End of ComponentDrawings
'[ Top Level Drawing
'If Sheet 2 doesn't exist then create it
If oDwgDoc.Sheets.Count = 1 Then oDwgDoc.Sheets.Add()
'Set sheet parameters
oDwgDoc.Sheets(2).Name = oSheetName
oDwgDoc.Sheets(2).Size = oSheetSize
oDwgDoc.Sheets(2).Orientation = oSheetOrientation
oPoint1 = oTG.CreatePoint2d(oDwgDoc.Sheets(2).Width / 2, oDwgDoc.Sheets(2).Height / 2)
'If 1 view doesn't exist then create it
If oDwgDoc.Sheets(2).DrawingViews.Count = 0 Then
oView = oDwgDoc.Sheets(2).DrawingViews.AddBaseView(oAsmDoc, oPoint1, oScale, oViewOrientation, oViewStyle, "Master")
End If
'Set view parameters
oDwgDoc.Sheets(2).DrawingViews(1).Name = oViewName
oDwgDoc.Sheets(2).DrawingViews(1).Scale = oScale
oDwgDoc.Sheets(2).DrawingViews(1).Position = oPoint1
On Error Resume Next ' if DWG exists and is open or read only, resume next
'Write out the documents following choices
If ToDo = "DWG" Or ToDo = "DWG & DXF" Then
'Set the DWG target file name
oDataMedium.FileName = oDWGFolder & "\" & oAsmName & ".dwg"
Call DWGAddIn.SaveCopyAs(oDwgDoc, oContext, oOptions, oDataMedium)
End If
If ToDo = "DXF" Or Todo = "DWG & DXF" Then
'Set the DXF target file name
oDataMedium.FileName = oDXFFolder & "\" & oAsmName & ".dxf"
Call DXFAddIn.SaveCopyAs(oDwgDoc, oContext, oOptions, oDataMedium)
End If
oDwgDoc.Sheets(1).Activate
oDwgDoc.Save
'] Top Level Drawing
MessageBox.Show("New Files Created... :-)", "iLogic")
Bon tests 
Thomas
Mechanical Designer / Inventor Professional 2025
