I have written some very complex macros, but for some reason, this one just isn't' working for me. I have been on it for a few hours, and I am just not getting it. I think the switch from model to drawing is throwing things off. I have spent a lot of time in Google and this forum. There are similar type macros, but not exactly what I want. I need some help please.
What I want. I have a part/assembly open, I run the macro, a new drawing is created with the default template, a single iso view is inserted somewhere in the middle of the sheet, and a BOM is inserted from that view, and then saved in the same folder using the same name as the model. Auto ballooning the view would be a plus, but not a need.
I can create the drawing, insert the view, but I can't select the view to insert a BOM and ballooning. Then I can't get the save to work. This is maddening.
I have tried quite a few things that didn't work. I left a couple of lines that I thought had merit, however they are commented out.
Sub Auto_Create_Drawing_Main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swDraw As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim swConfig As Configuration
Dim sDefaultTemplatePath As String
Dim sDrawingPath As String
Dim bRet As Boolean
Dim lErrs As Long
Dim lWarnings As Long
Dim sConfigName As String
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
'swConfig = swModel.GetActiveConfiguration
'sConfigName = swConfig.Name
sDefaultTemplatePath = swApp.GetUserPreferenceStringValue(swDefaultTemplateDrawing) ' get default template
Set swDraw = swApp.NewDocument(sDefaultTemplatePath, 0, 0, 0) ' new drawing using template
Set swView = swDraw.CreateDrawViewFromModelView3(swModel.GetPathName, "*Isometric", 0.42, 0.3, 0) ' insert iso view
'bRet = swModelDocExt.SelectByID2("Drawing View1", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0) ' select view
'bRet = swDrawing.ActivateView("Drawing View1") ' activate view
'Set swView = swModel.GetFirstView ' get the first view on the sheet
'bRet = swView.InsertBomTable3(True, 0, 0, , 2, sConfigName, "C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\lang\english\bom-standard.sldbomtbt", False)
'save drawing
sDrawingPath = Left(swModel.GetPathName, Len(swModel.GetPathName) - 6) & "slddrw" ' path to save drawing
'bRet = swDraw.Extension.SaveAs(sDrawingPath, swSaveAsCurrentVersion, swSaveAsOptions_Silent, lErrs, lWarnings)
'bRet = swModelDocExt.SaveAs(sDrawingPath, swSaveAsCurrentVersion, swSaveAsOptions_Silent, Nothing, lErrs, lWarnings)
End Sub