hello, i have some code that exports all my drawings from an assembly in .dwg, with the part as there name but i need it to export with the part number. i've tried some variations but can't seem to figure it out.
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 =(iProperties.Value("Project", "Part Number"), "-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:\Users\Monkey\Documents\Modularte\Cubo\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
Solved! Go to Solution.
Solved by bradeneuropeArthur. Go to Solution.
Change this:
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 =iProperties.Value("Project", "Part Number")& "-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:\Users\Monkey\Documents\Modularte\Cubo\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
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!
! For administrative reasons, please mark a "Solution as solved" when the issue is solved !
Can't find what you're looking for? Ask the community or share your knowledge.