Hello, I still need help, I'm an intern in a company and I don't understand much about the loop system how to put them on properly
My goal is to retrieve the name of the file, check it (description, property, reference) once this step finishes checking if there are other parts/assembly in the parent file if yes it redoes the check for each subfile "part" or "assembly", if not no subfiles, it goes back up and goes to the next part, then does the same procedure again for each file
I already have all the commands for the info but then it's how to get it put in a loop
The ideal would be to post your code (or pieces of code) via the assigned tag:
Then choose VBscrip.
Then it will be easier to help you.
If I have understood correctly from an assembly you want to analyze each part or sub-assembly by checking if the description, property and reference are existing, or well informed?
What do you do if it's not the case a simple msgbox or do you also have to make a report with the parts, assemblies not or poorly informed?
Option Explicit
Const RechercheDeLaPosition = True
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swAssy As SldWorks.AssemblyDoc
Dim swConf As SldWorks.Configuration
Dim swRootComp As SldWorks.Component2
Dim Nom
Dim fileName As String
Dim compte As Long
Dim caractere As String
Dim Position As Single
Dim Resultat1 As String
Dim Position2 As Single
Dim caractere2 As String
Dim resultat3 As String
Dim cusPropMgr As SldWorks.CustomPropertyManager
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim ContrôleVF As Boolean
Dim ValOut As String
Dim WasResolved As Boolean
Dim ResolvedValOut As String
Dim LinkToProperty As Boolean
Dim ValeurDesc, ValeurRéférence
Dim REF_Et_la_DESC As String
Sub TraverseComponent(swComp As SldWorks.Component2, nLevel As Long)
Dim vChildComp As Variant
Dim swChildComp As SldWorks.Component2
Dim swCompConfig As SldWorks.Configuration
Dim sPadStr As String
Dim i As Long
sPadStr = ""
For i = 0 To nLevel - 1
sPadStr = sPadStr + " "
Next i
vChildComp = swComp.GetChildren
For i = 0 To UBound(vChildComp)
Set swChildComp = vChildComp(i)
TraverseComponent swChildComp, nLevel + 1
Debug.Print sPadStr & swChildComp.Name2 '& " <" & swChildComp.ReferencedConfiguration & ">"
Next i
End Sub
Sub main()
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
'---- Affiche le chemin d'accès et le nom du fichier
If MsgBox("Le nom du fichier est :" & vbCrLf & vbCrLf & swModel.GetPathName, vbOKCancel, "Vérification") = vbOK Then
End If
Set swModelDocExt = swModel.Extension
Set cusPropMgr = swModelDocExt.CustomPropertyManager("")
'---------------------------------------------------------------
'----Récupération de la valeur donné correspondante au Nom De La Propriété---
'---------------------Afficher la valeur------------------------
'---------------------------------------------------------------
ValeurDesc = swModel.GetCustomInfoValue("", "description")
If MsgBox("Le nom du fichier est :" & vbCrLf & vbCrLf & ValeurDesc, vbOKOnly, "Vérification") = vbOK Then
End If
ValeurRéférence = swModel.GetCustomInfoValue("", "référence")
If MsgBox("La référence est :" & vbCrLf & vbCrLf & ValeurRéférence, vbOKOnly, "Vérification") = vbOK Then
End If
REF_Et_la_DESC = ValeurRéférence & "_" & ValeurDesc
If REF_Et_la_DESC = resultat3 Then
MsgBox "La description est identique au nom :" & vbCrLf & vbCrLf & REF_Et_la_DESC & vbCrLf & vbCrLf & resultat3, vbQuestion, "Vérification"
MsgBox "Vous pouvez continuer"
Else
MsgBox "Les valeurs ne sont pas cohérentes avec le nom de fichier référencé"
MsgBox "Veuillez vérifier les informations"
End If
'---- Cherche le dernière "\" dans le chemain d'accès du fichier-----
caractere = "\"
Position = InStrRev(swModel.GetPathName, caractere)
'Afficher seulement le nom du fichier + l'extension
Resultat1 = Mid(swModel.GetPathName, Position + 1)
'---- Cherche le dernier "." dans resultat1 pour ensuite retirer l'extension et afficher que le nom du fichier-
caractere2 = "."
Position2 = InStrRev(Resultat1, caractere2)
'MsgBox Left(Resultat1, Position2 - 1)
resultat3 = Left(Resultat1, Position2 - 1)
'---- On cherche la référence puis on vérifie qu'elle fait moins de 50 chr
' va traiter la longueur de notre demande de vérification du caractère
If Len(resultat3) >= 50 Then
MsgBox "Votre Nom de fichier est trop long !"
MsgBox "Veuillez modifier le nom !"
End If
Nom = swModel.GetPathName
' Ouvre l'assemblage si il n'est pas déjà ouvert
fileName = Nom
'Set swModel = swApp.OpenDoc6(fileName, swDocumentTypes_e.swDocASSEMBLY, swOpenDocOptions_e.swOpenDocOptions_Silent, "", errors, warnings)
Set swConf = swModel.GetActiveConfiguration
Set swRootComp = swConf.GetRootComponent3(True)
Debug.Print "Chemin et Nom du Fichier = " & swModel.GetPathName
' Traverse components
TraverseComponent swRootComp, 1
End Sub
Yes that's right, I have to check each time "the floor" and if it's good I check what it contains by checking if what's inside is compliant and that everything is referenced and if it's good I go back upstairs and I move on to the next room etc,
And if he finds an inconsistency, I'd like him to tell me there's an error, msgbox "Inconsistency .... etc, I stop the macro"
and once User has corrected the error, he restarts the macro