Description
Pre-select one or more components in an assembly and execute the macro. The selected components will become isolated in the assembly. The SolidWorks macro to instantly isolate selected components in an assembly can be placed on the Graphics Area menu (which pops up when you right-click a component) for convenient access.
System Requirements
- SolidWorks Version: SolidWorks 2014 or newer
- Operating System: Windows 7 or later
Prerequisites
- At least one component must be pre-selected in an active SolidWorks assembly document.
- The active document must be an assembly document (.SLDASM).
Results
- The pre-selected components will be isolated in the assembly environment.
- If no components are selected, or if the active document is not an assembly document, a message box will appear to direct the user to do so.
Steps to Set Up the Macro
- Registering the Macro File: Make sure you have SolidWorks open, and navigate to Tools > Macro > Newā¦
- Name and Register: Name the macro meaningfully (e.g., IsolateComponents.swp), then save the file. This will automatically open your VBA editor.
- Paste the VBA code: Please download the VBA code we have listed below and place it within your editor.
- Run Macro (Optional Next Setup): Close the VBA editor and save when prompted. Now you can run the macro with Tools > Macro > Run, or with a shortcut, or you can add it to a shortcut menu for convenience.
VBA Macro Code
Visual Basic
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
' 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 ' Main subroutine to isolate selected components in an assembly Sub main() ' Declare SolidWorks application and active document objects Dim swApp As Object ' SolidWorks application object Dim Part As Object ' Active document object (assembly) Dim boolstatus As Boolean ' Boolean status to capture operation results Dim longstatus As Long, longwarnings As Long ' Long variables for capturing status and warnings ' Initialize SolidWorks application and get the active document Set swApp = Application.SldWorks Set Part = swApp.ActiveDoc ' Check if there is an active document open If Part Is Nothing Then MsgBox "No active document found. Please open an assembly and try again.", vbCritical, "No Active Document" Exit Sub End If ' Check if the active document is an assembly If Part.GetType <> swDocASSEMBLY Then MsgBox "This macro only works on assemblies. Please open an assembly and try again.", vbCritical, "Invalid Document Type" Exit Sub End If ' Isolate the pre-selected components in the assembly ' RunCommand with ID 2726 is used to isolate components in SolidWorks boolstatus = Part.Extension.RunCommand(2726, "") ' Note: The following command can be used to exit isolation mode if required: ' boolstatus = Part.Extension.RunCommand(2732, "") ' RunCommand ID 2732 exits isolate mode ' Clean up by releasing references to objects Set Part = Nothing Set swApp = Nothing End Sub |
Macro
You can download the macro fromĀ here.
We build custom macros and add-ins that meet your specific workflow needs. Contact us to discuss custom development needs and projects!
