3 Replies Latest reply on Oct 28, 2014 5:18 PM by Daniel Andersson

    Delete equations at index and read excel

    Alex Smith

      Hello everyone.  I have been struggling with getting something to work.  I am working on an automation which runs off of a series of global variables and equations.  I am looking for some new knowledge.


      1. Can someone layout the syntax on how to delete all equations (or the suppressed ones) and unlink the text file yet still keep all global variables?  I can delete the equations folder, but i want to keep the equations folder to retain the global variables.
      2. I am moving to another phase of the automation and want to use excel.  Can someone tell me how to read an cell in excel which has the name of a component and assemble it?  I am looking to have an Access database export a component list to excel, and have Solidworks create an assembly that list.


      Any help is appreciated and thanks in advance!


        • Re: Delete equations at index and read excel
          Daniel Andersson

          1) I tested out a little bit and came up with this. It deletes all equations and keeps global variables and the feature suppressions.

          See this as a basic start. The Split function might be possible to handle different and perhaps in more convenient way than going for split twice... The concept of the idea is that only equations have "@" in their name. I can not find any other way since the equation manager is not giving anything else useful than the equation string.

          For further reference, you find the members of the equation manager here. By using that you can add other functions such just delete the suppressed equations.


          I would also recommend that you read about the accessor ModelDoc2::GetEquationMgr


          If you want to try the macro, do it on some parts you have copies off...

          Dim swApp As SldWorks.SldWorks
          Dim swModel As SldWorks.ModelDoc2
          Dim swEqnMgr As SldWorks.EquationMgr


          Sub main()
          Dim sSplit As Variant


          Set swApp = Application.SldWorks
          Set swModel = swApp.ActiveDoc
          Set swEqnMgr = swModel.GetEquationMgr


          For i = 0 To swEqnMgr.GetCount - 1
              sSplit = Split(swEqnMgr.Equation(i), """")
              sSplit = Split(sSplit(1), "@")
              If UBound(sSplit) > 0 Then
                  MsgBox swEqnMgr.Equation(i) & " This is a equation and is about to be deleted "
                  swEqnMgr.Delete(i)  'This will delete this equation
                  GoTo Restart_: 'Equation deleted, which mess up the index... restart the loop.
                  MsgBox swEqnMgr.Equation(i) & " This is a global var OR a Feature suppression"
              End If
          Next i

          End Sub


          2) Making assemblies on the fly... well.. here is different levels of automation to talk about. Do you want to have the data from the access database to tell the assembly to replace a few parts..? If so you should dig into how to replace referenced parts in a assembly. You may also think of to connect directly to the access database.