follow code, select component in Assembly.
result
*************************************************************
File = D:\bb\aa.SLDASM
Component = bb-1/cc-1/dd-1 [D:\bb\dd.SLDASM]
ParentComp = bb-1/cc-1 [D:\cc.SLDASM]
***********************************************************
'---------------------------------------
'
' Preconditions:
' (1) Assembly document is open.
' (2) Assembly component is selected.
'
' Postconditons: None
'
'---------------------------------------
Option Explicit
Sub main()
Dim SwApp As SldWorks.SldWorks
Dim SwModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swConfigMgr As SldWorks.ConfigurationManager
Dim swConf As SldWorks.Configuration
'Dim swConf As SldWorks.Configuration
Dim swComp As Component2
Dim SwParentComp As SldWorks.Component2
Dim bRet As Boolean
Set SwApp = Application.SldWorks
Set SwModel = SwApp.ActiveDoc
Set swSelMgr = SwModel.SelectionManager
Set swComp = swSelMgr.GetSelectedObjectsComponent2(1)
' Returns NULL if selected component is a top-level component
Set SwParentComp = swComp.GetParent
'Debug.Print swParentComp.Name2
'Debug.Print SwComp.Name2
If Nothing Is SwParentComp Then
Set swConfigMgr = SwModel.ConfigurationManager
Set swConf = swConfigMgr.ActiveConfiguration
Set SwParentComp = swConf.GetRootComponent
End If
Debug.Assert Not SwParentComp Is Nothing
Debug.Print "File = " & SwModel.GetPathName
Debug.Print " Component = " & swComp.Name2 & " [" & swComp.GetPathName & "]"
Debug.Print " ParentComp = " & SwParentComp.Name2 & " [" & SwParentComp.GetPathName & "]"
End Sub
SolidworksApi macros