3 Replies Latest reply on Jun 28, 2018 4:57 PM by Artem Taturevych

    Deleting a global variable of a specified name with equation manager

    Jonathan Hoffman



      So I'm working on a macro to set up various quantities in one part document, so that I can reference it in the drawing, and right now I am working on creating a global variable that references all the relevant custom properties.  I need to figure out how to add this equation, and replace the old one if the old one exists.


      Right now, my VBA code looks something like this (this is copy-pasted from a much larger code), and I can't figure out how to delete an equation by variable name instead of by index or by the whole equation.  I can't search by the whole equation, because I don't have any way of knowing what the old equation was, as it might have been changed.  Does anyone have any ideas on how I might be able to do this?


      Any help y'all might have would be greatly appreciated.



              Dim swEquationMgr As EquationMgr

              Dim longEquation As Long

              Dim Add3() As Integer

              Dim Total_Quantity As String

              Set swEquationMgr = Part.GetEquationMgr


          If UsedFor_Quantity_Array(1) = -1 Then


              'This is the case in which there are no callbacks and "Total_Quantity" equals QTY


              Total_Quantity = Chr(34) & "QTY" & Chr(34)


              longEquation = swEquationMgr.Add3(-1, Total_Quantity, True, swAllConfiguration, Empty)






              'This is if there are callbacks and the total quantity is the sum of QTY and the callback quantities



              Dim Equation As String





              For eq = 0 To UBound(UsedFor_Quantity_Array)


                  Equation = Equation & " + " & Chr(34) & "Callback_Quantity" & eq & Chr(34)




              Total_Quantity = "Total Quantity = " & Equation


              longEquation = swEquationMgr.Add3(-1, Total_Quantity, True, swAllConfiguration, Empty)


             Dim Total_Quantity_Ref As String

             Total_Quantity_Ref = Chr(34) & "Total Quantity@" & file & Chr(34)



             retval = Part.DeleteCustomInfo2("", "Total Qty")

             retval = Part.AddCustomInfo3("", "Total Qty", swCustomInfoText, Total_Quantity_Ref)