Property Revision

Hi everyone,
We use the revision tables in the MEPs to increment the revision index and note the changes made.
Thus, the revision property is located in the MEP file.

Is it possible to link this property of the MEP revision index to a property in the part or assembly in order to add it to bills of materials, for example?

Thank you in advance.
Have a nice day

Hello @remrem, it's been a while... :grinning:

If you have access to the MyCadTools suite, the Smartproperties tool allows you to do this:

But I don't recommend it at all, this function doesn't have a notion of " Automatic Update".
=> If the drawing is updated with a new index, you will have to restart the Smartproperties on this drawing and then open the associated 3D and restart the Smartproperties again... This is a huge potential for error.

1 Like

Hello remrem,

I think it would not be advisable to index 3D. As only the 3D said times.

What we do to send a 3D to customers through a WWTP by re-naming it with the index and the date of creation of the WWTP.

Otherwise use a PLM to manage all this...
It's up to you.
@+.
AR.

Yes. Indeed. I'm back. :wink:
I don't have the MyCadTools suite...

Indeed, the objective is to limit errors.

I don't really understand your answer.
If 3D is a good time, why not index 3D?

Well, there will be a risk of errors.
so I advise you to do a re-named WWTP with the index and date of completion.
There you go...
@+.
AR.

Hello,
In our country (even if we have Solidworks PDM), it is the 3D that carries the index in its properties.
The information is duplicated in the drawing properties either by macro or via the vault.
Then we also have macros that retrieve the information from the index property to format export names (STEP, IGES, STL...)

1 Like

Thank you for your answer, you don't use revision tables?

No, never implemented

That's why my revision is in the MEP.
When a new row is created in the table, the " Revision " property is automatically incremented. But it is in the MEP.

1 Like

Hello

But what if the error comes from the plan, but not from the 3D?

At home has become complicated :sweat_smile:
There is a room index and a plan index.
We indicate on the general plans in the nomenclature the index of the piece. And in the detail shots too.

This information is independent of each other.

If the 3D part changes, the 3D evolves and the plan inevitably goes up as well.
If the plan evolves (e.g. a nota or other) the plan goes up by index but not the piece?

You can link the subscript of the plan and the room, you have to recreate a custom property chain with a term different from the subscript of the plan. That said, the plan index will continue to exist. You have to recreate text linked to a property in the title block and in the revision bar.

Hello,

With us it's just the same as @Cyril_f : it's the 3D that carries the clue (which is easy to retrieve in the 2D as a result).

NB: in practice the 2 have an index that is mounted in parallel, but the main one remains that of 3D.

To answer @FRED78's question, we mount a hint on the 3D even if the modification is only done in practice on the 2D (like adding a nota) because a small note can have a big impact on the part (even if its 3D geometry does not change).

What is the string to bind this property?

@remrem

Used perhaps for the wrong purpose, I was thinking of a chain from 3D to MEP, part - assembly, assembly - plan. And to forward a link (the clue) from 3D to 2D.
But I probably expressed myself badly :sweat_smile:

Here's a macro that replaces the " Revision" property of the part or assembly with the "Revision " property of the MEP.

Option Explicit
    Dim PrtPath As String
    Dim AsmPath As String


