Skip to main content

Upgrade cosmetic threads in active SOLIDWORKS part or assembly using SOLIDWORKS API

Upgrade cosmetic threads command{ width=500 }

This macro invokes the Upgrade cosmetic thread features command in SOLIDWORKS part and assembly which may improve the performance of the document.

This macro will be beneficial to use along with task automation software such as SOLIDWORKS Task Scheduler or Batch+.

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2

Sub main()

Set swApp = Application.SldWorks

Dim allowUpgrade As Boolean
allowUpgrade = swApp.GetUserPreferenceToggle(swUserPreferenceToggle_e.swEnableAllowCosmeticThreadsUpgrade)

try:
On Error GoTo catch

Set swModel = swApp.ActiveDoc

If Not swModel Is Nothing Then

swApp.SetUserPreferenceToggle swUserPreferenceToggle_e.swEnableAllowCosmeticThreadsUpgrade, True

If False = swModel.Extension.UpgradeLegacyCThreads() Then
Debug.Print "Thread is not upgraded"
End If

Else
Err.Raise vbError, "", "Please open document"
End If

GoTo finally

catch:
swApp.SendMsgToUser2 Err.Description, swMessageBoxIcon_e.swMbStop, swMessageBoxBtn_e.swMbOk
finally:

swApp.SetUserPreferenceToggle swUserPreferenceToggle_e.swEnableAllowCosmeticThreadsUpgrade, allowUpgrade

End Sub