9 Replies Latest reply on Jul 1, 2016 7:50 AM by Yong Ning

    How to active configuration in bom of part

    Yong Ning

      Can traverse configuration, but cannot activate the  configuration of (a1,a2,a3,a4)

       

      https://forum.solidworks.com/servlet/JiveServlet/downloadImage/2-440382-148735/450-312/1.jpg

       

       

       

      Private Sub ll1()

        Dim SwModel As ModelDoc2

          Set SwModel = Application.SldWorks.ActiveDoc

        Dim Params As Variant, SwConf As Configuration

          Params = SwModel.GetConfigurationNames

       

          For ii = 0 To UBound(Params)

             Set SwConf = SwModel.GetConfigurationByName(Params(ii))

       

             With SwConf

                Debug.Print .Name,

                Debug.Print .BOMPartNoSource,

                Debug.Print .AlternateName,

                .AlternateName = ii

                Debug.Print .Comment,

                .Comment = .Name

                Debug.Print .Type

                ss = .GetParameters(aa, .Name)          

             End With      

          Next ii

      End Sub

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

       

      In this code

      Can traverse Configuration , result is

      a2             8            0             a2             0

      a3             8            1             a3             0

      a4             8            2             a4             0

      a1             8            3             a1             0

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

      Help me

        How to active configuration.

        active configurate a1,a2,a3,a4

        • Re: How to active configuration in bom of part
          Artem Taturevych

          IBomTableAnnotation::BomFeature->BomFeature::Configuration

            • Re: How to active configuration in bom of part
              Yong Ning

              0.jpg

              Why  follow code don't active configuration?

               

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

              question

                     .Configuration = "a3" →

                     Debug.Print .Configuration → result "a1"

               

               

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

              Private Sub main()

                Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2, SwDraw As DrawingDoc

                  ''

                  Set SwApp = Application.SldWorks

                  Set SwModel = SwApp.ActiveDoc    

                Dim SwSelMgr As SelectionMgr 

                  Set SwSelMgr = SwModel.SelectionManager   

                Dim SwBomFeat As BomFeature

                  Set SwBomFeat = SwSelMgr.GetSelectedObject5(1)

                  Debug.Print SwBomFeat.GetFeature.Name

                Dim Visible(3), ss(3)

                  ss(0) = "a1"

                  ss(1) = "a2"

                  ss(2) = "a3"

                  ss(3) = "a4"

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

                  Visible(0) = False

                  Visible(1) = True

                  Visible(2) = False

                  Visible(3) = False

                  SwBomFeat.SetConfigurations False, Visible, ss

                  Stop  

              End Sub

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

              Private Sub main()

                Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2, SwDraw As DrawingDoc

                  ''

                  Set SwApp = Application.SldWorks

                  Set SwModel = SwApp.ActiveDoc

                Dim SwSelMgr As SelectionMgr, Visible

                  Set SwSelMgr = SwModel.SelectionManager

                Dim SwBomFeat As BomFeature

                  Set SwBomFeat = SwSelMgr.GetSelectedObject5(1)

                  Debug.Print SwBomFeat.GetFeature.Name

                  SwModel.ShowConfiguration2 "a3"

                  With SwBomFeat

                     .SetConfigurations True, Visible, "a3"

                     .Configuration = "a3"

                     Debug.Print .Configuration

                  End With

              End Sub

                • Re: How to active configuration in bom of part
                  Yong Ning

                  'This example shows how to get the custom properties for the configurations in a document.

                   

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

                  Option Explicit

                   

                  Public Enum swCustomInfoType_e

                      swCustomInfoUnknown = 0

                      swCustomInfoText = 30       '  VT_LPSTR

                      swCustomInfoDate = 64       '  VT_FILETIME

                      swCustomInfoNumber = 3      '  VT_I4

                      swCustomInfoYesOrNo = 11    '  VT_BOOL

                  End Enum

                   

                  Sub main()

                   

                      Dim swApp                   As SldWorks.SldWorks

                      Dim swModel                 As SldWorks.ModelDoc2

                      Dim swConfig                As SldWorks.Configuration

                      Dim vConfName               As Variant

                      Dim vPropName               As Variant

                      Dim vPropValue              As Variant

                      Dim vPropType               As Variant

                      Dim nNumProp                As Long

                      Dim i                       As Long

                      Dim j                       As Long

                      Dim bRet                    As Boolean

                      Set swApp = Application.SldWorks

                      Set swModel = swApp.ActiveDoc

                   

                      Debug.Print "File = " + swModel.GetPathName

                   

                      vConfName = swModel.GetConfigurationNames

                      For i = 0 To UBound(vConfName)

                          Set swConfig = swModel.GetConfigurationByName(vConfName(i))

                   

                          nNumProp = swConfig.GetCustomProperties(vPropName, vPropValue, vPropType)

                   

                          Debug.Print "  Config       = " & vConfName(i)

                          For j = 0 To nNumProp - 1

                              Debug.Print "    " & vPropName(j) & " <" & vPropType(j) & "> = " & vPropValue(j)

                          Next j

                          Debug.Print "  ---------------------------"

                      Next i

                  End Sub

                   

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

                   

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

                  Private Sub ll1()

                    Dim SwModel As ModelDoc2

                      Set SwModel = Application.SldWorks.ActiveDoc

                    Dim Params As Variant, SwConf As Configuration

                      Params = SwModel.GetConfigurationNames

                      For ii = 0 To UBound(Params)

                         Set SwConf = SwModel.GetConfigurationByName(Params(ii))

                         With SwConf

                            SwModel.ShowConfiguration2 .Name

                            SwModel.ViewZoomtofit

                          End With

                      Next ii

                  End Sub

                    • Re: How to active configuration in bom of part
                      Artem Taturevych

                      This works for me in 2014:

                       

                      Private Sub main()

                       

                          Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2, SwDraw As DrawingDoc

                       

                          Set SwApp = Application.SldWorks

                         

                          Set SwModel = SwApp.ActiveDoc

                          Dim SwSelMgr As SelectionMgr

                         

                          Set SwSelMgr = SwModel.SelectionManager

                          Dim SwBomFeat As BomFeature

                         

                          Set SwBomFeat = SwSelMgr.GetSelectedObject5(1)

                          SwBomFeat.Configuration = "a2"

                         

                      End Sub

                        • Re: How to active configuration in bom of part
                          Yong Ning

                          thanks your tips

                           

                          This works for me in sw2011.

                           

                          question

                              SwBomFeat.Configuration = "a2"

                              Debug.Print SwBomFeat.Configuration → result is "a1" → Hope result is "a2"

                          0.jpg

                           

                          Hope "a1" change "a2"

                           

                          1.jpg

                           

                           

                           

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

                           

                          SolidWorks Forums: Partnumber-configuation Macro

                          https://forum.solidworks.com/message/440898#440898

                           

                          In this tips, my question is

                           

                          Set Configuration BOM Property to Configuration Name.swp

                          How to  set Configuration Bill Of Materials options to Configuration Name?

                           

                          key code →

                                  Set sConfig = swModel.GetConfigurationByName(sConfigName) →  sConfig name

                           

                                  what mean for BOMPartNoSource?

                           

                                  sConfig.BOMPartNoSource = swBOMPartNumber_ConfigurationName

                          • Re: How to active configuration in bom of part
                            Yong Ning

                            Find the reason, your code can only run in drawing, don't run in part.

                             

                                SwBomFeat.Configuration = "a3"

                                Debug.Print SwBomFeat.Configuration → result is a3.

                             

                             

                            2.jpg

                             

                            Private Sub main()

                             

                                Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2, SwDraw As DrawingDoc

                             

                                Set SwApp = Application.SldWorks

                              

                                Set SwModel = SwApp.ActiveDoc

                                Dim SwSelMgr As SelectionMgr

                              

                                Set SwSelMgr = SwModel.SelectionManager

                                Dim SwBomFeat As BomFeature

                              

                                Set SwBomFeat = SwSelMgr.GetSelectedObject5(1)

                                SwBomFeat.Configuration = "a3"

                                Debug.Print SwBomFeat.Configuration

                              

                            End Sub

                              • Re: How to active configuration in bom of part
                                Artem Taturevych

                                It runs successfully in parts as well for me in 2014.

                                  • Re: How to active configuration in bom of part
                                    Yong Ning

                                    Why follow code runs successfully in parts as well for me in SW2014

                                     

                                     

                                     

                                    Private Sub Main3()

                                        Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2, SwDraw As DrawingDoc

                                           Set SwApp = Application.SldWorks

                                           Set SwModel = SwApp.ActiveDoc

                                        Dim SwSelMgr As SelectionMgr

                                           Set SwSelMgr = SwModel.SelectionManager

                                        Dim SwConf As Configuration

                                           Set SwConf = SwModel.GetActiveConfiguration

                                        Dim SwBomFeat As BomFeature

                                           Set SwBomFeat = SwSelMgr.GetSelectedObject5(1)

                                           SwBomFeat.Configuration = SwConf.Name

                                           SwModel.ForceRebuild3 True

                                           Debug.Print SwBomFeat.Configuration, SwConf.Name

                                        'Stop

                                    End Sub

                                     

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

                                    0.jpg

                                    but in Sw2013, the code don't runs successfully in parts.

                                      key  code

                                           SwBomFeat.Configuration = SwConf.Name

                                           Debug.Print SwBomFeat.Configuration, SwConf.Name

                                    result SwBomFeat.Configuration → "a1" , Hope SwBomFeat.Configuration  → "a3"

                                • Re: How to active configuration in bom of part
                                  Yong Ning

                                  Private Sub TraverChangeBOMconfiguration()

                                      Dim Str, tmp

                                         Str = "Bill of Materials1"

                                      Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2, SwDraw As DrawingDoc

                                         Set SwApp = Application.SldWorks

                                         Set SwModel = SwApp.ActiveDoc

                                      Dim SwSelMgr As SelectionMgr

                                         Set SwSelMgr = SwModel.SelectionManager

                                        

                                      Dim ConfArr, swConf As Configuration

                                         ConfArr = SwModel.GetConfigurationNames

                                      Dim SwBomFeat As BomFeature

                                        

                                         For ii = 1 To UBound(ConfArr)

                                             tmp = SwModel.Extension.SelectByID2("Bill of Materials1", "BOMFEATURE", 0, 0, 0, False, 0, Nothing, 0)

                                             Set SwBomFeat = SwSelMgr.GetSelectedObject5(1)

                                             SwModel.ShowConfiguration2 ConfArr(ii)

                                             Set swConf = SwModel.GetActiveConfiguration

                                             SwBomFeat.Configuration = swConf.Name

                                             SwModel.ForceRebuild3 False

                                            

                                             Debug.Print SwBomFeat.Configuration, swConf.Name, SwBomFeat.GetFeature.Name

                                             'Stop

                                         Next ii

                                      'Stop

                                  End Sub

                                   

                                   

                                   

                                  Private Sub Main3()

                                      Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2, SwDraw As DrawingDoc

                                         Set SwApp = Application.SldWorks

                                         Set SwModel = SwApp.ActiveDoc

                                      Dim SwSelMgr As SelectionMgr

                                         Set SwSelMgr = SwModel.SelectionManager

                                      Dim swConf As Configuration

                                         Set swConf = SwModel.GetActiveConfiguration

                                      Dim SwBomFeat As BomFeature

                                         Set SwBomFeat = SwSelMgr.GetSelectedObject5(1)

                                        

                                         SwBomFeat.Configuration = swConf.Name

                                         SwModel.ForceRebuild3 False

                                         Debug.Print SwBomFeat.Configuration, swConf.Name, SwBomFeat.GetFeature.Name

                                      'Stop

                                  End Sub