Files
Delete global variable and all associated equations Associated model(s)
Code
Module: mMain
'Demonstrates how to delete a global variable with a specified name _
and all associated equations.
'Preconditions: "delete eqn.sldprt" is open
'Result: Global variable named "angle" is deleted along with all equations
' that cannot no longer solve.
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
Option Compare Text
Const SEARCH_STRING As String = "angle"
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swEqnMgr As SldWorks.EquationMgr
Dim i As Integer
Dim vSplit As Variant
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swEqnMgr = swModel.GetEquationMgr
'Delete global variable named "angle"
For i = 0 To swEqnMgr.GetCount - 1
vSplit = Split(swEqnMgr.Equation(i), "=")
vSplit(0) = Trim(vSplit(0))
vSplit(0) = Replace(vSplit(0), Chr(34), Empty)
If vSplit(0) = SEARCH_STRING Then
swEqnMgr.Delete i
Exit For
End If
Next i
'Verify that each equation can still successfully execute, otherwise _
delete that equation.
StartTraverse:
For i = 0 To swEqnMgr.GetCount - 1
Debug.Print swEqnMgr.Value(i) 'Necessary for IEquationMgr::Status
If swEqnMgr.Status = -1 Then
swApp.SendMsgToUser swEqnMgr.Equation(i) & vbCrLf & _
"This equation no longer evaluates and will be deleted."
swEqnMgr.Delete i
GoTo StartTraverse
End If
Next i
End Sub