使用SOLIDWORKS API升级活动SOLIDWORKS零件或装配中的装饰螺纹
{ width=500 }
此宏在SOLIDWORKS零件和装配中调用“升级装饰螺纹特征”命令,可以提高文档的性能。
此宏可与SOLIDWORKS任务计划程序或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 "螺纹未升级"
End If
Else
Err.Raise vbError, "", "请打开文档"
End If
GoTo finally
catch:
swApp.SendMsgToUser2 Err.Description, swMessageBoxIcon_e.swMbStop, swMessageBoxBtn_e.swMbOk
finally:
swApp.SetUserPreferenceToggle swUserPreferenceToggle_e.swEnableAllowCosmeticThreadsUpgrade, allowUpgrade
End Sub