Salut,
Je viens de tester "swModel.Save" sur une simple macro SolidWorks, exécutée sur Solidworks avec un plan ouvert, et cela met bien à jour les variables mappés, comme un simple Ctrl +S.
Voici le code complet (Script dans la tache PDM), merci :
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
Case "sldprt"
intFileType = 1
Case "sldasm"
intFileType = 2
Case "slddrw"
intFileType = 3
Case Else
Msg = "Erreur format de fichier !" + Chr(13) + Chr(10) + "*.sldprt, *.sldasm, *.slddrw uniquement !" + Chr(13) + Chr(10) + "Le fichier " + strFileName + " est ignoré." ' 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 = "Erreur : Fichier " + strFileName + " déjà extrait par : " + 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, "Mise à jour automatique", 64
End Sub