Skip to content

Instantly share code, notes, and snippets.

@cwg999
Last active February 2, 2017 13:01
Show Gist options
  • Save cwg999/4cd6305ca3f58cce8eb80c07c51224b3 to your computer and use it in GitHub Desktop.
Save cwg999/4cd6305ca3f58cce8eb80c07c51224b3 to your computer and use it in GitHub Desktop.
Inventor Export DWG
' For Inventor R9 (REALLY OLD)
Public Sub PublishDWG()
Dim myArray(1 To 1) As String
myArray(1) = "C:\temp\some.idw"
' Attempt to connect to a running instance of Inventor.
Dim oApp As Inventor.Application
On Error Resume Next
Set oApp = GetObject(, "Inventor.Application")
If Err Then
Err.Clear
' Failed to connect to a running instance, so start Inventor.
Set oApp = CreateObject("Inventor.Application")
If Err Then
MsgBox "Unable to connect to Inventor."
Exit Sub
End If
' Make the application visible.
oApp.Visible = False
End If
On Error GoTo 0
oApp.SilentOperation = True ' Silent Operation
Dim addIns As Inventor.ApplicationAddIns
Set addIns = oApp.ApplicationAddIns
Dim dwgAddIn As Inventor.TranslatorAddIn
Dim i As Integer
For i = 1 To addIns.Count
If addIns(i).AddInType = Inventor.ApplicationAddInTypeEnum.kTranslationApplicationAddIn Then
If addIns(i).Description = "Autodesk Internal DWG Translator" Then
Set dwgAddIn = addIns.Item(i)
Exit For
End If
End If
Next i
For j = 175 To 175
oApp.Documents.CloseAll
'Set a reference to the active document (the document to be published).
Dim oDocument As Document
Set oDocument = oApp.Documents.Open(myArray(j))
' Create a NameValueMap object
Dim oOptions As NameValueMap
Set oOptions = oApp.TransientObjects.CreateNameValueMap
' Create a DataMedium object
Dim oDataMedium As DataMedium
Set oDataMedium = oApp.TransientObjects.CreateDataMedium
Dim oContext As TranslationContext
Set oContext = oApp.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
' Check whether the translator has 'SaveCopyAs' options
If dwgAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
'Dim strIniFile As String
strIniFile = "C:\temp\dwg.ini"
' Create the name-value that specifies the ini file to use.
oOptions.Value("Export_Acad_IniFile") = strIniFile
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
'oOptions.Value("Custom_Begin_Sheet") = 3
'oOptions.Value("Custom_End_Sheet") = 3
End If
'Set the destination file name
Dim filePath As String
filePath = "C:\temp\" & Right(myArray(j), Len(myArray(j)) - 1) & ".dwg"
oDataMedium.FileName = filePath
Dim file As Variant
dwgAddIn.SaveCopyAs oDocument, oContext, oOptions, oDataMedium
Debug.Print j
Set oDocument = Nothing
Set oOptions = Nothing
Set oDataMedium = Nothing
Next j
End Sub
Sub SetPropertiesOff()
' Attempt to connect to a running instance of Inventor.
Dim oApp As Inventor.Application
On Error Resume Next
Set oApp = GetObject(, "Inventor.Application")
If Err Then
Err.Clear
' Failed to connect to a running instance, so start Inventor.
Set oApp = CreateObject("Inventor.Application")
If Err Then
MsgBox "Unable to connect to Inventor."
Exit Sub
End If
' Make the application visible.
oApp.Visible = False
End If
On Error GoTo 0
oApp.SilentOperation = False ' Silent Operation
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment