2 Replies Latest reply on Jun 10, 2014 9:53 PM by Yong Ning

    How to traverse Configuration(s)

    Yong Ning

      0.jpg

       

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

          • Re: How to traverse Configuration(s)
            Yong Ning

            Thanks your link web,the code is

             

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

            ' Forcibly rebuild each configuration

            Option Explicit

            Sub main()

                Dim swApp                   As SldWorks.SldWorks

                Dim swModel                 As SldWorks.ModelDoc2

                Dim vConfNameArr            As Variant

                Dim sConfigName             As String

                Dim nStart                  As Single

                Dim i                       As Long

                Dim bShowConfig             As Boolean

                Dim bRebuild                As Boolean

                Dim bRet                    As Boolean

               

                Set swApp = CreateObject("SldWorks.Application")

                Set swModel = swApp.ActiveDoc

               

                Debug.Print "File = " + swModel.GetPathName

               

                vConfNameArr = swModel.GetConfigurationNames

                For i = 0 To UBound(vConfNameArr)

                    sConfigName = vConfNameArr(i)

                   

                    bShowConfig = swModel.ShowConfiguration2(sConfigName)

                   

                    nStart = Timer

                    bRebuild = swModel.ForceRebuild3(False)

                   

                    Debug.Print "  Config       = " & sConfigName

                    Debug.Print "    ShowConfig = " & bShowConfig

                    Debug.Print "    Rebuild    = " & bRebuild

                    Debug.Print "    Time       = " & Timer - nStart & " s"

                Next i

            End Sub

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

             

            Restult is

            File = F:\MyPrograme\BE(J)S\Part1.SLDPRT
              Config       = A1
                ShowConfig = False
                Rebuild    = True
                Time       = .1875 s
              Config       = A2
                ShowConfig = True
                Rebuild    = True
                Time       = .078125 s
              Config       = A3
                ShowConfig = True
                Rebuild    = True
                Time       = .078125 s
              Config       = A4
                ShowConfig = True
                Rebuild    = True
                Time       = .078125 s

             

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


            Sub Main1()
                Dim swApp                   As SldWorks.SldWorks
                Dim swModel                 As SldWorks.ModelDoc2
                Dim vConfNameArr            As Variant
                Dim sConfigName             As String
                Dim nStart                  As Single
                Dim i                       As Long, Str
                Dim bShowConfig             As Boolean
                Dim bRebuild                As Boolean
                Dim bRet                    As Boolean
                Dim swCustProp As CustomPropertyManager
               
                Set swApp = CreateObject("SldWorks.Application")
                Set swModel = swApp.ActiveDoc
               
                Debug.Print "File = " + swModel.GetPathName
               
                vConfNameArr = swModel.GetConfigurationNames
                For i = 0 To UBound(vConfNameArr)
                    sConfigName = vConfNameArr(i)
                    Set swCustProp = swModel.Extension.CustomPropertyManager(sConfigName)
                   
                    bShowConfig = swModel.ShowConfiguration2(sConfigName)
                   
                    nStart = Timer
                    bRebuild = swModel.ForceRebuild3(False)
                    Str = "SW-Mass@@" & sConfigName & "@" & swModel.GetTitle
                    'Debug.Print """" & Str & """"
                    swCustProp.Set "质量", Chr(34) & Str & Chr(34)

                Next i
            End Sub
            '--------------------------------------