
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
We export copies of our IDW files to AutoCAD DWGs. These files get processed in AutoCAD and added to some of our customer documentation. I'm trying to write a macro in Inventor 2016 using VBA to export ("Save Copy As") the current file to an AutoCAD DWG. We do some folder organization based off our part numbering system and the macro will find the correct folder automatically (that part is working fine).
The issue I'm having is that when the current document is a multi-sheet drawing, the macro still brings up a file dialog for each sheet and asks the user to give it a name. I'm fine with the default suffix of "_Sheet1" or whatever it decides to do. I just don't want the user to be prompted with the file dialog. In addition, the file will usually be saving over top of an existing file and will also be saving outside of the current project. I don't want any of the associated messages popping up during execution of the macro.
My code is as follows:
Sub PartsBookBOMColumnsAndExport() ' Set a reference to the drawing document. ' This assumes a drawing document is active. Dim DrawingRef As DrawingDocument Set DrawingRef = ThisApplication.ActiveDocument ' Export (Save Copy As) the drawing as an AutoCAD DWG ' Get the filename of the current drawing and extract just the filename without the extension CurrentFilename = DrawingRef.FullFileName Dim FilepathParts() As String FilepathParts() = Split(CurrentFilename, "\") CurrentFilename = FilepathParts(ArrayLen(FilepathParts) - 1) CurrentFilename = Left(CurrentFilename, Len(CurrentFilename) - 4) ' Extract the series number and the first two digits of the assembly number Dim SeriesNum As String, AssyNum As String, TargetFilepath As String SeriesNum = Left(CurrentFilename, 2) AssyNum = SeriesNum + "-" + Mid(CurrentFilename, 3, 2) + "00" ' Check if the proper folders exist and create them if they don't MsgBox Dir("T:\Inventor DWG\" + SeriesNum + "\") If Dir("T:\Inventor DWG\" + SeriesNum + "\") = "" Then MkDir "T:\Inventor DWG\" + SeriesNum End If If Dir("T:\Inventor DWG\" + SeriesNum + "\" + AssyNum + "\") = "" Then MkDir "T:\Inventor DWG\" + SeriesNum + "\" + AssyNum + "\" End If ' Save the drawing as an AutoCAD DWG TargetFilepath = "T:\Inventor DWG\" + SeriesNum + "\" + AssyNum + "\" + CurrentFilename + ".dwg" Call DrawingRef.SaveAs(TargetFilepath, True) End Sub
I've been searching for other methods to use than SaveAs(), but I can't seem to find any that don't have the same behavior.
Solved! Go to Solution.