2 Replies Latest reply on Mar 12, 2015 12:29 PM by Joe Walton

    Using a macro change all pages to have the same CustomPropertyView View #.

    Joe Walton

           Alright, I've looked everywhere and I can't seem to find a true answer, if there even is one.

           I have a macro that will traverse all my drawing sheets and update my drawing sheets and this works fine.  While updating the sheets, I also want all sheets to have the same custompropertview View #, which just so happens to be on page #1.  Currently I can get page 1 to set to the view on page 1 (Ex: Drawing View1).  The problem is that I can't get Drawing View1 to be set for Page 2 and more because Drawing View 1 only exists on Page 1.

           The manual solution is to go to each page, right click, go to properties and in "Use custom property values from model shown in:" drop down select Drawing View 1.

           I can't rely on "Default" as the property to use because not all drawings have started on page 1 hence "Default" doesn't always represent Drawing View 1.

       

           I currently have Solidworks 2015 SP 2.0 installed.

       

      Here is my code:

          Dim swView                      As SldWorks.View

          Dim bRet                          As Boolean

          Dim vSheetNames           As Variant

          Dim Fsheet                      As sheet

          Dim Osheet                      As String

          Dim Name                        As String

          Dim vSheetProps             As Variant

         

          Set swApp = Application.SldWorks

          Set swModel = swApp.ActiveDoc

          Set swDraw = swModel

          Set swSheet = swDraw.GetCurrentSheet

         

          'get list of sheet names

          vSheetNames = swDraw.GetSheetNames

          'get current sheet name

          Osheet = swSheet.GetName

          'Go to First Sheet

          bRet = swDraw.ActivateSheet(vSheetNames(0))

          Debug.Print "First Sheet " & vSheetNames(0)

          'Get First Sheet View Name

          Set swView = swDraw.GetFirstView

          Set swView = swView.GetNextView

          Name = swView.GetName2

          Debug.Print "First View " & Name

          'Set sheet custom property name to view

          Set swSheet = swDraw.GetCurrentSheet

          swSheet.CustomPropertyView = Name

         

          'Traverse all sheets and change view property

          For i = 0 To UBound(vSheetNames)

              Debug.Print "********************************"

              bRet = swDraw.ActivateSheet(vSheetNames(i))

              Debug.Print "Sheet " & vSheetNames(i) & " before - view " & Name

              Set swSheet = swDraw.GetCurrentSheet

              'Place "Default" to change all the pages to be default view, which didn't work correctly.

              'Name = "Default"

              swSheet.CustomPropertyView = Name

              Debug.Print "Sheet " & vSheetNames(i) & " after - view " & swSheet.CustomPropertyView

          Next i

       

          'Go Back to original sheet

          bRet = swDraw.ActivateSheet(Osheet)

       

      End Sub

        • Re: Using a macro change all pages to have the same CustomPropertyView View #.
          Deepak Gupta

          I don't think this method would work. So use SetupSheet5 method to set the Custom Property View.

           

          Here are the codes you can use:

           

          Dim vSheetProps             As Variant

          'Traverse all sheets and change view property

              For i = 0 To UBound(vSheetNames)

                  Debug.Print "********************************"

                  bRet = swDraw.ActivateSheet(vSheetNames(i))

                  Set swSheet = swDraw.GetCurrentSheet

                  Debug.Print "Sheet " & vSheetNames(i) & " before - view " & Name

                  vSheetProps = swSheet.GetProperties

                  swDraw.SetupSheet5 swSheet.GetName, vSheetProps(0), vSheetProps(1), vSheetProps(2), vSheetProps(3), vSheetProps(4), "", vSheetProps(5), vSheetProps(6), Name, False

                  Debug.Print "Sheet " & vSheetNames(i) & " after - view " & swSheet.CustomPropertyView

              Next i

          I would also suggest you to use Option Explicit on the top of macro which would make sure that all variables have been defined.

            • Re: Using a macro change all pages to have the same CustomPropertyView View #.
              Joe Walton

              Thanks Deepak. This worked.  I have removed the section where I actually used SetupSheet5 to replace the templates as they are traversed. 

               

              My macro did the following:

              1) changed customviewproperty.

              2) updated sheet template (pulling the supposedly already updated customviewproperty)

               

              Your suggestion, and it works, did this all in 1 step. I stared at it for so long that I just completely missed it.  Thanks again.

               

              This is a very small snipit of a larger macro.  It does have Option Explicit at the beginning. I just wanted to supply enough for someone to run this part.