4 Replies Latest reply on May 23, 2018 5:59 PM by Kaijiun Cheang

    How to switch the configuration of the drawing views?

    Kaijiun Cheang

      Hi,

       

      I am trying to create a macro, that will switch the configuration of the drawing views in to my appointed name.

       

      I tried to record macro and run it, but looks like it didn’t work. The configuration stays the same as it is before.

       

      Anyone have any solution for this?

       

      Thanks for your help

       

      Attached is the macro I recorded.

       

      Dim swApp As Object

       

       

      Dim Part As Object

      Dim boolstatus As Boolean

      Dim longstatus As Long, longwarnings As Long

       

       

      Sub main()

       

       

      Set swApp = _

      Application.SldWorks

       

       

      Set Part = swApp.ActiveDoc

      Dim myModelView As Object

      Set myModelView = Part.ActiveView

      myModelView.FrameState = swWindowState_e.swWindowMaximized

      boolstatus = Part.ActivateSheet("Sheet1")

      boolstatus = Part.ActivateView("Drawing View1")

      boolstatus = Part.Extension.SelectByID2("Drawing View1", "DRAWINGVIEW", 0.129656022558782, 0.17639323452528, 0, False, 0, Nothing, 0)

      boolstatus = Part.ChangeRefConfigurationOfFlatPatternView("P:\Data\Engineering\SOLIDWORKS\AM00X-00101 BIFOLD DOOR\AM00X-00101G01.SLDASM", "CLOSED-OFFSET BIFOLD")

      Part.ViewZoomtofit2

      Part.ClearSelection2 True

      boolstatus = Part.ActivateSheet("Sheet2")

      boolstatus = Part.ActivateView("Drawing View2")

      boolstatus = Part.Extension.SelectByID2("", "EDGE", 0.108617334865133, 0.253403458635116, -24500.0945, False, 0, Nothing, 0)

      boolstatus = Part.ChangeRefConfigurationOfFlatPatternView("P:\Data\Engineering\SOLIDWORKS\AM00X-00101 BIFOLD DOOR\AM00X-00101G01.SLDASM", "CLOSED-OFFSET BIFOLD")

      boolstatus = Part.ActivateView("Drawing View3")

      boolstatus = Part.Extension.SelectByID2("Drawing View3", "DRAWINGVIEW", 0.29879326549845, 0.232182110323512, 0, False, 0, Nothing, 0)

      boolstatus = Part.ChangeRefConfigurationOfFlatPatternView("P:\Data\Engineering\SOLIDWORKS\AM00X-00101 BIFOLD DOOR\AM00X-00101G01.SLDASM", "OPENED-OFFSET BIFOLD")

      Part.ViewZoomtofit2

      Part.ClearSelection2 True

      boolstatus = Part.ActivateSheet("Sheet3")

      boolstatus = Part.ActivateView("Drawing View4")

      boolstatus = Part.Extension.SelectByID2("Drawing View4", "DRAWINGVIEW", 0.128318370555632, 0.168032909505594, 0, False, 0, Nothing, 0)

      boolstatus = Part.ChangeRefConfigurationOfFlatPatternView("P:\Data\Engineering\SOLIDWORKS\AM00X-00101 BIFOLD DOOR\AM00X-00101G01.SLDASM", "CLOSED-OFFSET BIFOLD")

      End Sub

        • Re: How to switch the configuration of the drawing views?
          Artem Taturevych

          This macro changes the configuration of the selected view

           

          Const CONF_NAME As String = "{SPECIFY CONFIG NAME HERE}"

           

          Dim swApp As SldWorks.SldWorks

          Dim swModel As SldWorks.ModelDoc2

          Dim swSelMgr As SldWorks.SelectionMgr

           

          Sub main()

           

              Set swApp = Application.SldWorks

             

              Set swModel = swApp.ActiveDoc

                 

              Set swSelMgr = swModel.SelectionManager

             

              Dim swView As SldWorks.View

             

              Set swView = swSelMgr.GetSelectedObject6(1, -1)

             

              swView.ReferencedConfiguration = CONF_NAME

             

          End Sub

            • Re: How to switch the configuration of the drawing views?
              Kaijiun Cheang

              Hi Artem,

              Thanks for your answer. I tried to modify it to suit but when i run it, it gives me run time error. Can you spot what am i missing on?

              Thanks

              Dim swApp As Object

              Dim Part As Object

              Dim boolstatus As Boolean

              Dim longstatus As Long, longwarnings As Long

               

               

              Sub main()

               

               

              Set swApp = _

              Application.SldWorks

               

               

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

              Set swSelMgr = swModel.SelectionManager

              Dim swView As SldWorks.View

               

               

              Const CONF_NAME As String = "CLOSED-OFFSET BIFOLD"

              Const CONF_NAME2 As String = "OPENED-OFFSET BIFOLD"

               

               

               

               

              boolstatus = Part.ActivateSheet("Sheet1")

              boolstatus = Part.ActivateView("Drawing View1")

              swView.ReferencedConfiguration = CONF_NAME

               

               

              boolstatus = Part.ActivateSheet("Sheet2")

              boolstatus = Part.ActivateView("Drawing View2")

              swView.ReferencedConfiguration = CONF_NAME

               

               

              boolstatus = Part.ActivateView("Drawing View3")

              swView.ReferencedConfiguration = CONF_NAME2

               

               

               

               

               

               

              boolstatus = Part.ActivateSheet("Sheet3")

              boolstatus = Part.ActivateView("Drawing View4")

              swView.ReferencedConfiguration = CONF_NAME

               

               

              End Sub

                • Re: How to switch the configuration of the drawing views?
                  Artem Taturevych

                  Hi Kaijiun,

                   

                  Try this:

                   

                  Dim swApp As SldWorks.SldWorks

                  Dim swDraw As SldWorks.DrawingDoc

                   

                  Sub main()

                   

                      Set swApp = Application.SldWorks

                   

                   

                      Set swDraw = swApp.ActiveDoc

                     

                      ChangeViewConfiguration "Sheet1", "Drawing View1", "CLOSED-OFFSET BIFOLD"

                      ChangeViewConfiguration "Sheet2", "Drawing View2", "CLOSED-OFFSET BIFOLD"

                      ChangeViewConfiguration "Sheet2", "Drawing View3", "OPENED-OFFSET BIFOLD"

                   

                  End Sub

                   

                  Sub ChangeViewConfiguration(sheetName As String, drViewName As String, confName As String)

                     

                      Dim swSheet As SldWorks.Sheet

                      Set swSheet = swDraw.Sheet(sheetName)

                     

                      Dim vViews As Variant

                      vViews = swSheet.GetViews()

                     

                      Dim i As Integer

                     

                      For i = 0 To UBound(vViews)

                         

                          Dim swView As SldWorks.View

                          Set swView = vViews(i)

                         

                          If UCase(swView.GetName2()) = UCase(drViewName) Then

                              swView.ReferencedConfiguration = confName

                              Exit Sub

                          End If

                         

                      Next

                   

                  End Sub