4 Replies Latest reply on Jan 13, 2015 5:42 AM by Adam Hoffman

    Drawing view model and active configurations

    Michael Caulton



      I am trying to get the referenced configurations of the child parts in a drawing view but it is not working as expected.


      Dim RootModel As SldWorks.ModelDoc2 = swView.ReferencedDocument - Gets the modeldoc for the current view


      Dim sConfig = swView.ReferencedConfiguration - Gets the configuration name of the active view, works for both part and assembly files



      I then try and use the code below to get the child components if the view is of an assembly.


                       Dim AllComp As Object = swView.ReferencedDocument.GetComponents(False)

                      'Fill out config name and if profile lists


                      For i = 0 To UBound(AllComp)

                          sTempConfig = AllComp(i).ReferencedConfiguration

                          Debug.Print(i.ToString + " " + AllComp(i).ReferencedConfiguration + " " + AllComp(i).GetSuppression.ToString)



      If the view is unchanged from when drawing was first opened it works fine and the data makes sense. if the view has been changed using "swView.ReferencedConfiguration = sConfig". the data no longer makes sense as it still reflects the original models data.


      Why am I not getting the correct data? All I want is the suppression state and configuration name of the child parts in the drawing view.

        • Re: Drawing view model and active configurations
          Daniel Andersson

          Have you tried to do a rebuild after you change the configuration?

          • Re: Drawing view model and active configurations
            Adam Hoffman

            I would process the assembly doc separately like this:


            Dim swApp As SldWorks.SldWorks
            Dim swModel As SldWorks.ModelDoc2
            Dim swDrawModel As SldWorks.ModelDoc2
            Dim swDraw As SldWorks.DrawingDoc
            Dim swAssy As SldWorks.AssemblyDoc

            Dim swView As SldWorks.View
            Dim swComp As SldWorks.Component2
            Dim swConfig As SldWorks.Configuration
            Dim sConfigName As String
            Dim AllComps As Variant

            Dim i As Integer
            Dim bRet As Boolean
            Dim iSupp As Integer


            Sub main()


            Set swApp = Application.SldWorks


            If swApp.GetDocumentCount() = 0 Then Exit Sub


            Set swModel = swApp.ActiveDoc


            If Not swModel.GetType() = swDocumentTypes_e.swDocDRAWING Then Exit Sub


            Set swDraw = swModel


            Set swView = swDraw.GetFirstView


            Set swView = swView.GetNextView


            Set swDrawModel = swView.ReferencedDocument


            If Not swDrawModel.GetType() = swDocumentTypes_e.swDocASSEMBLY Then Exit Sub


            sConfigName = swView.ReferencedConfiguration


            bRet = swDrawModel.ShowConfiguration2(sConfigName)


            Set swAssy = swDrawModel


            AllComps = swAssy.GetComponents(False)


            For i = 0 To UBound(AllComps)


                Set swComp = AllComps(i)
                iSupp = swComp.GetSuppression()
                If iSupp = 0 Then
                   MsgBox ("The Configuration Name For The Component Is: " + swComp.ReferencedConfiguration + " And It Is Fully Suppressed")
                ElseIf iSupp = 2 Then
                   MsgBox ("The Configuration Name For The Component Is: " + swComp.ReferencedConfiguration + " And It Is Unsuppressed")
                End If
            Next i



            End Sub