2 Replies Latest reply on Apr 19, 2017 11:21 PM by Damian Gillespie

    Turn off sheet format with API

    Damian Gillespie

      Hi All,

      Not a programmer but trying.

      I am trying to turn off the sheet format of a specific sheet named "DXF Sheet". There could be multiple sheets in the drawings but only this sheet is to be turned off. The code below is not really doing what i want. For some reason it is turning the active sheet off from when i start the macro. I need to cycle through all sheets to find the correct sheet then turn off the "DXF Sheet"

      Any help would be great





      Dim SwDraw As DrawingDoc, SwSheet As Sheet

      Dim DXF_Sheet As String

      Dim swDrawingDoc As SldWorks.DrawingDoc


      Sub main()

        Set SwDraw = Application.SldWorks.ActiveDoc

        Set SwSheet = SwDraw.GetCurrentSheet

        vSheetNames = SwDraw.GetSheetNames

        DXF_Sheet = "DXF Sheet"



      For i = 0 To UBound(vSheetNames)

              SheetName = vSheetNames(i)




                  'MsgBox SheetName

                  If SheetName = DXF_Sheet Then

                      SheetName = "DXF Sheet"

                      SwDraw.ActivateSheet (SheetName)

                      Debug.Print SwSheet.GetName

                      SwSheet.SheetFormatVisible = False


                  End If

      Next i

      SwDraw.ActivateSheet vSheetNames(0)

        • Re: Turn off sheet format with API
          Deepak Gupta

          Good start Damian. Try these codes


          Option Explicit
          Sub main()
              Dim swApp                      As SldWorks.SldWorks
              Dim swModel                   As SldWorks.ModelDoc2
              Dim swDraw                    As SldWorks.DrawingDoc
              Dim vSheetName            As Variant
              Dim i                                As Long
              Set swApp = Application.SldWorks
              Set swModel = swApp.ActiveDoc
              Set swDraw = swModel    
              vSheetName = swDraw.GetSheetNames
              For i = 0 To UBound(vSheetName)
                  If vSheetName(i) = "DXF Sheet" Then
                   swDraw.ActivateSheet vSheetName(i)
                   swDraw.GetCurrentSheet.SheetFormatVisible = False
                  End If
              Next i    
              swDraw.ActivateSheet (vSheetName(0))
          End Sub



          The issue with your codes is that you're setting SwSheet as the current active sheet (before looping and find the DXF sheet). And hence macro is hiding that sheet's format

          • Re: Turn off sheet format with API
            Damian Gillespie

            Thanks Deepak. All makes sense now.