Texte préformaté
’**********************
'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
Dim swRootComp As SldWorks.Component2
Set swRootComp = swModel.ConfigurationManager.ActiveConfiguration.GetRootComponent
' MsgBox "avant de rentrer dans la première boucle des enfants"
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() & ")"
’ Ouvre le fichier de la boucle
ext = Right(swChildComp.GetPathName(), 6)
'si c’est un part
If ext = « sldprt » Then
'Debug.Print "Part " & swChildComp.GetPathName()
'swApp.OpenDoc6 "C:\VueLocalePDM\PDM\2-CREE\01-Bibliotheque\Pièces\Pièces 06\DOC-000024428.sldprt", 1, 0, "", 0, 0
swApp.OpenDoc6 swChildComp.GetPathName(), 1, 0, « », 0, 0
Else
'ce n’est pas un prt"
If ext = « sldasm » Then
'////aSM
Set Part = swApp.OpenDoc6(swChildComp.GetPathName(), 2, 0, « », longstatus, longwarnings) '2 pou swDocASSEMBLY
Else
MsgBox "pas d'extension trouvée"
End If
End If
MsgBox "avant fermeture du fichier"
''ferme le fichier de la boucle
'swApp.CloseDoc Part.GetPathName
Set Part = Nothing
Next
End Sub