5 Replies Latest reply on Sep 18, 2018 1:43 PM by Shail Patel

    Check read only status and confirm popup window.

    Alex Graff

      Hello All,


      So with help from people in the forum I was able to successfully create a macro to work through a directory opening each drawing file, deleting an old BOM, inserting a new one and then saving and closing. After getting that working I now realize there is more work to be done to make it user friendly at my work. My goal is to be able to run the macro to run on multiple files at one and walk away. The problem I am having is that we use workgroup PDM and some of the files in the working directory don't have ownership on the computer in use and an error message poos up. I am not looking for a way to take ownership, I am looking for a way to just check if a file is read only and if that file is, just skip it and move on to the next. I would imagine the easiest way to do this would be with an If statement but I don't the the code to check read only status.


      My next catch is I will occasionally run across a drawing that has a pop-up dialog box asking to confirm drawing view update when the document tries to save. Is there a way to have the macro confirm this and move on to the next drawing? Possibly even have box in front of "Don't prompt me again in this session" be checked so it is only a problem once.

      I have the same thing with the pop-up "Component documents must be saved."


      Thank you all in advance for your help. I will post what code i currently have as well.


      Dim swApp As SldWorks.SldWorks

      Dim swDoc As ModelDoc2

      Dim fileerror As Long

      Dim filewarning As Long

      Const TABLE_TEMPLATE As String = "Revision table template location"

      Dim swModel As SldWorks.ModelDoc2

      Dim swDraw As SldWorks.DrawingDoc

      Dim swSheet As SldWorks.Sheet

      Dim vViews As Variant

      Dim swView As SldWorks.View

      Dim swTableAnn As SldWorks.TableAnnotation

      Dim swAnn As SldWorks.Annotation

      Dim swRevTableAnn As SldWorks.RevisionTableAnnotation






      Const folder As String = "C:\working\"

      Dim files As Variant


      Sub main()

          Set swApp = Application.SldWorks


          files = Dir(folder & "*.slddrw", vbNormal)

          Do While files <> ""

          'Open files in folder

              swApp.OpenDoc6 folder & files, swDocDRAWING, 0, "", fileerror, filewarning

              files = Dir


          Set swModel = swApp.ActiveDoc

          Set swDraw = swModel

          Set swSheet = swDraw.GetCurrentSheet


          'Delete existing revision table

          Set swView = swDraw.GetFirstView

          Do While Not swView Is Nothing

              Set swTableAnn = swView.GetFirstTableAnnotation

              While Not swTableAnn Is Nothing

                  If swTableAnn.Type = swTableAnnotation_RevisionBlock Then

                      Set swAnn = swTableAnn.GetAnnotation

                      swAnn.Select3 False, Nothing

                      swModel.Extension.DeleteSelection2 Empty

                      Exit Do

                  End If

                  Set swTableAnn = swTableAnn.GetNext


              Set swView = swView.GetNextView



          'Add new revision table

          Set swRevTableAnn = swSheet.InsertRevisionTable(True, Empty, Empty, _

              swBOMConfigurationAnchor_TopRight, TABLE_TEMPLATE)


          swModel.Save3 0, 0, 0


          'Get title and close

          Dim swTitle As String

          Dim Part As Object

          Set Part = Nothing

          swTitle = swModel.GetTitle

          swApp.CloseDoc swTitle



      End Sub