Hide Table of Contents

Add Equation and Evaluate All Example (C#)

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.       

//      

// Post-conditions:     

// 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.   

//-------------------------------------------------------------------------

using SolidWorks.Interop.sldworks;

using SolidWorks.Interop.swconst;

using System;

using System.Diagnostics;

namespace AddEquationAndEvaluateAll_CSharp.csproj

{

    partial class SolidWorksMacro

    {

        public void Main()

        {

            ModelDoc2 swModel = default(ModelDoc2);

            swModel = (ModelDoc2)swApp.ActiveDoc;

            EquationMgr MyEqu = default(EquationMgr);

            int Index = 0;

            long lValue = 0;

            long evalStatus = 0;   

          

                System.DateTime t1 = default(System.DateTime);

                System.DateTime t2 = default(System.DateTime);

      

            long i = 0;

            i = 0;

            MyEqu = swModel.GetEquationMgr();

            if (MyEqu.GetCount() > 0)

            {

                while ((i < 26))

                {

                    MyEqu.Delete(0);

                    i = i + 1;

                }

            }

            Debug.Print("Delaying evaluation of equations until the end...");

            for (Index = System.Convert.ToInt32('A'); Index <= System.Convert.ToInt32('Z'); Index++)

            {

                t1 = DateTime.Now;

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

                //FeatureManager design tree not updated

                lValue = MyEqu.Add2(Index, "\"" + System.Convert.ToChar(Index) + "\"=" + Index, false);

                

                t2 = DateTime.Now;

                Debug.Print("Time of evaluation for character " + System.Convert.ToChar(Index) + ": ");

                TimeSpan t3 = t2 - t1;

                Debug.Print(t3.ToString());

            }

            Debug.Print("number of equations added to EquationMgr is " + MyEqu.GetCount());

            //Solve all equations after they have been added

            //FeatureManager design tree updated

            Debug.Print("Evaluating all equations...");

            evalStatus = MyEqu.EvaluateAll();

            Debug.Print("finished Add2 and EvaluateAll");

            MyEqu = null;

            swModel = null;

            //swApp.CloseAllDocuments True

            swApp = null;

        }

        public SldWorks swApp;

    }

}



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 (C#)
*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.