From 1327bf1cbde78d72dde5869fc0e9f803c2088d96 Mon Sep 17 00:00:00 2001 From: xarial-dev <59645027+xarial-dev@users.noreply.github.com> Date: Wed, 22 Jul 2020 16:42:13 +1000 Subject: [PATCH] Added error handling Added SW style message box --- .../document/delete-model-equations/Macro.vba | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/solidworks-api/document/delete-model-equations/Macro.vba b/solidworks-api/document/delete-model-equations/Macro.vba index ba96df51..5caada0a 100644 --- a/solidworks-api/document/delete-model-equations/Macro.vba +++ b/solidworks-api/document/delete-model-equations/Macro.vba @@ -8,6 +8,9 @@ Sub main() Set swApp = Application.SldWorks +try_: + On Error GoTo catch_ + Set swModel = swApp.ActiveDoc Dim hasDeleted As Boolean @@ -16,7 +19,7 @@ Sub main() If swModel.GetType = swDocumentTypes_e.swDocASSEMBLY Then - If MsgBox("Do you want to delete equations in all components of the assembly?", vbYesNo) = vbYes Then + If swApp.SendMsgToUser2("Do you want to delete equations in all components of the assembly?", swMessageBoxIcon_e.swMbQuestion, swMessageBoxBtn_e.swMbYesNo) = swMessageBoxResult_e.swMbHitYes Then Dim swAssy As SldWorks.AssemblyDoc Set swAssy = swModel @@ -59,6 +62,12 @@ Sub main() swModel.ForceRebuild3 False End If + GoTo finally_ + +catch_: + swApp.SendMsgToUser2 Err.Description, swMessageBoxIcon_e.swMbStop, swMessageBoxBtn_e.swMbOk +finally_: + End Sub Sub DeleteEquationsFromModel(model As SldWorks.ModelDoc2, ByRef hasDeleted As Boolean) @@ -94,4 +103,4 @@ Function IsEquationBroken(eqMgr As SldWorks.EquationMgr, index As Integer) As Bo IsEquationBroken = (eqMgr.Status = STATUS_BROKEN) -End Function \ No newline at end of file +End Function