4 Replies Latest reply on Aug 29, 2017 10:17 AM by Michael Dekoning

    Clean property script

    Lasse Nielsen

      Hello Forum,


      I need some help with a macro. I have modified some code from another macro as seen below. I am trying to delete some old and very annoying properties from files located in the vault. Others need renaming due to confusing names. The idea is to run it as a task from the right-click menu.


      So far the macro opens the file in question, but in read-only mode and thus not able to delete or rename any properties. I somehow need a chunk of code that checks the file out before starting the cleaning process.


      Hopefully someone can help me out here?




      Dim swModel As sldworks.ModelDoc2

      Dim swCustPropMgr As SldWorks.CustomPropertyManager


      Dim Vault As Object

      Dim boolProperty As Boolean


      Sub main()


          docFileName = "<Filepath>"


          If LCase(Right(docFileName, 7)) = ".sldasm" Then

              Set swApp = Application.SldWorks

              swApp.Visible = True

              OpenAndSave docFileName

              Exit Sub


              Exit Sub

          End If


      End Sub




      Sub OpenAndSave(docFileName)

          Dim swDocSpecification As SldWorks.DocumentSpecification


          'Login to vault

          Set swApp = Application.SldWorks

          Set Vault = CreateObject("ConisioLib.EdmVault.1")

          Vault.Login "Admin", "PW", "VaultName"


          'Open file with specifications

          Set swDocSpecification = swApp.GetOpenDocSpec(docFileName)

          swDocSpecification.Silent = True

          swDocSpecification.ConfigurationName = "Default"

          Set swModel = swApp.OpenDoc7(swDocSpecification)



          'What to do?


          'Test deleting property & test renaming property

          Set swCustPropMgr = swModel.Extension.CustomPropertyManager("Default")


          swCustPropMgr.Delete2 "Kunde"


          Dim strValue As String

          Dim strResolved As String


          boolProperty = swCustPropMgr.Get4("DimAfdeling", False, strValue, strResolved)


          If boolProperty = True Then

              swCustPropMgr.Delete2 "DimAfdeling"

              swCustPropMgr.Add3 "Department", swCustomInfoText, strValue, 1

          End If



          'What to do?


      End Sub

        • Re: Clean property script
          Deepak Gupta

          If you're looking to remove the custom properties, then you can can use Document Manager (you should be on subscription to request your DM key) and can add/update/remove the properties without opening the files. Not sure how to use DM with Vault.

          • Re: Clean property script
            Michael Dekoning


            What version of PDM are you running? I do not think that PDM Professional 2017 API supports VBA.

              • Re: Clean property script
                Lasse Nielsen

                Hi Michael,


                After some research i found that


                A. the macro I copied some code from, appears to be very sloppy coded and basically useless

                B. scripts run from tasks (PDM administration -> Tasks) has to be done in VB.net or C#


                Regarding B. Is Dassault abandoning VBA or are you supposed to be coding general macros on VBA and PDM scripts in C#?

                  • Re: Clean property script
                    Michael Dekoning

                    I don't think that Dassault is abandoning VBA but that would be better answered by them.


                    I recall in earlier EPDM API help files there were VBA examples that have been removed from the current help. I think for PDM Tasks that VBA can still be used, but looking through the "script" for the ones they provide the files are not checked out. I can tell you for VB.Net or C# once you have the IEdmFile5 object you call the LockFile method to check out the file.