Messed up configurations

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