Hi. I was wondering if anyone had a macro to save ALL drawings sheets to one dwg file into a specific folder using our custom mapping options. Thanks
I believe what you are trying to do is to save SolidWorks drawing file ".slddrw" which contains more than 1 drawing sheets into one ".dwg" file into a specific location using custom mapping options. If it is the case try this:
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim dwgName As String
Dim lErrors As Long
Dim lWarning As Long
Dim bSave As Boolean
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If Not swModel Is Nothing Then
dwgName = swModel.GetPathName 'Gets the path of the drawing document.
If Not dwgName = Empty Then
dwgName = Right(dwgName, Len(dwgName) - InStrRev(dwgName, "\")) 'Saves the drawing name including extension ".slddrw".
If swModel.GetType = swDocumentTypes_e.swDocDRAWING Then
dwgName = Left(dwgName, Len(dwgName) - (Len(dwgName) - InStrRev(dwgName, ".") + 1)) 'Saves the drawing name without extension ".slddrw".
'Warning message if the active document is not a Drawing Document.
swApp.SendMsgToUser2 "'" + dwgName + "' is not a Drawing Document. Open or Activate Drawing Document.", swMbStop, swMbOk
'Warning message if the document is not saved.
swApp.SendMsgToUser2 "Drawing Document must be saved before running the macro.", swMbStop, swMbOk
'Warning message if there is no ducoment open.
swApp.SendMsgToUser2 "No document is open. Open Drawing Document.", swMbStop, swMbOk
bSave = swModel.Extension.SaveAs("YOUR LOCATION" + dwgName + ".dwg", swSaveAsVersion_e.swSaveAsCurrentVersion, _
swSaveAsOptions_e.swSaveAsOptions_Silent, Nothing, lErrors, lWarning)
If bSave = False Then
'Warning message if failed to save drawing document as DWG file.
swApp.SendMsgToUser2 "Failed to save drawing document as DWG.", swMbStop, swMbOk
Just change the words "YOUR LOCATION" in the macro with your the location where you want to save the dwg file. Set up all your DWG options before running the macro e.g. custom mapping, scale output etc. I have tried the macro and works OK. The macro uses Solidworks drawing file name and saves the dwg file with the same name.
Thanks. It worked great. Thanks again. I do have one more question though. If i want to be able to have it go to certain folder then be able to choose what sub sub-folder location to go to is this possible also. There is a guy that saves to all kinds of different folders here and its just has to do with what project he works on.
Just replace 'bSave = swModel.Extension.SaveAs....' with this 'bSave = swModel.Extension.RunCommand(swCommands_SaveAs, Empty)'.
It will open native Solidworks Save As dialog box & you can choose the folder where you want to save the DWG file. But by doing this, you defeat the purpose of the macro. You should just use 'File --> Save As' instead.
Is the folder path where you save the DWG document related to Solidworks drawing document path? I mean, you can use the path of the Solidworks drawing document and find the path of the folder to save DWG document, if it is located in the same project folder and if it is in same manner all times.
Retrieving data ...