4 Replies Latest reply on Sep 19, 2018 4:25 PM by Deepak Gupta

    Modifying Document Toggle Options

    Luke Frost

      Hi All,

       

      I am trying to create a simple macro that toggles the "Rename cut list folders with Description property value" in the document options of a part.

       

      I have found the following post, which helped me get the code (see below) working.

       

      Dim swApp As Object

      Dim Part As Object

      Dim boolstatus As Boolean

      Dim instance As IModelDocExtension

       

      Sub main()

      Set swApp = Application.SldWorks

      Set Part = swApp.ActiveDoc

      Set instance = Part.Extension

      boolstatus = instance.SetUserPreferenceToggle(swUserPreferenceToggle_e.swWeldmentRenameCutlistDescriptionPropertyValue, 0, True)

      End Sub

       

      The option does seem to be toggling on however the actual cutting list doesn't seem to be changing at all where as if i was to do it manually outside of the macro then it does change.  Am i missing something that i need to add in order to get this sorted.

       

      Thanks in advanced

       

      Luke

        • Re: Modifying Document Toggle Options
          Jim Sculley

          Force a rebuild:

           

          Part.ForceRebuild3 True

          • Re: Modifying Document Toggle Options
            Deepak Gupta

            Try these codes to toggle that option On and Off. The macro would also check if the active file is a weldment part or not.

             

            Option Explicit
            Dim swApp As SldWorks.SldWorks
            Dim Part As SldWorks.ModelDoc2
            Dim swPartDoc As SldWorks.PartDoc
            Dim boolstatus As Boolean
            Sub main()
            
            Set swApp = Application.SldWorks
            Set Part = swApp.ActiveDoc
            
            If Part Is Nothing Then
               MsgBox "Open a weldment part file and try again!!"
               Exit Sub
            End If
            
            If Part.GetType <> 1 Then
                MsgBox "Open a weldment part file and try again!!"
               Exit Sub
            End If
            
            Set swPartDoc = Part
            If swPartDoc.IsWeldment Then
                If swPartDoc.Extension.GetUserPreferenceToggle(swWeldmentRenameCutlistDescriptionPropertyValue, swDetailingNoOptionSpecified) = False Then
                    boolstatus = swPartDoc.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swWeldmentRenameCutlistDescriptionPropertyValue, swDetailingNoOptionSpecified, True)
                Else
                    boolstatus = swPartDoc.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swWeldmentRenameCutlistDescriptionPropertyValue, swDetailingNoOptionSpecified, False)
                End If
            Else
               MsgBox "Open a weldment part file and try again!!"
               Exit Sub
            End If
            
            swPartDoc.ForceRebuild3 True
            swPartDoc.Save
            
            End Sub
            
            • Re: Modifying Document Toggle Options
              Luke Frost

              Hi Both

               

              Thank you both for your swift replies and helping me out with this one.  Im guessing it was just that force rebuild i was missing and then Deepak Gupta thanks for providing a much better version taking in the abillity to completly toggle the switch on and off and add the validation.

               

              On a slightly different note do either of you have any good recomendations on books or resources where its possible to learn more about the API apart from the Help obviously as is is soemthign that i would like to get more into.  I am happy to raise this as a sepetate thread if its seen fit to.

               

              Thanks again

               

              Luke