Messed up configurations

Hey there,

The red and green are two configurations of a part, that belong to the assembly as shown on the drawing. I’m trying to automatically place boom balloons on the assembly view by selecting the part view and then running a macro that gets the part and its configuration of the selected view and then finds this component on the assembly view.

First, I find the component by name and then I compare it by configuration, the problem is that I successfully find both components on the assembly view, but GetID always returns the same value for both parts althou they are set to different configurations in the assembly.

I tried to access the active configuration from the ModelDoc2 object and the ConfigurationManager, but I always got the same result. What am I doing wrong?

This is the part of the code performing this operation:

        For i = 0 To UBound(FvComps)
            Set FvComp = FvComps(i)
            FvComp.SetSuppression2 (swComponentFullyResolved)
            Set swFvCompModel = FvComp.GetModelDoc2
            If Not swFvCompModel Is Nothing Then
                Set swCfgMgr = swFvCompModel.ConfigurationManager
                Set swFvComponentConfig = swCfgMgr.ActiveConfiguration
                compName1 = swCompModel.GetTitle
                compName2 = swFvCompModel.GetTitle
                If compName1 = compName2 Then
                    Set swFvComponentConfig = swFvCompModel.ConfigurationManager.ActiveConfiguration
                    'Najprej preveri če je isto ime komponente
                    If swCompConfig.GetID = swFvComponentConfig.GetID Then
                        Dim RefCong As String
                        RefCong = swView.ReferencedConfiguration
                        vEdges = swBoomView.GetVisibleEntities2(FvComp, swViewEntityType_e.swViewEntityType_Edge)
                        Set swEnt = vEdges(0)
                        BoomViewName = swBoomView.GetName2
                        swEnt.Select (False)
                        Dim myNote2 As SldWorks.Note
                        Dim myANote2 As SldWorks.Annotation
                        Dim errors As Long
                        Dim BomBalloonParams As Object
                        Set BomBalloonParams = swModel.Extension.CreateBalloonOptions()
                        Set myNote2 = swModel.Extension.InsertBOMBalloon2(BomBalloonParams)
                        GoTo cont
                    End If
                Else
                End If
              End If
            Next

Thank you for your help and have a nice day.

Here’s a solution for your testing purposes:

You will get the component referenced config name even on light weight mode.

Option Explicit

Dim swApp As SldWorks.SldWorks
Dim swDrawingDoc As SldWorks.IDrawingDoc
Dim swView As SldWorks.IView
Dim visibleComponents As Variant
Dim visibleComponent As Variant
Dim drawingComponent As SldWorks.IDrawingComponent
Dim myComponent As SldWorks.IComponent2

Sub Main()

Set swApp = Application.SldWorks

Set swDrawingDoc = swApp.IActiveDoc2

'You can change the code block below based on the selected view
'*************************************************************
Set swView = swDrawingDoc.GetFirstView

Do While Not swView Is Nothing
    
    If swView.Type = swDrawingViewTypes_e.swDrawingSheet Then GoTo next_
    
    'Breaking point according to the desired view name
    If swView.Name <> "Your view name" Then GoTo next_
    
    visibleComponents = swView.GetVisibleComponents
    
    Exit Do
        
next_:
    
    Set swView = swView.GetNextView
Loop
'*************************************************************

If swView Is Nothing Then
    
    Debug.Print "Did not find a view"
    
    End
End If

If IsEmpty(visibleComponents) Then

    Debug.Print "There's no visible components in this view [ " & swView.Name & " ]"
    
    End
End If

For Each visibleComponent In visibleComponents
    
    Set myComponent = visibleComponent
    
    'First you must cast to the Drawing Component class
    Set drawingComponent = myComponent.GetDrawingComponent(swView)
    
    'Then cast back to the Component class
    'You can set to another variable name
    Set myComponent = drawingComponent.component
    
    'Then you will retrieve the component referenced config name
    Debug.Print "Component referenced config name: " & myComponent.ReferencedConfiguration
    
Next

'Stop
End Sub
1 Like

The code below has been worked for those drawing views:

  • Break view
  • Crop view
  • Broken-out section
  • Section view
  • Detail view
Option Explicit

Dim swApp As SldWorks.SldWorks
Dim swDrawingDoc As SldWorks.IDrawingDoc
Dim swModelDoc As SldWorks.IModelDoc2
Const viewName As String = "Your drawing view name"
Dim i As Integer

Sub Main()

Set swApp = Application.SldWorks

Set swDrawingDoc = swApp.IActiveDoc2
Set swModelDoc = swApp.IActiveDoc2

Dim view As SldWorks.IView
Set view = swDrawingDoc.GetFirstView

Do
    
    If view.Name <> viewName Then
        Set view = view.GetNextView
    Else
        Exit Do
    End If
Loop While Not view Is Nothing

If view Is Nothing Then
    
    Debug.Print "The view [ " & viewName & " ] hasn't been found."
    
    End
End If

Dim visibleComponents As Variant
visibleComponents = view.GetVisibleComponents

If IsEmpty(visibleComponents) Then
    
    Debug.Print "There's no visible components!"
    
    End
End If


For i = 0 To UBound(visibleComponents)

    Dim visibleComponent As SldWorks.IComponent2
    Set visibleComponent = visibleComponents(i)
    
    Dim visibleEdges As Variant
    visibleEdges = view.GetVisibleEntities2(visibleComponent, swViewEntityType_e.swViewEntityType_Edge)
    
    Dim count As Long
    count = swModelDoc.Extension.MultiSelect2(visibleEdges, False, Nothing)
    
' Uncomment if you want to select the drawing component
'**************************************************************
'    Dim drawingComponent As SldWorks.IDrawingComponent
'    Set drawingComponent = visibleComponent.GetDrawingComponent(view)
'
'    Dim ret As Boolean
'    ret = drawingComponent.Select(False, Nothing)
'**************************************************************
    
    Debug.Print "Visible edges selected count for component >> " & visibleComponent.GetSelectByIDString & " <<:  " & count
    'Stop
Next


'Stop
End Sub

1 Like

I suggest you traversing the components within the view and compare their own referenced configurarion name by Component2::ReferencedConfiguration.