12 Replies Latest reply on Aug 30, 2016 7:19 AM by Marko Rebec

    Drawings do not Save on disk

    Marko Rebec

      Hi,

       

      I am working on a macro to generate drawing and other thing from assembly components.I have a problem becouse newly generated drawings do NOT save if I use No. 2. way of saving it does not save the file! If I use No. 1. works fine but I get windows explorer window to save the drawing.I would like the file to be saved silently with no user touch.

      Here is a sub I use to save:

      2016-08-29_1712.png

      Thank you for any help.

        • Re: Drawings do not Save on disk
          Scott Stuart

          If you have not previously saved the drawing you will need to use swModel.Extension.SaveAs method to save it for the first time. That method will allow you to specify the silent option. Subsequent saves can use the Save3 method.

          • Re: Drawings do not Save on disk
            Ivana Kolin

            2016 SOLIDWORKS API Help - Save3 Method (IModelDoc2)

            swModel.Save3(swSaveAsOptions_e.swSaveAsOptions_Silent + swSaveAsOptions_e.swSaveAsOptions_SaveReferenced, errors, warnings)

             

            I hate code screendump. As far as I can see, you are saving you assembly or part and indirectly your drawing. Why not this way?

             

            swDraw.Save3(swSaveAsOptions_e.swSaveAsOptions_Silent , errors, warnings)

              • Re: Drawings do not Save on disk
                Marko Rebec

                Sorry for the screendump but I have several sub procedures and maybe I mest up with the different type of variables I pass to these procedures.I tried both variants Scotts and yours with No succes.Yes I try to import a STEP assembly add some custom preperties

                and then make drawings from parts and assemblies.Untill now all was going well and now I got stuck with (probably) the simpliest thing I have to do.Can you please pass me a simple code how to make From active assembly a drawing for a part and save it and close it (that last I can even manage!).I creat a NewDocument put in BOM and Annottations and then I can not save the THING.

                Apreciate any help and thanks to both of you.

                  • Re: Drawings do not Save on disk
                    Ivana Kolin

                    as Scott Stuart wrote you need to save your drawing first time with saveAs, to give it filename, maybe is that an issue why your drawing is not saving

                     

                    Option Explicit
                    Dim swApp                                         As SldWorks.SldWorks
                    Dim swModel                                       As SldWorks.ModelDoc2
                    Dim swDrawingModel                                    As SldWorks.ModelDoc2
                    Dim swModelDocExt                                 As SldWorks.ModelDocExtension
                    Dim swDrawing                                     As SldWorks.DrawingDoc
                    Dim swSelmgr                                      As SldWorks.SelectionMgr
                    Dim swView                                        As SldWorks.View
                    Dim retval                                        As String
                    Dim status                                        As Boolean
                    Dim errors                                        As Long
                    Dim warnings                                      As Long
                    
                    Sub main()
                        Set swApp = Application.SldWorks
                        Set swModel = swApp.ActiveDoc
                        If swModel.GetPathName = "" Then
                            MsgBox "Save document"
                            Exit Sub
                        End If
                        retval = swApp.GetUserPreferenceStringValue(swDefaultTemplateDrawing)
                        Set swDrawingModel = swApp.NewDocument(retval, 0, 0, 0)
                        Set swDrawing = swDrawingModel
                        Set swModelDocExt = swDrawingModel.Extension
                        Set swSelmgr = swDrawingModel.SelectionManager
                      
                        Set swView = swDrawing.CreateDrawViewFromModelView3(swModel.GetPathName, "*Front", 0.1314541543147, 0.1407887187817, 0)
                      
                        status = swModelDocExt.SelectByID2("Drawing View1", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)
                        status = swDrawing.ActivateView("Drawing View1")
                        swModel.ClearSelection2 True
                        swModelDocExt.SaveAs "d:\newDrawing.slddrw", 0, swSaveAsOptions_e.swSaveAsOptions_Silent, Nothing, errors, warnings
                      
                    
                    End Sub
                    
                    
                    
                    
                    
                    
                      • Re: Drawings do not Save on disk
                        Marko Rebec

                        Thanks for this Ivana.But stil having problems.When I try to put avariable instead fix path it gives me an error?

                        Option Explicit
                        Dim swApp                                     As SldWorks.SldWorks
                        Dim swModel                                   As SldWorks.ModelDoc2
                        Dim swDrawingModel                            As SldWorks.ModelDoc2
                        Dim swModelDocExt                             As SldWorks.ModelDocExtension
                        Dim swDrawing                                 As SldWorks.DrawingDoc
                        Dim swSelmgr                                  As SldWorks.SelectionMgr
                        Dim swView                                    As SldWorks.View
                        Dim retval                                    As String
                        Dim FileName                                  As String
                        Dim status                                    As Boolean
                        Dim errors                                    As Long
                        Dim warnings                                  As Long
                        Sub main()
                            Set swApp = Application.SldWorks
                            Set swModel = swApp.ActiveDoc
                          
                            Set FileName = swModel.GetPathName
                          
                            Debug.Print swModel.GetPathName

                         

                            If swModel.GetPathName = "" Then
                                MsgBox "Save document"
                                Exit Sub
                            End If
                            retval = swApp.GetUserPreferenceStringValue(swDefaultTemplateDrawing)
                            Set swDrawingModel = swApp.NewDocument(retval, 0, 0, 0)
                            Set swDrawing = swDrawingModel
                            Set swModelDocExt = swDrawingModel.Extension
                            Set swSelmgr = swDrawingModel.SelectionManager
                            Set swView = swDrawing.CreateDrawViewFromModelView3(swModel.GetPathName, "*Front", 0.1314541543147, 0.1407887187817, 0)
                            status = swModelDocExt.SelectByID2("Drawing View1", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)
                            status = swDrawing.ActivateView("Drawing View1")
                            swModel.ClearSelection2 True
                            swModelDocExt.SaveAs FileName, 0, swSaveAsOptions_e.swSaveAsOptions_Silent, Nothing, errors, warnings
                          

                        swApp.CloseDoc FileName

                        Set swApp = Application.SldWorks

                        End Sub

                         

                        2016-08-30_1154.png