4 Replies Latest reply on Jul 2, 2018 6:40 PM by Artem Taturevych

    Enable/disable "Lock Rotation" function with SW API

    Nikolay Bratovanov

      Hello,

       

      I have a two-link robot assembly with a concentric mate between the links. I'm trying to create a VBA macro with the following simple functionality:

       

      - Pressing the "LOCK R" ToggleButton enables the "Lock Rotation" function of the concentric mate;

      - Releasing the "LOCK R" ToggleButton disables the "Lock Rotation" function of the concentric mate;

       

      1.jpg

       

      I'm trying to do this with the following code:

       

      2.jpg

       

      As a result, the concentric mate ("Concentric5") is selected but the "Lock Rotation" function does not change! Can anyone help me with the code? I'm using the EditMate4 Method, but obviously something more has to be done. Thank you!

        • Re: Enable/disable "Lock Rotation" function with SW API
          Artem Taturevych

          Hi Nikolay,

           

          I'm afraid this is the known issue (have seen this before and able to reproduce from my side). Here is the workaround: #CODE|Lock Concentric Mate

           

          Thanks,
          Artem

          • Re: Enable/disable "Lock Rotation" function with SW API
            Suthida Thongnuch

            Hello Artem,

             

            I really like to see your workaround to this problem, but the link is broken. Could you please post the new link?

            I couldn't find any commands that get "Lock rotation" or "Unlock rotation" from concentric mates.

             

            Thank you,

            Suthida

              • Re: Enable/disable "Lock Rotation" function with SW API
                Artem Taturevych

                Hi Suthida,

                 

                Take a look at this one:

                 

                #If VBA7 Then 'SolidWorks 2015 and later (x64 VBA engine)

                     Private Declare PtrSafe Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

                #Else 'SolidWorks older than 2015 (x32 VBA engine)

                     Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

                #End If

                 

                Const WM_COMMAND As Long = 273

                Const LOCK_ROTATION_CMD As Long = 9680

                 

                Dim swApp As SldWorks.SldWorks

                Dim swModel As SldWorks.ModelDoc2

                Dim swSelMgr As SldWorks.SelectionMgr

                 

                Sub main()

                 

                     Set swApp = Application.SldWorks

                    

                     Set swModel = swApp.ActiveDoc

                    

                     Set swSelMgr = swModel.SelectionManager

                    

                     Dim swMateFeat As SldWorks.Feature

                    

                     Set swMateFeat = swSelMgr.GetSelectedObject6(1, -1)

                        

                     If Not swMateFeat Is Nothing Then

                         Dim swMate As SldWorks.Mate2

                         Set swMate = swMateFeat.GetSpecificFeature2

                         If swMate.Type = swMateType_e.swMateCONCENTRIC Then

                             ToggleLockRotation swMate

                         Else

                             MsgBox "Only concentric mate is supported"

                         End If

                     Else

                         MsgBox "Please select mate"

                     End If

                    

                End Sub

                 

                Sub ToggleLockRotation(swMate As SldWorks.Mate2)

                 

                     Dim swMateFeat As SldWorks.Feature

                    

                     Set swMateFeat = swMate

                    

                     swMateFeat.Select2 False, -1

                    

                     Dim swFrame As SldWorks.Frame

                 

                     Set swFrame = swApp.Frame

                    

                     SendMessage swFrame.GetHWnd(), WM_COMMAND, LOCK_ROTATION_CMD, 0

                    

                End Sub

                Thanks,
                Artem