11 Replies Latest reply on Feb 13, 2018 10:48 AM by Lasse Nielsen

    PDM task to update drawing

    Lasse Nielsen

      Hello Forum,


      Hopeully I will be able to explain the situation properly.


      Our current set up matches something like this How to Link Variables in SOLIDWORKS PDM to a Newly Created Drawing


      Meaning that our drawings title block and data cards inherits it data from the model represented on the drawing. This includes the uniqe drawing number and the drscription.


      In the PDM vault the uniqe number column and description column thus hold identical values for a part and its associated drawing which is great.


      Now lets say you find a typo in the parts description. You fix the type and now you need to update the value on the drawing as well. What i'm looking for is an automated task that will check out the drawing, update it, save it and check it back in so that the title block and the data card gets updated with new description or anything similar.


      Any suggestions?

        • Re: PDM task to update drawing
          Jacob Corder

          Do you have pdm professional or pdm standard?

          If you have standard then probably not. If professional then definitely. And easy.


          Answer what vault product you have then we can proceed.

            • Re: PDM task to update drawing
              Lasse Nielsen

              We have PDM professional

                • Re: PDM task to update drawing
                  Jacob Corder

                  ok to do this you will need to write a solidworks addin or macro.  macros fire when asked to, they can also be events but more complicated and less reliable as the end user has to either launch solidworks in a macro state or click a button.


                  addins are always best in my opionion.


                  what you need to do is start writing.  if your not capable of doing it you will need to find someone to hire.  i will not write this for you but there are some on here who do this for a living,  Keith Rice at CADSharp does this.


                  i push people to him on here recently because they are great at developing this type of stuff. 


                  Steps to achieve this:

                  execute some sort of check, if it fails the check, get the drawing document from the vault using your own code.


                  you will then need to use the EPDM API to get the IEDMFile from the IEDMVault object


                  once you have the file you can execute a 2016 SOLIDWORKS API Help - LockFile Method (IEdmFile5)

                  once it is checked out (Locked) then you can open and update the drawing with your custom code.

                  then when completed, execute 2016 SOLIDWORKS API Help - UnlockFile Method (IEdmFile5)



                  if you have not written any code before i would suggest attempting it as its very powerful. i didn't write any code until 5 years ago. i started with solidworks automation. so it can be done without any programming experience and training.

                    • Re: PDM task to update drawing
                      Lasse Nielsen

                      Hi Jacob,


                      I'm am familiar with writing macros on a simple basis. And have actually created a macro that indeed does check out the drawing, opens it, saves it, closes the drawing and checks it back in.


                      Option Explicit


                      Dim swApp As SldWorks.SldWorks

                      Dim swModel As SldWorks.ModelDoc2


                      Dim pdmVault As Object


                      Dim strFullPath As String

                      Dim strFolderPath As String


                      Dim strFileType As String

                      Dim intFileType As Integer


                      Dim i As Integer

                      Dim strFileName As String



                      Sub Main()


                          'Initialize macro

                          Set swApp = Application.SldWorks


                          strFullPath = "<Filepath>"

                          strFolderPath = "<Path>"



                          'Limit the macro to SLDDRW files

                          strFileType = LCase(Right(strFullPath, 6))


                          Select Case strFileType

                              Case "slddrw"

                                  intFileType = 3

                              Case Else


                          End Select



                          'Grabs filename only

                          i = InStrRev(strFullPath, "\")

                          strFileName = Right(strFullPath, Len(strFullPath) - i)


                          'Create vault object

                          Set pdmVault = CreateObject("ConisioLib.EdmVault")

                          pdmVault.loginauto "[vaultName]", 0


                          Dim folder As Object

                          Set folder = pdmVault.GetFolderFromPath(strFolderPath)


                          Dim file As Object

                          Set file = pdmVault.GetFileFromPath(strFullPath, folder)



                          'Check out if needed

                          If False = file.IsLocked Then

                              file.LockFile folder.ID, 0

                          End If



                          'open model

                          Set swModel = swApp.OpenDoc(strFullPath, intFileType)

                          swModel.ForceRebuild3 False


                          swApp.CloseDoc strFileName



                         'Check in

                          If True = file.IsLocked Then

                              file.UnlockFile 0, "Checked in by Macro"

                          End If


                      End Sub


                      And it does just that. in the PDM vault I can see that the modified column (i think this is a MS explorer column) is updated, but description column is not updated.


                      The code is executed as a task script

                  • Re: PDM task to update drawing
                    Christian Nordenström

                    I´m also very interested in a solution for this.