2 Replies Latest reply on May 26, 2011 10:41 AM by Yann Le Dirach

    SW Drawing : Change sheets name with active configuration of a model

    Yann Le Dirach

      Hello all,

       

      I got SW drawing with , on eacxh sheets, 1 part or assembly. These part or assembly comes with a specific configuration.

       

      I want to rename the sheets regarding the active configuration ot the firstview (face) per sheet in vba.

       

      I know how to rename each sheet, i just need to retreive the actual configuration on a model in a view.

       

       

      Than in advance

        • Re: SW Drawing : Change sheets name with active configuration of a model
          Wayne Matus

          From the API help file.

           

          Get Configurations Referenced in View Example (VBA)

          This example shows how to get the names of the configurations referenced in  each drawing view in the drawing sheet.

           

          '-------------------------------------

          '

          ' Preconditions: Drawing document is open.

          '

          ' Postconditions: None

          '

          '--------------------------------------

          Option Explicit

          Sub main()

              Dim  swApp                       As  SldWorks.SldWorks

              Dim  swModel                     As  SldWorks.ModelDoc2

              Dim  swDraw                      As  SldWorks.DrawingDoc

              Dim  swView                      As  SldWorks.view

              Dim  bRet                        As  Boolean

           

              Set  swApp = Application.SldWorks

              Set  swModel = swApp.ActiveDoc

              Set  swDraw = swModel

           

              Debug.Print  "File = " & swModel.GetPathName

           

              Set  swView = swDraw.GetFirstView

              Do  While Not swView Is Nothing

                  Debug.Print  "  View = " +  swView.Name

                  Debug.Print  "    Model  = " + swView.GetReferencedModelName

                  Debug.Print  "    Config = " +  swView.ReferencedConfiguration

           

                  Set  swView = swView.GetNextView

              Loop

          End Sub

            • Re: SW Drawing : Change sheets name with active configuration of a model
              Yann Le Dirach

              thanks wayne,

               

              I got the link and here's the complete code in vba

               

               

              ******************************************

              Dim swApp As SldWorks.SldWorks
              Dim swModel As SldWorks.ModelDoc2
              Dim swDraw As SldWorks.DrawingDoc
              Dim swSheet As SldWorks.Sheet
              Dim swModelview2 As Configuration
              Dim vSheets As Variant
              Dim swView As SldWorks.View
              Dim i As Integer

              Sub main()
              Set swApp = Application.SldWorks
              Set swModel = swApp.ActiveDoc
              Set swDraw = swModel
              Dim ConfigName As String

              vSheets = swDraw.GetSheetNames
              For i = 1 To swDraw.GetSheetCount
              swDraw.ActivateSheet vSheets(i - 1)
              Set swSheet = swDraw.GetCurrentSheet
              Count = swDraw.GetModelViewCount

              Set swView = swDraw.GetFirstView

              Do While Not swView Is Nothing
              ConfigName = swView.ReferencedConfiguration
              Set swView = swView.GetNextView
              Loop
              swSheet.SetName "Config N°" & i & " : " & ConfigName
              Next i
              Exit Sub

              *****************************