bon avec votre aide j’ai réussi à faire quelque chose qui n’est probablement pas optimal mais qui semble fonctionner. l’ouverture des enfants est effectivement nécessaire.
si jamais cela peut aider
'**********************
'Copyright(C) 2023 Xarial Pty Limited
'Reference: Traversing the components tree using SOLIDWORKS API
'License: License
'**********************
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim Part As SldWorks.ModelDoc2
Dim SelMgr As SldWorks.SelectionMgr
Dim swFeatMgr As SldWorks.FeatureManager
Dim path_complete As String 'chemin complet de la pièce
Dim myError As Long
Dim myWarning As Long
Dim guillemet As String
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim ext As String
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
End Sub
Sub TraverseComponent(comp As SldWorks.Component2, indent As String)
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
’ Set swFeatMgr = Part.FeatureManager
’ Ouvre le fichier de la boucle
ext = Right(swChildComp.GetPathName(), 6)
'si c’est un part
If ext = « sldprt » Then
Set Part = swApp.OpenDoc6(swChildComp.GetPathName(), 1, 0, « », longstatus, longwarnings)
Else
'ce n’est pas un prt"
If ext = « sldasm » Then
'////aSM
Set Part = swApp.OpenDoc6(swChildComp.GetPathName(), 2, 0, « », longstatus, longwarnings)
Else
MsgBox "pas d'extension trouvée"
End If
End If
''modifie l’affichage de l’arbre SW
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 « avant fermeture du fichier »
''ferme le fichier de la boucle
swApp.CloseDoc Part.GetPathName
Set Part = Nothing
Next
End Sub