Files
Code
Module: mMain
'If nothing is selected, macro toggles document units between IPS and MMSG.
'If a dimension is selected, macro toggles the dimension units between in and mm.
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim swSelMgr As SelectionMgr
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
If swSelMgr.GetSelectedObjectCount2(-1) = 0 Then
ToggleDocUnits swModel
Else
If swSelMgr.GetSelectedObjectType3(1, -1) = swSelDIMENSIONS Then ToggleDimUnits swSelMgr
End If
End Sub
Private Sub ToggleDocUnits(swModel As ModelDoc2)
Select Case swModel.Extension.GetUserPreferenceInteger( _
swUserPreferenceIntegerValue_e.swUnitSystem, _
swUserPreferenceOption_e.swDetailingNoOptionSpecified)
Case swUnitSystem_IPS
swModel.Extension.SetUserPreferenceInteger swUserPreferenceIntegerValue_e.swUnitSystem, _
swUserPreferenceOption_e.swDetailingNoOptionSpecified, swUnitSystem_MMGS
Case swUnitSystem_MMGS
swModel.Extension.SetUserPreferenceInteger swUserPreferenceIntegerValue_e.swUnitSystem, _
swUserPreferenceOption_e.swDetailingNoOptionSpecified, swUnitSystem_IPS
Case Else
MsgBox "This documents's unit system is not IPS or MMGS and therefore cannot be toggled."
End Select
End Sub
Private Sub ToggleDimUnits(swSelMgr As SelectionMgr)
Dim swDispDim As DisplayDimension
Set swDispDim = swSelMgr.GetSelectedObject6(1, -1)
Select Case swDispDim.GetUnits
Case -1
MsgBox "This dimension's unit system is controlled by the document unit system. You must override the unit system if you wish to toggle it."
Case swINCHES
swDispDim.SetUnits Empty, swMM, Empty, Empty, Empty
Case swMM
swDispDim.SetUnits Empty, swINCHES, Empty, Empty, Empty
Case Else
MsgBox "This dimension's units are not in inches or millimeters and therefore cannot be toggled."
End Select
End Sub