Hide Table of Contents

Add Equation and Evaluate All Example (VBA)

This example shows how to use EquationMgr interfaces to add an equation to a model and

delay evaluation until all equations have been added.

'----------------------------------------------------------------------------

' Preconditions: Open any model document.

'

' Postconditions:

' 1. Observe 26 new equations in the Equations folder of the FeatureManager

'    design tree.

' 2. Observe the near-zero evaluation time for each equation

'    in the Immediate Window, demonstrating that the evaluations were delayed.

'----------------------------------------------------------------------------

Option Explicit

#Const ccTIMER = 1

Public Sub Main()

Dim swApp             As SldWorks.SldWorks

Dim swModel           As SldWorks.ModelDoc2

Dim swPart            As SldWorks.PartDoc

    Set swApp = Application.SldWorks

    Dim errors As Long

    Dim warnings As Long

   

   

    Set swModel = swApp.ActiveDoc

    Dim MyEqu    As SldWorks.EquationMgr

    

    Dim Index    As Integer

    Dim lValue   As Long

    Dim evalStatus As Long

    

    

#If ccTIMER = 1 Then

    Dim t1     As Single

    Dim t2     As Single

    

#Else

    Dim t1     As Date

    Dim t2     As Date

    

#End If

    

    

    Dim i As Long

    i = 0

    Set MyEqu = swModel.GetEquationMgr

    If MyEqu.GetCount > 0 Then

        Do While (i < 26)

            MyEqu.Delete (0)

            i = i + 1

        Loop

    End If

    

    For Index = Asc("A") To Asc("Z")

    

#If ccTIMER = 1 Then

        t1 = Timer

#Else

        t1 = Now

#End If

        

       'Delay solving each equation until after all equations are added (set solve parameter to False)

       'FeatureManager design tree not updated

        lValue = MyEqu.Add2(Index, """" & Chr$(Index) & """=" & Index, False)

        

        

#If ccTIMER = 1 Then

        t2 = Timer

#Else

        t2 = Now

#End If

        

        Debug.Print "Time of evaluation: "

        Debug.Print (t2 - t1)

        

        

    Next Index

    

    Debug.Print "number of equations added to EquationMgr is " & MyEqu.GetCount

    

    'Solve all equations after they have been added

    'FeatureManager design tree updated

    evalStatus = MyEqu.EvaluateAll

    

    Debug.Print "finished Add2 and EvaluateAll"

    

    Set MyEqu = Nothing

    Set swModel = Nothing

    'swApp.CloseAllDocuments True

    Set swApp = Nothing

End Sub



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Add Equation and Evaluate All Example (VBA)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:

x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2014 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.