Description
This utility is a must-have for SOLIDWORKS engineers who often use both measurement methods. This macro, known as the SOLIDWORKS macro to toggle dimension style, automates the process of toggling the SOLIDWORKS dimension style. The logic is simple but powerful, and proceeds as follows. The macro first checks the unit system used in the drawing.
If the dimension is decimal, the macro will change the style to fractional, will change the denominator (the fraction) to 1/32 (which is a common style in the industry), and will set the rounding to the nearest fraction. If the dimension is already in fractional style, then the macro instantly reverts the unit system back to decimal. This is a one-click solution to change the unit system quickly. It saves you time setting the style all over again, when the active drawing was set in a different unit system. It also has error handling, so that it can gracefully terminate if things go wrong.
System Requirements
- SOLIDWORKS Version: SOLIDWORKS 2014 or newer
- Operating System: Windows 10 or later
Pre-requisites
- The application SOLIDWORKS should be installed and running on the machine.
- An open drawing document must be running.
- The document must have some views with dimensions that have unit styles to switch.
Results
- The style of dimension in the active drawing document will automatically switch from fractional to decimal (or vice versa).
- In fractional unit styles, the denominator will automatically be set to 32, and rounding of the dimension to the nearest fraction will be turned on for precision.
Steps to Implement the Macro
- Prepare the Document: Make certain there is an active SOLIDWORKS drawing with the dimensions you want to adjust.
- Load and Execute the Macro:
- Open macro in SOLIDWORKS using the VBA editor (Alt + F11).
- Run the macro from SOLIDWORKS through Tools > Macro > Run to select the saved file.
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
Dim swApp As SldWorks.SldWorks ' SolidWorks application object
Dim swDraw As SldWorks.DrawingDoc ' Active drawing document
Dim boolstatus As Boolean ' Status flag for checking if operations were successful
Sub main()
' Error handling: jump to ErrorHandler if an error occurs
On Error GoTo ErrorHandler
' Get the SolidWorks application instance
Set swApp = Application.SldWorks
' Get the active document (drawing) in SolidWorks
Set swDraw = swApp.ActiveDoc
' Check if the current unit system is set to Decimal
If swDraw.GetUserPreferenceIntegerValue(swUnitsLinearDecimalDisplay) = swDECIMAL Then
' If Decimal, change the unit system to Fractional
boolstatus = swDraw.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swUnitsLinearRoundToNearestFraction, 0, True)
' Set linear display to fractional units
swDraw.SetUserPreferenceIntegerValue swUnitsLinearDecimalDisplay, swFRACTION
' Set the fractional denominator to 32 (1/32 increments)
swDraw.SetUserPreferenceIntegerValue swUnitsLinearFractionDenominator, 32
' Enable rounding to the nearest fraction
swDraw.SetUserPreferenceToggle swUnitsLinearRoundToNearestFraction, True
Else
' If the current unit system is not Decimal (i.e., it's Fractional), change it to Decimal
boolstatus = swDraw.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsLinearDecimalDisplay, 0, swFractionDisplay_e.swDECIMAL)
' Set linear display to decimal units
swDraw.SetUserPreferenceIntegerValue swUnitsLinearDecimalDisplay, swDECIMAL
End If
' End the macro execution
End
Exit Sub
ErrorHandler:
' End the macro execution in case of an error
End
End Sub
Macro
You can download the macro from here.
Need help with customization? Reach out to our team of experts!
This tool has simplified a common, tedious, repetitive task and offered engineers an efficient means to toggle SOLIDWORKS dimension style for compliance with different drawing standards. The default parameters (like the denominator of 1/32) will work for a lot of cases, but you may require different settings for your particular design environment.
If so, reach out to Blue Byte Systems Inc.! Our team of experts specialize in customizing and developing professional SOLIDWORKS macros and add-ins to meet explicit needs. Whether you are searching for a SOLIDWORKS macro to toggle dimension style or need a broader automation, we can help So… need some modifications to the default fractional denominator, or want to add this feature to a larger drawing automation script, contact us today!
Our experienced team of experts will ensure that you get a custom solution that meets your needs while maximizing drawing accuracy and overall workflow efficiency.
