2 Replies Latest reply on Aug 16, 2014 9:01 AM by Yong Ning

    How to get Use named configurations In assembly, with API.

    Yong Ning

      In assembly, Use named configurations is p1.



      In Part1.sldprt, set configuration name is "p3".



      Help me.

      How to get Use named configurations (is p1) In assembly, .with API

          • Re: How to get Use named configurations In assembly, with API.
            Yong Ning

            Thanks for your reply




            'Change Referenced Configuration Example (VB)

            'This example shows how to change the configuration of a component in an assembly without opening the part.


            Option Explicit

            Sub main()

                Dim swApp                   As SldWorks.SldWorks

                Dim swAssy                  As SldWorks.AssemblyDoc

                Dim swSelMgr                As SldWorks.SelectionMgr

                Dim swModel                 As SldWorks.ModelDoc

                Dim swComp                  As SldWorks.Component

                Dim RefCfg                  As String

                Dim oSwModel As ModelDoc2

                Set swApp = CreateObject("SldWorks.Application")

                Set swModel = swApp.ActiveDoc

                Set swAssy = swModel

                Set swSelMgr = swModel.SelectionManager

                Set swComp = swSelMgr.GetSelectedObject5(1)

                Debug.Print swComp.Name, swComp.Name2

                ' Debugging only

                RefCfg = swComp.ReferencedConfiguration

                Debug.Print RefCfg

                ' Change component config to "in-use"

                'swComp.ReferencedConfiguration = "p1" 'RefCfg

                Set oSwModel = swComp.GetModelDoc

                Debug.Print oSwModel.GetTitle

                oSwModel.ShowConfiguration RefCfg

                ' For changes to take effect


            End Sub

            Private Sub ll()

              Dim oDic As New Dictionary, Str


              Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2, oSwModel As ModelDoc2

                Set SwApp = GetObject(, "SldWorks.Application")

                Set SwModel = SwApp.ActiveDoc

              Dim SwSelMgr As SelectionMgr

                Set SwSelMgr = SwModel.SelectionManager

              Dim SwAssy As AssemblyDoc, SwComp As Component2

                Set SwAssy = SwModel

              Dim SwConf As Configuration, SwRootComp As Component2

                Set SwConf = SwModel.GetActiveConfiguration

                Set SwRootComp = SwConf.GetRootComponent

              Dim vChildComp

                vChildComp = SwRootComp.GetChildren


                For ii = 0 To UBound(vChildComp)

                   Set SwComp = vChildComp(ii)

                   Set oSwModel = SwComp.GetModelDoc


                   'Debug.Print ii, SwComp.Name, oSwModel.GetTitle

                   If Not oDic.Exists(oSwModel.GetTitle) Then

                      oDic(oSwModel.GetTitle) = ""

                      Str = SwComp.ReferencedConfiguration

                      Debug.Print ii, SwComp.Name, oSwModel.GetTitle, Str

                      oSwModel.ShowConfiguration Str

                   End If

                Next ii

            End Sub