6 Replies Latest reply on Jul 28, 2017 6:52 AM by Mike Sveda

    Macro to clear configuration specific properties?

    Mike Sveda

      Is this possible?  I have a customer that doesn't want configuration specific tabs filled out, however, my PDM system writes to all configurations.  This would be an outside vault operation if it can be done.  Thanks.

        • Re: Macro to clear configuration specific properties?
          Nilesh Patel

          Hi Mike,

           

          Try following:

           

          Option Explicit
          
          
          Sub main()
          
          
              Dim swApp               As SldWorks.SldWorks
              Dim swModel             As SldWorks.ModelDoc2
              Dim swCustPropMgr       As SldWorks.CustomPropertyManager
              Dim vConfigNames        As Variant
              Dim vConfigPropNames    As Variant
              Dim i                   As Integer
              Dim j                   As Integer
              Dim lErrors             As Long
              Dim lWarnings           As Long
              
              
              Set swApp = Application.SldWorks
              Set swModel = swApp.ActiveDoc
              
              If swModel.GetType <> swDocumentTypes_e.swDocASSEMBLY And swModel.GetType <> swDocumentTypes_e.swDocPART Then Exit Sub
              
              vConfigNames = swModel.GetConfigurationNames
              
              If IsEmpty(vConfigNames) = False Then
                  For i = 0 To UBound(vConfigNames)
                      Set swCustPropMgr = swModel.Extension.CustomPropertyManager(vConfigNames(i))
                      vConfigPropNames = swCustPropMgr.GetNames
                      If IsEmpty(vConfigPropNames) = False Then
                          For j = 0 To UBound(vConfigPropNames)
                              swCustPropMgr.Delete2 (vConfigPropNames(j))
                          Next j
                      End If
                  Next i
              End If
              
              swModel.EditRebuild3
              
              If swModel.Save3(swSaveAsOptions_e.swSaveAsOptions_Silent, lErrors, lWarnings) = False Then
                  swApp.SendMsgToUser2 "Error: Failed to save model document '" & swModel.GetTitle & "'.", swMessageBoxIcon_e.swMbStop, swMessageBoxBtn_e.swMbOk
                  Exit Sub
              End If
              
          End Sub
          

           

          The macro works for both part and assembly document, but you need to make sure that model is checked out by user as it saves the model in the end.

           

          Regards,