2 Replies Latest reply on Oct 7, 2015 4:04 AM by Peter Brinkhuis

    How to check for an open file

    Peter Brinkhuis

      Hi all,

       

      I've been working on a macro to open all configurations of a file and export them to STEP and other formats. It gets better, more complex en more user friendly over time, but it crashes when no file is opened before the macro is executed. The macro is meant to be used after a file is opened, but I'd like to be able to handle the other possibility.

       

      The first few lines are, as always:

      Set swApp = Application.SldWorks

      Set swModel = swApp.ActiveDoc

      This works, but swModel keeps a value of "nothing" as no file opened. The macro then crashes when I try to do the following:

      Set custPropMan = swModel.Extension.CustomPropertyManager("")

      What would be the best way to check if there is a file open in SW? If I know the answer to this question, I'm sure I can figure out a way to create an "open file" window.

        • Re: How to check for an open file
          Deepak Gupta

          Yes you should put codes to make sure there is an active file and that is not a drawing.

           

          Set swApp = Application.SldWorks

          Set swModel = swApp.ActiveDoc

           

          If swModel Is Nothing Then

                  MsgBox "Open a Part OR Assembly first and then TRY again!"""

                  Exit Sub

          End If

           

          If swModel.GetType = swDocDRAWING Then

           

                  MsgBox "Open a Part OR Assembly first and then TRY again!"""

                  Exit Sub

          End If

           

          Set custPropMan = swModel.Extension.CustomPropertyManager("")