Sub main()
    Dim swApp As SldWorks.SldWorks
    
    Dim swDrawModel As SldWorks.ModelDoc2
    Dim swDrawModelDocExt As ModelDocExtension
    Dim swDrawCustProp As CustomPropertyManager
    Dim swDrawDoc As SldWorks.DrawingDoc
    Dim swDrawView As SldWorks.View
    Dim DrawVal As String
    Dim DrawRevision As String
    Dim DrawBool As Boolean
    
    Dim swRefModel As SldWorks.ModelDoc2
    Dim swRefPath As String
    Dim swRefModelDocExt As ModelDocExtension
    Dim swRefCustProp As CustomPropertyManager
    Dim RefReturn As Integer
    Dim RefBool As Boolean
    Dim RefVal As String
    Dim RefRevision As String
    Dim RefDocType As swDocumentTypes_e
    
    Dim FileError As Long
    Dim FileWarning As Long

    Set swApp = Application.SldWorks
    Set swDrawModel = swApp.ActiveDoc

    If swDrawModel Is Nothing Then
        swApp.SendMsgToUser2 "Ouvrir un fichier mise en plan", swMbWarning, swMbOk
        Exit Sub
    End If

    If swDrawModel.GetType <> swDocDRAWING Then 'swDocASSEMBLY, swDocPART
        swApp.SendMsgToUser2 "Ouvrir un fichier mise en plan", swMbWarning, swMbOk
        Exit Sub
    Else
        RefDocType = RefDocTypeSearch(swDrawModel.GetPathName)
        Select Case RefDocType
            Case swDocPART
                Set swRefModel = swApp.OpenDoc6(PrtPath, swDocPART, swOpenDocOptions_Silent, "", FileError, FileWarning)
                Debug.Print "PrtPath = " & PrtPath
                Debug.Print "FileError = " & FileError
                Debug.Print "FileWarning = " & FileWarning
                
            Case swDocASSEMBLY
                Set swRefModel = swApp.OpenDoc6(AsmPath, swDocASSEMBLY, swOpenDocOptions_Silent, "", FileError, FileWarning)
                Debug.Print "AsmPath = " & AsmPath
                Debug.Print "FileError = " & FileError
                Debug.Print "FileWarning = " & FileWarning
                
        End Select
        
        If Not swRefModel Is Nothing Then
            swRefPath = swRefModel.GetPathName
            If IsFileExist(swRefModel.GetPathName) Then
                Set swDrawModelDocExt = swDrawModel.Extension
                Set swDrawCustProp = swDrawModelDocExt.CustomPropertyManager("")
                
                DrawBool = swDrawCustProp.Get4("Révision", False, DrawVal, DrawRevision)
                Debug.Print "DrawBool = " & DrawBool
                Debug.Print "DrawRevision = " & DrawRevision
                
                Set swRefModelDocExt = swRefModel.Extension
                Set swRefCustProp = swRefModelDocExt.CustomPropertyManager("")
                
                RefReturn = swRefCustProp.Set("Révision", DrawRevision)
                Debug.Print "RefReturn = " & RefReturn
                
                RefBool = swRefCustProp.Get4("Révision", False, RefVal, RefRevision)
                Debug.Print "RefModelPath = " & swRefModel.GetPathName
                Debug.Print "RefBool = " & RefBool
                Debug.Print "RefRevision = " & RefRevision
            End If
        End If
    End If
End Sub
Function RefDocTypeSearch(DrawPath As String) As swDocumentTypes_e
    Dim DrawPathLow As String
    
    DrawPathLow = LCase(DrawPath)
    Debug.Print "DrawPath = " & DrawPath
    Debug.Print "DrawPathLow = " & DrawPathLow
    
    PrtPath = Replace(DrawPathLow, "slddrw", "sldprt")
    AsmPath = Replace(DrawPathLow, "slddrw", "sldasm")
    
    If IsFileExist(PrtPath) Then
        RefDocTypeSearch = swDocPART
        Exit Function
    End If
    If IsFileExist(AsmPath) Then
        RefDocTypeSearch = swDocASSEMBLY
    End If
End Function


Function IsFileExist(FullName As String) As Boolean
  ' Vérifie l'existence d'un fichier
  IsFileExist = Dir(FullName) <> ""
End Function

Assembly, part, and MEp files must be in the same folder

3 Likes

Happy Birthday from Forum @remrem :birthday: !

Thanks for macro sharing. (The key will be to remember to launch it regularly :sweat_smile:).

Be careful for those who use " Revision " (without accent), it will be necessary to modify the code slightly...

2 Likes

