How do I update variables mapped to a macro?

Hello

I just created my account and I ask my very first question. Thank you for being indulgent if I forget details about my question or if it has already been asked...

The problem is quite simple and I don't understand why it doesn't work.

I'm working with SolidWorks PDM 2018 Sp4. I've created a PDM (macro) task, which I run on .slddrw files to update the file automatically.

The job extracts the file, opens via Solidworks, updates , saves, closes, and archives automatically. Everything works perfectly EXCEPT updating the mapped variables.

By that, I mean, that via PDM, I mapped variables so that when you change them to a .sldprt / .sldasm, it affects the .slddrw file. This works very well, and as usual, you just need to save the .slddrw file and the variables in the plan will update to the part/assembly file.

But here's my problem, if I do this saving via a macro, the variables are not updated.

I'm using swModel.ForceRebuild3 and swModel.EditRebuild3 for the update but nothing helps. If I change the 3d, the views are updated well, but not the variables $PRP displayed in the title block.

If anyone has an idea I'm interested because I'm running out...

Thank you in advance and have a good day.

Hello
Do you do the reconstruction on the MEP?
Show us your code.

1 Like

Hello

I just tested "swModel.Save" on a simple SolidWorks macro, run on Solidworks with an open plane, and it updates the mapped variables well, like a simple Ctrl+S.

Here is the complete code (Script in the PDM task), thanks:

 

Option Explicit

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim boolstatus As Boolean
Dim lErrors As Long
Dim lWarnings As Long
Dim pdmVault As Object
Dim strFullPath As String
Dim strFullPathWithoutExt As String
Dim strFolderPath As String
Dim strFileType As String
Dim intFileType As Integer
Dim i As Integer
Dim strFileName As String
Dim swCustPropMgr As SldWorks.CustomPropertyManager
Dim Msg, Style, Title, Ctxt, Response

Sub Main()

    'Initialize macro
    strFullPath = "<Filepath>"
    strFolderPath = "<Path>"

    'Grabs filename only
    i = InStrRev(strFullPath, "\")
    strFileName = Right(strFullPath, Len(strFullPath) - i)

    ' Grabs FullPath without the extention to resolve the bug with UnlockFile and UPPERCASE instead of lowercase (Ex: SLDDRW / slddrw)
    strFullPathWithoutExt = Left (strFullPath, Len(strFullPath) -6)

    'Limit the macro to SolidWorks files
    strFileType = LCase(Right(strFullPath, 6))

    Select Case strFileType
        "sldprt" box
            intFileType = 1
        Case "sldasm"
            intFileType = 2
        "Slddrw" box
            intFileType = 3
        Case Else
            Msg = "File format error!" + Chr(13) + Chr(10) + "*.sldprt, *.sldasm, *.slddrw only!" + Chr(13) + Chr(10) + "File " +  strFileName + " is ignored."   ' Define message.
            Style = vbMsgBoxSetForeground + vbCritical    ' Define buttons.
            Title = "STOP!"    ' Define title.
            Response = MsgBox(Msg, Style, Title)
            Exit Sub
    End Select

    'Create vault object
    Set pdmVault = CreateObject("ConisioLib.EdmVault")
    pdmVault.Login "admin", "***********", "**********"    

    'Create folder object
    Dim folder As Object 'IEdmFolder5 IEdmFolder11 EdmObject_Folder
    Set folder = pdmVault.GetFolderFromPath(strFolderPath)
 
    'Create file object
    Dim file As Object
    Set file = pdmVault.GetFileFromPath(strFullPathWithoutExt + strFileType, folder)

    'Check out
    If False = file. IsLocked Then
        file. LockFile folder.ID, 0
    Else
        Msg = "Error: File " + strFileName + " already extracted by: " + file.LockedByUser.Name + " !"    ' Define message.
        Style = vbMsgBoxSetForeground + vbCritical    ' Define buttons.
        Title = "STOP!"    ' Define title.
        Response = MsgBox(Msg, Style, Title)
        Exit Sub
    End If

    'Open save and close model
    Set swApp = Application.SldWorks
    swApp.Visible = False
    Set swModel = swApp.OpenDoc(strFullPath, intFileType)
    swModel.ViewZoomtofit2
    swModel.ForceRebuild3 False 'False rebuil all and True rebuil only the top level
    swModel.EditRebuild3

    swModel.Save
    'boolstatus = swModel.Save3(swSaveAsOptions_Silent, lErrors, lWarnings)
    swApp.CloseDoc strFileName

    'Check in
    file. UnlockFile 0, "Automatic Update", 64

End Sub

Well, I just received the code and explanation from Visiativ.

For this to work, the macro must load the PDMSW.dll file. Be careful, if you want to reuse this code, make sure that the file PDMSW.dll be here: C:\Program Files\SolidWorks Enterprise PDM\PDMSW.dll


macro_pdm_mettre_a_jour_-_visiativ.txt