This website uses cookies to ensure you get the best experience on our website. By using our website you agree on the following Cookie Policy, Privacy Policy, and Terms Of Use
If active model is assembly, macro optionally allows to remove all equations from each component of the assembly. The following message will be displayed. Click Yes to remove equations from all components on all levels and No to only process equations of the top level assembly.
Set the DELETE_BROKEN_ONLY option to True in order to only remove the broken (dangling) equations.
IMPORTANT: Use this macro on your own risk. This macro modifies your data (deletes all equations) please backup your file before running this macro
Const DELETE_BROKEN_ONLY AsBoolean = False'if this flag is True than only broken equations are deleted, otherwise all equations are deletedDim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swEqMgr As SldWorks.EquationMgr
Sub main()
Set swApp = Application.SldWorks
try_:
OnErrorGoTo catch_
Set swModel = swApp.ActiveDoc
Dim hasDeleted AsBoolean
DeleteEquationsFromModel swModel, hasDeleted
If swModel.GetType = swDocumentTypes_e.swDocASSEMBLY ThenIf swApp.SendMsgToUser2("Do you want to delete equations in all components of the assembly?", swMessageBoxIcon_e.swMbQuestion, swMessageBoxBtn_e.swMbYesNo) = swMessageBoxResult_e.swMbHitYes ThenDim swAssy As SldWorks.AssemblyDoc
Set swAssy = swModel
'component needs to be loaded in memory in order to process it's equations
swAssy.ResolveAllLightWeightComponents TrueDim vComps AsVariant
vComps = swAssy.GetComponents(False)
Dim i AsIntegerFor i = 0 To UBound(vComps)
Dim swComp As SldWorks.Component2
Set swComp = vComps(i)
Dim swCompModel As SldWorks.ModelDoc2
Set swCompModel = swComp.GetModelDoc2
IfNot swCompModel IsNothingThenDim hasCompEqDeleted AsBoolean
DeleteEquationsFromModel swCompModel, hasCompEqDeleted
If hasCompEqDeleted Then
hasDeleted = TrueEndIfEndIfNextEndIfEndIfIf hasDeleted Then
swModel.ForceRebuild3 FalseEndIfGoTo finally_
catch_:
swApp.SendMsgToUser2 Err.Description, swMessageBoxIcon_e.swMbStop, swMessageBoxBtn_e.swMbOk
finally_:
EndSubSub DeleteEquationsFromModel(model As SldWorks.ModelDoc2, ByRef hasDeleted AsBoolean)
Set swEqMgr = model.GetEquationMgr()
Dim i AsInteger
hasDeleted = False'iterate in the reverse direction as the equation index will change once previous equation is deletedFor i = swEqMgr.GetCount - 1 To 0 Step -1
IfNot DELETE_BROKEN_ONLY Or IsEquationBroken(swEqMgr, i) Then
swEqMgr.Delete i
hasDeleted = TrueEndIfNextIf hasDeleted Then'deleting equation doesn't make the model dirty
model.SetSaveFlag
EndIfEndSubFunction IsEquationBroken(eqMgr As SldWorks.EquationMgr, index AsInteger) AsBooleanConst STATUS_BROKEN AsInteger = -1
Dim val AsString
val = eqMgr.Value(index) 'evaluate to get the status
IsEquationBroken = (eqMgr.Status = STATUS_BROKEN)
EndFunction