Thank you. :wink:
I signed up in 2013 and already had white hair :joy:

2 Likes

Happy birthday forum one of the very rare, much older than me!
And for me still very little white hair! :rofl:
image

2 Likes

@remrem , I took the liberty of starting from your macro to make it a little more " universal " (don't blame me).
The changes are mainly focused on double reading
" Revision " versus " Revision ".
I also used the " Perplexity " AI to add text comments (AIs are still only good at this but it's still very practical).
In theory, compatibility with the Solidworks > 2022 version is also increased. (but I can't test!).

Tip:
For those who own the " Mycad " Suite, this version is supposed to be compatible with its use in Smartproperties (and therefore automatable when closing the Smartproperties Window (in the event that your revisions are generated with this utility).
This should greatly reduce the risk of bad revision between 3D and Drawings...

Example:
image

Option Explicit

' =====================================================
' DÉCLARATIONS GLOBALES
' =====================================================
' Ces variables globales stockent les chemins des fichiers pièce (.sldprt) et assemblage (.sldasm)
' détectés automatiquement à partir du chemin de la mise en plan (.slddrw).
' Pourquoi globales ? Pour qu'elles soient accessibles par toutes les fonctions de la macro.
Dim PrtPath As String     ' Chemin complet vers la pièce référencée
Dim AsmPath As String     ' Chemin complet vers l'assemblage référencé

' =====================================================
' PROCÉDURE PRINCIPALE : main()
' =====================================================
' BUT : Synchroniser la propriété "Révision/Revision" de la mise en plan vers son modèle référencé
'       (pièce ou assemblage). Fonctionne avec SolidWorks 2022 et ses spécificités API.
Sub main()
    On Error GoTo GestionErreur    ' Gestion centralisée des erreurs
    
    ' =====================================================
    ' DÉCLARATION DES OBJETS SOLIDWORKS
    ' =====================================================
    ' swApp : Instance principale de SolidWorks (toujours accessible via Application.SldWorks)
    Dim swApp As SldWorks.SldWorks
    ' swDrawModel : Document actif (la mise en plan)
    Dim swDrawModel As SldWorks.ModelDoc2
    ' Extensions et gestionnaires de propriétés personnalisées
    Dim swDrawModelDocExt As ModelDocExtension
    Dim swDrawCustProp As CustomPropertyManager
    ' Modèle référencé (pièce ou assemblage à synchroniser)
    Dim swRefModel As SldWorks.ModelDoc2
    Dim swRefModelDocExt As ModelDocExtension
    Dim swRefCustProp As CustomPropertyManager
    Dim RefDocType As swDocumentTypes_e    ' Type du document référencé
    
    ' =====================================================
    ' VARIABLES UTILITAIRES
    ' =====================================================
    Dim DrawRevision As String    ' Valeur de révision dans la mise en plan
    Dim RefRevision As String     ' Valeur de révision dans le modèle
    Dim PropName As String        ' Nom exact de la propriété (ex: "Revision" ou "Révision")
    Dim FileError As Long         ' Code d'erreur ouverture fichier
    Dim FileWarning As Long       ' Code d'avertissement ouverture fichier
    Dim Msg As String             ' Message informatif
    Dim addRes As Long            ' Résultat de l'ajout de propriété
    
    ' =====================================================
    ' ÉTAPE 1 : CONNEXION À SOLIDWORKS ET VÉRIFICATIONS
    ' =====================================================
    Set swApp = Application.SldWorks           ' Récupère l'instance SolidWorks courante
    Set swDrawModel = swApp.ActiveDoc          ' Document actif = mise en plan
    
    ' Vérification : un document doit être actif
    If swDrawModel Is Nothing Then
        swApp.SendMsgToUser2 "Aucun document actif. Ouvrez une mise en plan.", swMbWarning, swMbOk
        Exit Sub
    End If
    
    ' Vérification : le document actif DOIT être une mise en plan (.slddrw)
    If swDrawModel.GetType <> swDocDRAWING Then
        swApp.SendMsgToUser2 "Le document actif n'est pas une mise en plan.", swMbWarning, swMbOk
        Exit Sub
    End If
    
    ' =====================================================
    ' ÉTAPE 2 : DÉTECTION DU MODÈLE RÉFÉRENCÉ
    ' =====================================================
    ' Recherche automatique du fichier .sldprt ou .sldasm correspondant au .slddrw
    RefDocType = RefDocTypeSearch(swDrawModel.GetPathName)
    If RefDocType = 0 Then
        swApp.SendMsgToUser2 "Aucun modèle référencé trouvé (.sldprt ou .sldasm).", swMbWarning, swMbOk
        Exit Sub
    End If
    
    ' =====================================================
    ' ÉTAPE 3 : OUVERTURE SILENCIEUSE DU MODÈLE
    ' =====================================================
    ' Ouverture sans interface utilisateur (swOpenDocOptions_Silent)
    Select Case RefDocType
        Case swDocPART      ' Pièce
            Set swRefModel = swApp.OpenDoc6(PrtPath, swDocPART, swOpenDocOptions_Silent, "", FileError, FileWarning)
        Case swDocASSEMBLY  ' Assemblage
            Set swRefModel = swApp.OpenDoc6(AsmPath, swDocASSEMBLY, swOpenDocOptions_Silent, "", FileError, FileWarning)
    End Select
    
    ' Vérification ouverture réussie
    If swRefModel Is Nothing Or FileError <> 0 Then
        swApp.SendMsgToUser2 "Échec ouverture modèle.", swMbStop, swMbOk
        Exit Sub
    End If
    
    ' =====================================================
    ' ÉTAPE 4 : LECTURE PROPRIÉTÉS M ISE EN PLAN
    ' =====================================================
    Set swDrawModelDocExt = swDrawModel.Extension
    Set swDrawCustProp = swDrawModelDocExt.CustomPropertyManager("")    ' Propriétés document ("" = niveau document)
    
    ' DÉTECTION INTELLIGENTE du nom exact de la propriété révision
    PropName = DetectRevisionPropertyFixed(swDrawCustProp)
    Debug.Print "=== PROPNAME FINAL : '" & PropName & "' ==="    ' Debug pour développeur
    
    If PropName = "" Then
        swApp.SendMsgToUser2 "Aucune propriété Révision/Revision trouvée.", swMbStop, swMbOk
        GoTo NettoyageSimple
    End If
    
    ' Lecture de la valeur (avec fallback si vide)
    If Not GetCustomPropValue(swDrawCustProp, PropName, DrawRevision) Then
        DrawRevision = "NON_RENSEIGNÉ"    ' Valeur par défaut
        Debug.Print "Valeur mise en plan vide ? fallback"
    End If
    
    Debug.Print "Valeur À SYNCHRONISER : '" & DrawRevision & "'"
    
    ' =====================================================
    ' ÉTAPE 5 : ACCÈS PROPRIÉTÉS MODÈLE RÉFÉRENCÉ
    ' =====================================================
    Set swRefModelDocExt = swRefModel.Extension
    Set swRefCustProp = swRefModelDocExt.CustomPropertyManager("")    ' Propriétés du modèle
    
    ' =====================================================
    ' ÉTAPE 6 : SYNCHRONISATION (CRU DE LA MACRO)
    ' =====================================================
    Debug.Print "--- DÉBUT SYNCHRO ---"
    
    ' ? IMPORTANT SolidWorks 2022 : Force la reconstruction pour rafraîchir les propriétés
    swRefModel.ForceRebuild3 False    ' False = ne pas afficher les messages
    
    ' Test 1 : La propriété existe-t-elle déjà dans le modèle ?
    If GetCustomPropValue(swRefCustProp, PropName, RefRevision) Then
        Debug.Print "  ? Propriété existe : '" & RefRevision & "'"
        If RefRevision <> DrawRevision Then
            Debug.Print "  ? MISE À JOUR nécessaire"
            
            ' Mise à jour de la valeur existante
            Dim setRes As Long
            setRes = swRefCustProp.Set2(PropName, DrawRevision)    ' Set2 = mise à jour
            Debug.Print "  ? Set2 retour : " & setRes
            
            If setRes = 0 Then
                Msg = "? " & PropName & " mise à jour : " & DrawRevision
            Else
                Msg = "? Échec mise à jour " & PropName
            End If
        Else
            Msg = "? Déjà OK : " & PropName & " = " & DrawRevision
        End If
    Else
        Debug.Print "  ? CRÉATION propriété manquante"
        ' Création avec Add2 (stable sur SolidWorks 2022)
        addRes = swRefCustProp.Add2(PropName, swCustomInfoText, DrawRevision)
        Debug.Print "  ? Add2 retour : " & addRes
        
        If addRes = 0 Or addRes = 2 Then    ' 0=OK, 2=existe déjà
            Msg = "? " & PropName & " créée : " & DrawRevision
        Else
            ' Fallback Add3 si Add2 échoue
            addRes = swRefCustProp.Add3(PropName, swCustomInfoText, DrawRevision, 0)
            Debug.Print "  ? Add3 fallback retour : " & addRes
            If addRes = 0 Or addRes = 2 Then
                Msg = "? " & PropName & " créée (Add3) : " & DrawRevision
            Else
                Msg = "? ÉCHEC création " & PropName & " (Add2=" & addRes & ", Add3=" & addRes & ")"
            End If
        End If
    End If
    
    ' Debug.Print "--- SYNCHRO TERMINÉE : " & Msg & " ---"
    ' swApp.SendMsgToUser2 Msg, swMbInformation, swMbOk    ' Décommentez pour voir le résultat

    ' =====================================================
    ' NETTOYAGE : FERMETURE MODÈLE
    ' =====================================================
NettoyageSimple:
    If Not swRefModel Is Nothing Then
        On Error Resume Next      ' Ignore erreurs de fermeture
        swApp.CloseDoc swRefModel.GetPathName    ' Ferme sans sauvegarde
        On Error GoTo 0           ' Restaure gestion erreurs normale
    End If
    Exit Sub

    ' =====================================================
    ' GESTION D'ERREUR CENTRALE
    ' =====================================================
GestionErreur:
    swApp.SendMsgToUser2 "Erreur : " & Err.Description, swMbStop, swMbOk
    Debug.Print "ERREUR # " & Err.Number & " : " & Err.Description
    Resume NettoyageSimple    ' Nettoyage avant sortie
End Sub

' =====================================================
' FONCTION : DetectRevisionPropertyFixed()
' =====================================================
' BUT : Détecte intelligemment le nom exact de la propriété révision
'       Teste d'abord "Revision" ? "Révision" ? scan complet des propriétés
Function DetectRevisionPropertyFixed(CustMgr As CustomPropertyManager) As String
    Dim propNames As Variant
    Dim i As Long
    Dim PropName As String
    Dim propVal As String
    
    Debug.Print "=== SCAN COMPLET ==="
    
    ' 1?? PRIORITÉ 1 : Test direct "Revision" (standard anglais)
    If CustMgr.Get4("Revision", False, "", propVal) Then
        DetectRevisionPropertyFixed = "Revision"
        Debug.Print "? DIRECT : Revision"
        Exit Function
    End If
    
    ' 2?? PRIORITÉ 2 : Test "Révision" (standard français)
    If CustMgr.Get4("Révision", False, "", propVal) Then
        DetectRevisionPropertyFixed = "Révision"
        Debug.Print "? DIRECT : Révision"
        Exit Function
    End If
    
    ' 3?? PRIORITÉ 3 : Scan complet de TOUTES les propriétés
    propNames = CustMgr.GetNames    ' Tableau des noms de propriétés
    Debug.Print "Nb props: " & IIf(IsEmpty(propNames), 0, UBound(propNames) + 1)
    
    If Not IsEmpty(propNames) Then
        For i = 0 To UBound(propNames)
            PropName = CStr(propNames(i))
            Debug.Print "Prop " & i & ": '" & PropName & "'"
            ' Recherche insensible à la casse contenant "revision"
            If InStr(LCase(PropName), "revision") > 0 Then
                DetectRevisionPropertyFixed = PropName
                Debug.Print "? TROUVÉ : '" & PropName & "'"
                Exit Function
            End If
        Next i
    End If
    
    Debug.Print "? RIEN TROUVÉ"
    DetectRevisionPropertyFixed = ""    ' Aucune propriété trouvée
End Function

' =====================================================
' FONCTION : GetCustomPropValue()
' =====================================================
' BUT : Lit une propriété personnalisée avec gestion des valeurs vides
' RETOUR : True si propriété existe, False sinon
Function GetCustomPropValue(CustMgr As CustomPropertyManager, PropName As String, ByRef PropValue As String) As Boolean
    Dim res As Boolean
    Dim valOut As String, valEval As String    ' valEval = valeur évaluée (résolue)
    
    On Error Resume Next    ' Ignore erreurs Get4
    res = CustMgr.Get4(PropName, False, valOut, valEval)    ' Lecture propriété
    On Error GoTo 0         ' Restaure gestion erreurs
    
    Debug.Print "  Get4('" & PropName & "') ? res=" & res & " | val='" & valEval & "'"
    
    If res Then
        PropValue = IIf(valEval = "", "VIDE", valEval)    ' Gère les valeurs vides
        GetCustomPropValue = True
    Else
        PropValue = ""
        GetCustomPropValue = False
    End If
End Function

' =====================================================
' FONCTION : RefDocTypeSearch()
' =====================================================
' BUT : Détecte si le chemin .slddrw pointe vers .sldprt OU .sldasm
'       Remplit les variables globales PrtPath/AsmPath
Function RefDocTypeSearch(DrawPath As String) As swDocumentTypes_e
    Dim DrawPathLow As String
    DrawPathLow = LCase(DrawPath)    ' Minuscules pour comparaison
    
    ' Conversion automatique des noms de fichiers
    PrtPath = Replace(DrawPathLow, "slddrw", "sldprt")    ' Mise en plan ? Pièce
    AsmPath = Replace(DrawPathLow, "slddrw", "sldasm")    ' Mise en plan ? Assemblage
    
    Debug.Print "Test pièce : " & PrtPath & " ? " & IIf(IsFileExist(PrtPath), "OK", "KO")
    Debug.Print "Test assem : " & AsmPath & " ? " & IIf(IsFileExist(AsmPath), "OK", "KO")
    
    If IsFileExist(PrtPath) Then
        RefDocTypeSearch = swDocPART
        Exit Function
    End If
    If IsFileExist(AsmPath) Then
        RefDocTypeSearch = swDocASSEMBLY
    End If    ' Retourne 0 si aucun fichier trouvé
End Function

' =====================================================
' FONCTION UTILITAIRE : IsFileExist()
' =====================================================
' BUT : Teste l'existence d'un fichier sur disque
Function IsFileExist(FullName As String) As Boolean
    IsFileExist = (Dir(FullName) <> "")          ' VBA standard : Dir retourne "" si fichier inexistant
End Function

2 Likes

I don't blame you.
AI is good but do you understand what it does? :wink:
The comments sometimes contain questions because she doesn't understand everything and some elements sting my eyes such as the " On error " which is to be avoided because it does not allow to locate the defects.
My code is certainly not exhaustive but the error management by managing it will allow me (it is expected) to alert the user according to the errors.

1 Like