Description
- The macro targets a user-defined mate set to “Angle 0 Deg.”
- The macro toggles the mate’s suppression status (unsuppressing and immediately repressing).
System Requirements
- SolidWorks Version: SolidWorks 2014 or newer
- Operating System: Windows 7 or later
Pre-Requisites
- This macro must be executed from within an active SOLIDWORKS assembly document that contains the indicated target mate called “Angle 0 Deg.”. (The code can be changed to target any of the mates.)
Results
- The assigned mate, “Angle 0 Deg,” is programmatically toggled between suppressed and unsuppressed states.
- The automation cycle checks to see if the assembly constraints are stable without permanently changing any constraints.
- Optional: The code contains an additional feature to maximize the view of the assembly during the operation for visual feedback, which can be turned on easily by the user.
Steps to Set Up the Macro
- Open the SOLIDWORKS Assembly
- Check that the Active Document in SOLIDWORKS is the Assembly file that contains the specific mate that you will be toggling.
- Access and Load the VBA Macro
- Access the VBA Editor: Open the VBA editor in SolidWorks by pressing (Alt + F11).
- Load the Code: Insert a new Module (Insert > Module) and then paste the provided VBA Code from the SOLIDWORKS macro for automated mate toggling into the module window.
- Run the Macro
- Run the macro from within the VBA Editor itself (Run > Run Sub/UserForm) or save the macro file (.swp) and run the macro from the SOLIDWORKS menu (Tools > Macro > Run) or as a custom button on a custom Toolbar.
VBA Macro Code
' Disclaimer:
' The code provided should be used at your own risk.
' Blue Byte Systems Inc. assumes no responsibility for any issues or damages that may arise from using or modifying this code.
' For more information, visit [Blue Byte Systems Inc.](https://bluebyte.biz).
Option Explicit
' Declare variables for the SolidWorks application and active document
Dim swApp As Object ' SolidWorks application object
Dim Part As Object ' Active document object (part or assembly)
Dim boolstatus As Boolean ' Boolean to capture operation success
Dim longstatus As Long, longwarnings As Long ' Longs to capture detailed operation statuses
Sub main()
' Initialize the SolidWorks application object
Set swApp = Application.SldWorks
' Get the currently active document
Set Part = swApp.ActiveDoc
' Optional: Declare and set the active model view
Dim myModelView As Object ' Object for controlling the model view
Set myModelView = Part.ActiveView
' Optional: Maximize the SolidWorks window (uncomment to enable functionality)
' myModelView.FrameState = swWindowState_e.swWindowMaximized
' Step 1: Select the mate named "Angle 0 Deg"
boolstatus = Part.Extension.SelectByID2("Angle 0 Deg", "MATE", 0, 0, 0, False, 0, Nothing, 0)
' Step 2: Unsuppress the selected mate to activate it
Part.EditUnsuppress2
' Step 3: Clear the current selection to reset the environment
Part.ClearSelection2 True
' Step 4: Re-select the mate named "Angle 0 Deg"
boolstatus = Part.Extension.SelectByID2("Angle 0 Deg", "MATE", 0, 0, 0, False, 0, Nothing, 0)
' Step 5: Suppress the selected mate to deactivate it
Part.EditSuppress2
' Step 6: Clear the selection again to clean up the selection state
Part.ClearSelection2 True
End Sub
Macro
You can download the macro fromĀ here.
Need to customize the macro?
Contact us today to help create a more powerful, custom solution for your specific constraint testing experience.
