Cóż, z twoją pomocą udało mi się zrobić coś, co prawdopodobnie nie jest optymalne, ale wydaje się, że działa. Otwartość dzieci jest rzeczywiście konieczna.
jeśli to może pomóc
'**********************
"Prawa autorskie(C) 2023 Xarial Pty Limited
'Odniesienie: Przechodzenie przez drzewo komponentów za pomocą API SOLIDWORKS
'Licencja: Licencja
'**********************
Opcja jawna
Dim swApp jako SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Przyciemnij część jako SldWorks.ModelDoc2
Sun SelMgr jako SldWorks.SelectionMgr
Dim swFeatMgr As SldWorks.FeatureManager
Dim path_complete As String' Pełna Droga Utworu
Dim myError tak długo
Przyciemnij myWarning tak długo
Przyciemniony cudzysłów Jako ciąg
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim ext As Ciąg
Const INDENT_SYMBOL As String = " "
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If Not swModel Is Nothing Then
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set SelMgr = Part.SelectionManager
Set swFeatMgr = Part.FeatureManager
' Show Component Descriptions is set to true
swFeatMgr.ShowComponentDescriptions = True
' Show Component Configuration Names is set to false
swFeatMgr.ShowComponentConfigurationNames = True
' Show Component Configuration Descriptions is set to false
swFeatMgr.ShowComponentConfigurationDescriptions = False
' Show Component Names
swFeatMgr.ShowComponentNames = False
swFeatMgr.ShowDisplayStateNames = False
Dim swRootComp As SldWorks.Component2
Set swRootComp = swModel.ConfigurationManager.ActiveConfiguration.GetRootComponent
TraverseComponent swRootComp, ""
Else
MsgBox "Please open assembly"
End If
Koniec subwoofera
Sub TraverseComponent(comp As SldWorks.Component2, wcięcie jako ciąg)
Dim vChildComps As Variant
vChildComps = comp.GetChildren
Dim i As Integer
For i = 0 To UBound(vChildComps)
Dim swChildComp As SldWorks.Component2
Set swChildComp = vChildComps(i)
Debug.Print indent & swChildComp.Name2 & " (" & swChildComp.GetPathName() & ")"
TraverseComponent swChildComp, indent & INDENT_SYMBOL
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
' Set SelMgr = Part.SelectionManager
' Ustaw swFeatMgr = Part.FeatureManager
' Otwiera plik pętli
ext = Prawo(swChildComp.GetPathName(), 6)
– Jeśli to jest część
Jeśli ext = "sldprt" Wtedy
Ustaw część = swApp.OpenDoc6(swChildComp.GetPathName(), 1, 0, "", longstatus, longwarnings)
Inaczej
"To nie jest pożyczka"
Jeśli ext = "sldasm" Wtedy
'////aSM
Ustaw część = swApp.OpenDoc6(swChildComp.GetPathName(), 2, 0, "", longstatus, longwarnings)
Else
MsgBox "pas d'extension trouvée"
End If
Zakończ jeżeli:
''Modyfikuje wyświetlanie drzewa oprogramowania
Set SelMgr = Part.SelectionManager
Set swFeatMgr = Part.FeatureManager
' Show Component Descriptions is set to true
swFeatMgr.ShowComponentDescriptions = True
' Show Component Configuration Names is set to false
swFeatMgr.ShowComponentConfigurationNames = True
' Show Component Configuration Descriptions is set to false
swFeatMgr.ShowComponentConfigurationDescriptions = False
' Show Component Names
swFeatMgr.ShowComponentNames = False
swFeatMgr.ShowDisplayStateNames = False
' MsgBox ' przed zamknięciem pliku
''ferme le fichier de la boucle
swApp.CloseDoc Nazwa_części.GetPathName
Ustaw część = Nic
Next
Koniec subwoofera