Something like this?
Imports System.IO.Path
Imports System.IO
Imports System.Collections
Imports System.Windows.Forms
'Check it is an .idw
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
MessageBox.Show("This is not a drawing. This rule can only be run in an .idw environment" & vbNewLine & "The rule will exit...", "Error Handling",MessageBoxButtons.OK,MessageBoxIcon.Error)
Return
End If
' Check that this file has been saved and actually exists on disk
If String.IsNullOrEmpty(ThisDoc.Path) Then
MessageBox.Show("This file has not yet been saved and doesn't exist on disk!" & vbLf & "Please save it first","Error Handling",MessageBoxButtons.OK,MessageBoxIcon.Error)
Return
End If
strPath_Original = ThisDoc.Path
strExportPath = ThisDoc.Path & "\01.Data\"
If System.IO.Directory.Exists(strExportPath) = False Then
System.IO.Directory.CreateDirectory(strExportPath)
End If
Dim strIniFile As String
strIniFile = "C:\path to export file\ExportDWG.ini"
'Check that the export configuration file is downloaded
If System.IO.File.Exists(strIniFile) = False Then
MessageBox.Show("Cannot find the export configuration file: " & vbNewLine & strIniFile & vbNewLine & "The rule will exit...", "Error Handling", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End If
Dim oDDoc As DrawingDocument = ThisDrawing.Document
i = 0
For Each S As Sheet In oDDoc.Sheets
i += 1
If S Is oDDoc.ActiveSheet Then
ExportFilename = strExportPath & "Sheet " & i & "_DWG 2D.dwg"
End If
Next
' Get the DWG translator Add-In
Dim DXFAddIn As TranslatorAddIn
DXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")
Dim oDocument As Document
oDocument = ThisApplication.ActiveDocument
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
Dim oDataMedium As DataMedium
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
If DXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
oOptions.Value("Export_Acad_IniFile") = strIniFile
End If
'Set the DXF target file name
oDataMedium.FileName = ExportPath & ExportFilename
MessageBox.Show(oDataMedium.FileName, "Filename")
Try
'Publish document
DXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
Catch
MessageBox.Show("Error writing out DWG", "Error Handling",MessageBoxButtons.OK,MessageBoxIcon.Error)
End Try
Export file attached, just unzip and put it somewhere with your system files.