Solved! Go to Solution.
Solved by rjay75. Go to Solution.
Hi Jamie,
You can write a VBA function (Tools > VBA Editor) that loops tru all the files in a specific directory, opening each file and saving it to the same folder as DWG.
For file looping inside directory:
http://stackoverflow.com/questions/10380312/loop-through-files-in-a-folder-using-vba
For saving IDW to DWG:
http://forums.autodesk.com/t5/Inventor-Customization/Inventor-IDW-To-AutoCAD-2000-DWG/td-p/2644227
I hope you'll find your answers,
Good luck!
Laurens
Here's something to get you started.
This was cobbled together using some the Export DWG sample in the API help file.
You have to use the DWG translater to save as autocad files. Before you run it you want to use the Export to DWG command to save your Autocad options. Use the name of the exported file in the strIniFile variable.
Save this code in a new external rule file.
Imports SysIO = System.IO Sub Main() 'See if there are any open views If (ThisApplication.Views.Count > 0) Then 'Setup Translator to dwg Dim DWGAddIn As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}") Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = kFileBrowseIOMechanism ' Create a NameValueMap object Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap ' Create a DataMedium object Dim oDataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium 'Go through each view and save if it's a drawing document For Each view As View In ThisApplication.Views If view.Document.DocumentType = kDrawingDocumentObject Then 'Get the directory file is saved in. Can replace this with specific directory Dim dwgDir = SysIO.Path.GetDirectoryName(view.Document.FullFileName) 'Get name of file without the extension and add _acad2k to it. oDataMedium.MediumType = kFileNameMedium oDataMedium.FileName = dwgDir & "\\" & _
SysIO.Path.GetFileNameWithoutExtension(view.Document.FullFileName) & _
"_acad2k.dwg" ' Check whether the translator has 'SaveCopyAs' options If DWGAddIn.HasSaveCopyAsOptions(view.Document, oContext, oOptions) Then 'Use Export To DWG to save drawing configuration and set here Dim strIniFile As String = "C:\\Temp\\DWGOut.ini" ' Create the name-value that specifies the ini file to use. oOptions.Value("Export_Acad_IniFile") = strIniFile 'Save File DWGAddIn.SaveCopyAs(view.Document, oContext, oOptions, oDataMedium) End If End If Next End If End Sub
Hello Rodney Thomas Good morning! sorry to bother but seeing that this issue could be resolved to export an idw to dwg, I would like to know how you can do that at the time you are recording the file asks you the destination of this as if you were doing a Save as.
Thank you very much in advance!
Below is the rule modified to display the save as dialog to select the filename and location.
Imports SysIO = System.IO Sub Main() 'See if there are any open views If (ThisApplication.Views.Count > 0) Then 'Setup Translator to dwg Dim DWGAddIn As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}") Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = kFileBrowseIOMechanism ' Create a NameValueMap object Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap ' Create a DataMedium object Dim oDataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium 'Go through each view and save if it's a drawing document For Each view As Inventor.View In ThisApplication.Views If view.Document.DocumentType = kDrawingDocumentObject Then 'Get the directory file is saved in. Can replace this with specific directory Dim dwgDir = SysIO.Path.GetDirectoryName(view.Document.FullFileName) 'Prompt User for name of file Dim saveDlg = GetFileDlg(dwgDir) saveDlg.ShowSave() 'Cancel Process if no name selected If String.IsNullOrEmpty(saveDlg.FileName) Then Exit For Dim newFileName = saveDlg.FileName 'If name is the same as document name append acad to it. If newFileName.Equals(view.Document.FullFileName) Then newFileName = dwgDir & "\\" & _ SysIO.Path.GetFileNameWithoutExtension(view.Document.FullFileName) & _ "_acad.dwg" End If 'Get name of file without the extension and add _acad2k to it. oDataMedium.MediumType = kFileNameMedium oDataMedium.FileName = newFileName ' Check whether the translator has 'SaveCopyAs' options If DWGAddIn.HasSaveCopyAsOptions(view.Document, oContext, oOptions) Then 'Use Export To DWG to save drawing configuration and set here Dim strIniFile As String = "C:\\Temp\\DWGOut.ini" ' Create the name-value that specifies the ini file to use. If SysIO.File.Exists(strIniFile) Then oOptions.Value("Export_Acad_IniFile") = strIniFile Else MessageBox.Show("The settings ouput file " + strIniFile + " cannot be found.", "Export INI")
Exit For End If 'Save File DWGAddIn.SaveCopyAs(view.Document, oContext, oOptions, oDataMedium) End If End If Next End If End Sub Private Function GetFileDlg(defaultPath As String) As Inventor.FileDialog Dim fDlg As Inventor.FileDialog ThisApplication.CreateFileDialog(fDlg) fDlg.Filter = "Autocad Drawing Files (*.dwg)|*.dwg" fDlg.DialogTitle = "Save As Autocad Drawing" If Not String.IsNullOrEmpty(defaultPath) Then fDlg.InitialDirectory = defaultPath End If Return fDlg End Function
Can't find what you're looking for? Ask the community or share your knowledge.