I didn't understand that you wanted to create Autocad Dwg file. These are a bit more difficult to make. for that to work you need to save a DWGOut.ini file (= configuration file). You can just save the settings you use when you create an Autocad Dwg manually.

the rule expects that you save that file on "C:\temp\DWGOut.ini" but you can save it anywhere but then you need to change the location in the rule. (see comments in the rule.)
This script will go into all files referenced by the assembly (also sub-assembly parts). but for the script to work the dwg file name and part/assembly file name must be the same.
Sub Main()
Dim doc As AssemblyDocument = ThisDoc.Document
For Each refDoc As Document In doc.AllReferencedDocuments
Dim fileName As String = refDoc.FullFileName
Dim ext As String = IO.Path.GetExtension(fileName)
Dim inventorDwgFileName As String = fileName.Replace(ext, ".dwg")
Dim autocadDwgFileName As String = fileName.Replace(ext, "-acad.dwg")
If (IO.File.Exists(inventorDwgFileName) = False) Then
MsgBox("Could not find inventor dwg: " & inventorDwgFileName)
Continue For
End If
Dim dwgDoc As DrawingDocument = ThisApplication.Documents.Open(inventorDwgFileName)
DWGOutUsingTranslatorAddIn(dwgDoc, autocadDwgFileName)
dwgDoc.Close(True)
Next
End Sub
Public Sub DWGOutUsingTranslatorAddIn(doc As DrawingDocument, newFileName As String)
' Set the path to your DWGOut.ini fiile here
Dim dwgOutIniFile As String = "C:\temp\DWGOut.ini"
Dim oDWGAddIn As TranslatorAddIn = Nothing
Dim i As Long
For i = 1 To ThisApplication.ApplicationAddIns.Count
If ThisApplication.ApplicationAddIns.Item(i).ClassIdString = "{C24E3AC2-122E-11D5-8E91-0010B541CD80}" Then
oDWGAddIn = ThisApplication.ApplicationAddIns.Item(i)
Exit For
End If
Next
If oDWGAddIn Is Nothing Then
MsgBox("DWG add-in not found.")
Exit Sub
End If
If (IO.File.Exists(dwgOutIniFile) = False) Then
MsgBox("Unable to find: " & dwgOutIniFile)
Exit Sub
End If
If Not oDWGAddIn.Activated Then
oDWGAddIn.Activate()
End If
Dim oNameValueMap As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap()
oNameValueMap.Add("Export_Acad_IniFile", dwgOutIniFile)
Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext()
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oOutputFile As DataMedium = ThisApplication.TransientObjects.CreateDataMedium()
oOutputFile.FileName = newFileName
Call oDWGAddIn.SaveCopyAs(doc, oContext, oNameValueMap, oOutputFile)
End Sub
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Blog: hjalte.nl - github.com