<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to do a calculation by a formula line the evaluate method in EXCEL VBA? in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7803088#M27310</link>
    <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4476837"&gt;@ActivistInvestor&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much.&lt;/P&gt;
&lt;P&gt;Do you have more help doc of CalcEngine?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't know how to write the 'string expression'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my case i will use '+,-,*,/,^(Power),Sqrt,Sqr,(),Pi'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;best wishes&lt;/P&gt;
&lt;P&gt;swaywood&lt;/P&gt;</description>
    <pubDate>Fri, 23 Feb 2018 14:03:19 GMT</pubDate>
    <dc:creator>swaywood</dc:creator>
    <dc:date>2018-02-23T14:03:19Z</dc:date>
    <item>
      <title>How to do a calculation by a formula line the evaluate method in EXCEL VBA?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7785597#M27294</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a string like '(1-2+3)/4*5^2', How to calculate the fomula by some exist dll or class?&lt;/P&gt;
&lt;P&gt;I found excel vba's evaluate function can do this, but does not work for every computer, I don't know the reason.&lt;/P&gt;
&lt;P&gt;If you know other dll has this method, please tell me , thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or you have other way to solve this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;summary&amp;gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;/// 利用Excel VBA Evaluate&lt;BR /&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;/summary&amp;gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;param name="str"&amp;gt;&amp;lt;/param&amp;gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;public static double Cal(this string str)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;string dllName = System.Reflection.Assembly.GetExecutingAssembly().Location.ToString();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;var app = new Excel.Application();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;FileInfo info = new FileInfo(dllName);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Excel.Workbook workbook = app.Workbooks.Add(info.Directory.FullName + "\\Cal.xlt");&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Excel.Worksheet worksheet = workbook.Worksheets.Add() as Excel.Worksheet;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;var result = worksheet.Evaluate(str);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;app.DisplayAlerts = false;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;app.Quit();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;double data = double.Parse(result.ToString());&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return data;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;}&lt;/P&gt;</description>
      <pubDate>Sat, 17 Feb 2018 10:41:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7785597#M27294</guid>
      <dc:creator>swaywood</dc:creator>
      <dc:date>2018-02-17T10:41:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a calculation by a formula line the evaluate method in EXCEL VBA?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7785706#M27295</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        static double Calc(string expr)
        {
            bool wasOpen = false;
            dynamic xlApp;
            try
            {
                xlApp = Marshal.GetActiveObject("Excel.Application");
                wasOpen = true;
            }
            catch
            {
                try { xlApp = Activator.CreateInstance(Type.GetTypeFromProgID("Excel.Application")); }
                catch { throw; }
            }
                var book = xlApp.Workbooks.Add();
                var sheet = book.ActiveSheet;
            try
            {
                sheet.Cells[1, 1] = "=" + expr;
                return sheet.Cells[1, 1].Value;
            }
            catch { return double.NaN; }
            finally
            {
                book.Close(false);
                book = null;
                if (!wasOpen)
                {
                    xlApp.Quit();
                    Marshal.ReleaseComObject(xlApp);
                    xlApp = null;
                }
            }
        }&lt;/PRE&gt;</description>
      <pubDate>Sat, 17 Feb 2018 12:43:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7785706#M27295</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-02-17T12:43:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a calculation by a formula line the evaluate method in EXCEL VBA?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7785769#M27296</link>
      <description>&lt;P&gt;If you don't want to have a dependence on Excel (which is not guaranteed to be installed on every computer your code runs on), you can use any number of open-source libraries for &lt;A href="https://www.google.com/search?num=50&amp;amp;newwindow=1&amp;amp;ei=aDCIWvqeGuGP5wKauJiwDg&amp;amp;q=expression+evaluator+in+c%23&amp;amp;oq=expression+evaluator+in+c%23&amp;amp;gs_l=psy-ab.3..0l2j0i22i30k1l8.62128.66939.0.67219.9.8.0.1.1.0.149.789.0j6.6.0....0...1c.1.64.psy-ab..2.7.786...0i7i30k1j0i67k1j0i20i263k1.0.itzPZgWDNsU" target="_blank"&gt;expression parsing and evaluation&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1663708"&gt;@swaywood&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;Hi:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a string like '(1-2+3)/4*5^2', How to calculate the fomula by some exist dll or class?&lt;/P&gt;&lt;P&gt;I found excel vba's evaluate function can do this, but does not work for every computer, I don't know the reason.&lt;/P&gt;&lt;P&gt;If you know other dll has this method, please tell me , thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or you have other way to solve this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;summary&amp;gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;/// 利用Excel VBA Evaluate&lt;BR /&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;/summary&amp;gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;param name="str"&amp;gt;&amp;lt;/param&amp;gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;public static double Cal(this string str)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;string dllName = System.Reflection.Assembly.GetExecutingAssembly().Location.ToString();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;var app = new Excel.Application();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;FileInfo info = new FileInfo(dllName);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Excel.Workbook workbook = app.Workbooks.Add(info.Directory.FullName + "\\Cal.xlt");&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Excel.Worksheet worksheet = workbook.Worksheets.Add() as Excel.Worksheet;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;var result = worksheet.Evaluate(str);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;app.DisplayAlerts = false;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;app.Quit();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;double data = double.Parse(result.ToString());&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return data;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;}&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Feb 2018 13:53:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7785769#M27296</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2018-02-17T13:53:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a calculation by a formula line the evaluate method in EXCEL VBA?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7786394#M27297</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;dynamic can not be used in a framework 3.5 program?&lt;/P&gt;
&lt;P&gt;microsoft csharp.dll's framework is 4.0+?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Feb 2018 02:57:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7786394#M27297</guid>
      <dc:creator>swaywood</dc:creator>
      <dc:date>2018-02-18T02:57:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a calculation by a formula line the evaluate method in EXCEL VBA?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7786552#M27298</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1663708"&gt;@swaywood&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;dynamic can not be used in a framework 3.5 program?&lt;/P&gt;
&lt;P&gt;microsoft csharp.dll's framework is 4.0+?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes the dynamic type came with the .NET Framework 4.0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For prior Framework versions, to avoid referencing the COM libraries, you can use Late Binding with refelection.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        static object Calc(string expr)
        {
            bool wasOpen = false;
            object xlApp;
            try
            {
                xlApp = Marshal.GetActiveObject("Excel.Application");
                wasOpen = true;
            }
            catch
            {
                try { xlApp = Activator.CreateInstance(Type.GetTypeFromProgID("Excel.Application")); }
                catch { throw; }
            }
            object books = xlApp.GetType().InvokeMember("Workbooks", BindingFlags.GetProperty, null, xlApp, null);
            object book = books.GetType().InvokeMember("Add", BindingFlags.InvokeMethod, null, books, null);
            object sheet = book.GetType().InvokeMember("ActiveSheet", BindingFlags.GetProperty, null, book, null);
            try
            {
                object range = sheet.GetType().InvokeMember("Cells", BindingFlags.GetProperty, null, sheet, null);
                object cell = sheet.GetType().InvokeMember("Item", BindingFlags.GetProperty, null, range, new object[2] { 1, 1 });
                cell.GetType().InvokeMember("Value", BindingFlags.SetProperty, null, cell, new object[1] { "=" + expr });
                return (double)cell.GetType().InvokeMember("Value", BindingFlags.GetProperty, null, cell, null);
            }
            catch
            {
                return null;
            }
            finally
            {
                book.GetType().InvokeMember("Close", BindingFlags.InvokeMethod, null, book, new object[1] { false });
                book = null;
                if (!wasOpen)
                {
                    xlApp.GetType().InvokeMember("Quit", BindingFlags.InvokeMethod, null, xlApp, null);
                    Marshal.ReleaseComObject(xlApp);
                    xlApp = null;
                }
            }
        }&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The .NET Framework 3.5 brings extension methods.&lt;/P&gt;
&lt;P&gt;Using the following ones allows to avoid all the GetType().InvokeMember(...) stuff, and make the upper code more readable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;    public static class LateBindingextension
    {
        public static object Get(this object obj, string propName, params object[] parameter) =&amp;gt;
            obj.GetType().InvokeMember(propName, BindingFlags.GetProperty, null, obj, parameter);

        public static void Set(this object obj, string propName, params object[] parameter) =&amp;gt;
            obj.GetType().InvokeMember(propName, BindingFlags.SetProperty, null, obj, parameter);

        public static object Invoke(this object obj, string methName, params object[] parameter) =&amp;gt;
            obj.GetType().InvokeMember(methName, BindingFlags.InvokeMethod, null, obj, parameter);
    }&lt;/PRE&gt;
&lt;P&gt;The code becomes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        static object Calc(string expr)
        {
            bool wasOpen = false;
            object xlApp;
            try
            {
                xlApp = Marshal.GetActiveObject("Excel.Application");
                wasOpen = true;
            }
            catch
            {
                try { xlApp = Activator.CreateInstance(Type.GetTypeFromProgID("Excel.Application")); }
                catch { throw; }
            }
            object book = xlApp.Get("Workbooks").Invoke("Add");
            object sheet = book.Get("ActiveSheet");
            try
            {
                object cell = sheet.Get("Cells").Get("Item", 1, 1);
                cell.Set("Value", "=" + expr);
                return (double)cell.Get("Value");
            }
            catch
            {
                return null;
            }
            finally
            {
                book.Invoke("Close", false);
                book = null;
                if (!wasOpen)
                {
                    xlApp.Invoke("Quit");
                    Marshal.ReleaseComObject(xlApp);
                    xlApp = null;
                }
            }
        }&lt;/PRE&gt;</description>
      <pubDate>Sun, 18 Feb 2018 08:38:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7786552#M27298</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-02-18T08:38:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a calculation by a formula line the evaluate method in EXCEL VBA?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7787345#M27299</link>
      <description>&lt;P&gt;Above I write that you could use a third-party library to evaluate math expressions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Well, I'm not sure what I was thinking when I wrote that, but you don't need any third party library (or Excel) to do that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using System;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Internal.Calculator;


public static class CalcExample
{
   [CommandMethod("MYCALC")]
   public static void MyCalcCommand()
   {
      var doc = Application.DocumentManager.MdiActiveDocument;
      var ed = doc.Editor;
      var pso = new PromptStringOptions("\nExpression: ");
      pso.AllowSpaces = true;
      var psr = ed.GetString(pso);
      if(psr.Status == PromptStatus.OK)
      {
         try
         {
            var result = Evaluate(psr.StringResult);
            ed.WriteMessage("\nResult: {0}", result);
         }
         catch(System.Exception ex)
         {
            ed.WriteMessage(ex.Message);
         }
      }
   }


   public static double Evaluate(string expression)
   {
      if(string.IsNullOrWhiteSpace(expression))
         throw new ArgumentException(nameof(expression));
      CalcEngine engine = CalcEngine.GetEngine();
      CalcValueType valueType = new CalcValueType();
      valueType.Type = ValueTypeEnum.RealType;
      CalcResult calcResult = new CalcResult(valueType);
      if(engine.EvaluateExpression(expression, null, calcResult))
      {
         return calcResult.Result.R;
      }
      throw new ArgumentException("Failed to evaluate expression: " + expression);
   }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1663708"&gt;@swaywood&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;Hi:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a string like '(1-2+3)/4*5^2', How to calculate the fomula by some exist dll or class?&lt;/P&gt;&lt;P&gt;I found excel vba's evaluate function can do this, but does not work for every computer, I don't know the reason.&lt;/P&gt;&lt;P&gt;If you know other dll has this method, please tell me , thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or you have other way to solve this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;summary&amp;gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;/// 利用Excel VBA Evaluate&lt;BR /&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;/summary&amp;gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;param name="str"&amp;gt;&amp;lt;/param&amp;gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;public static double Cal(this string str)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;string dllName = System.Reflection.Assembly.GetExecutingAssembly().Location.ToString();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;var app = new Excel.Application();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;FileInfo info = new FileInfo(dllName);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Excel.Workbook workbook = app.Workbooks.Add(info.Directory.FullName + "\\Cal.xlt");&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Excel.Worksheet worksheet = workbook.Worksheets.Add() as Excel.Worksheet;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;var result = worksheet.Evaluate(str);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;app.DisplayAlerts = false;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;app.Quit();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;double data = double.Parse(result.ToString());&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return data;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;}&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Feb 2018 22:48:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7787345#M27299</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2018-02-18T22:48:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a calculation by a formula line the evaluate method in EXCEL VBA?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7787871#M27300</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4476837"&gt;@ActivistInvestor&lt;/a&gt; it seems to me CalcEngine is a &lt;A href="https://github.com/Bernardo-Castilho/CalcEngine" target="_blank"&gt;third party library&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, form AutoCAD, we can use the geomcal.crx to evaluate arithmetic expressions (see &lt;A href="https://knowledge.autodesk.com/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2016/ENU/AutoCAD-Core/files/GUID-B93BD7BF-B69D-40D4-968E-1EB60F90D93E-htm.html" target="_blank"&gt;&amp;gt;&amp;gt;here&amp;lt;&amp;lt; &lt;/A&gt;for expression reference)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        [CommandMethod("CALC")]
        public static void Calc()
        {
            var ed = Application.DocumentManager.MdiActiveDocument.Editor;
            var pso = new PromptStringOptions("\nEnter the expression: ");
            pso.AllowSpaces = true;
            var psr = ed.GetString(pso);
            if (psr.Status != PromptStatus.OK)
                return;
            var result = Evaluate(psr.StringResult);
            if (result == null)
                ed.WriteMessage("\nInvalid expression");
            else
                ed.WriteMessage($"\nResult: {result}");
        }

        public static object Evaluate (string expression)
        {
            var linker = SystemObjects.DynamicLinker;
            if (linker.GetLoadedModules().IndexOf("geomcal.crx") == -1)
                linker.LoadModule("geomcal.crx", false, true);
            var args = new ResultBuffer(
                new TypedValue((int)LispDataType.Text, "c:cal"),
                new TypedValue((int)LispDataType.Text, expression));
            var result = Application.Invoke(args);
            return result?.AsArray()[0].Value;
        }&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2018 08:01:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7787871#M27300</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-02-19T08:01:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a calculation by a formula line the evaluate method in EXCEL VBA?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7787960#M27301</link>
      <description>&lt;P&gt;ClearScript, Microsofts freeware product, is&amp;nbsp; my best of choice to add expressions to the C# program.&lt;/P&gt;
&lt;P&gt;You can add simple expressions, but&amp;nbsp; also add you're own Objects to use in calculations.&lt;/P&gt;
&lt;P&gt;This also adds C# functionality to PowerShell.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But it is supported from .NET 4.0 onwards&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See below for a few MS samples.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://microsoft.github.io/ClearScript/Tutorial/FAQtorial.html" target="_blank"&gt;https://microsoft.github.io/ClearScript/Tutorial/FAQtorial.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And my ow usage&lt;/P&gt;
&lt;PRE&gt;using Microsoft.ClearScript.Windows;
...

using (var vbScript = new VBScriptEngine())
{
var result = vbScript.Evaluate("(1-2+3)/4*5^2");

//ClearScript(VBScript) does not support IIF, therefore we supply this as a function
vbScript.Execute("Function IIf(bClause, sTrue, sFalse)\n If CBool(bClause) Then\n IIf = sTrue\n Else\n IIf = sFalse\n End If\n End Function");
 
vbScript.AddHostObject("propVals", requiredPropertyValues);
// now we can evaluate 'user formulars' like 
//  Custom.Gemeente=discTek.Gemeente | planDoc.Custom.Plaats + iif(len(planDoc.Custom.Gemeente) &amp;gt; 0," gem. " &amp;amp; planDoc.Custom.Gemeente,"")

...
&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2018 08:49:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7787960#M27301</guid>
      <dc:creator>SENL1362</dc:creator>
      <dc:date>2018-02-19T08:49:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a calculation by a formula line the evaluate method in EXCEL VBA?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7787972#M27302</link>
      <description>&lt;P&gt;With the geomcal, it would be more efficient to move the loading part to a static constructor or to the IExtensionApplication.Initialize() method.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2018 08:52:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7787972#M27302</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-02-19T08:52:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a calculation by a formula line the evaluate method in EXCEL VBA?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7788212#M27303</link>
      <description>&lt;PRE&gt;using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;

[assembly: CommandClass(typeof(AutoCAD2014Plugin.Commands))]

namespace AutoCAD2014Plugin
{
    public class Commands
    {
        static Commands()
        {
            SystemObjects.DynamicLinker.LoadModule("geomcal.crx", false, true);
        }

        [CommandMethod("CALC")]
        public static void Calc()
        {
            var ed = Application.DocumentManager.MdiActiveDocument.Editor;
            var pso = new PromptStringOptions("\nEnter the expression: ");
            pso.AllowSpaces = true;
            var psr = ed.GetString(pso);
            if (psr.Status != PromptStatus.OK)
                return;
            var result = TryEvaluate(psr.StringResult);
            if (result.HasValue)
                ed.WriteMessage($"\nType: {(LispDataType)result.Value.TypeCode} Value: {result.Value.Value}");
            else
                ed.WriteMessage("\nInvalid expression");
        }

        public static TypedValue? TryEvaluate(string expression) =&amp;gt;
            Application.Invoke(new ResultBuffer(
                new TypedValue((int)LispDataType.Text, "c:cal"),
                new TypedValue((int)LispDataType.Text, expression)))?.AsArray()[0];
    }
}
&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Feb 2018 11:02:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7788212#M27303</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-02-19T11:02:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a calculation by a formula line the evaluate method in EXCEL VBA?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7788370#M27304</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4476837"&gt;@ActivistInvestor&lt;/a&gt; it seems to me CalcEngine is a &lt;A href="https://github.com/Bernardo-Castilho/CalcEngine" target="_blank"&gt;third party library&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;, It seems to me that you're mistaken.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CalcEngine is what the Calculator UI and other components (like Data Extraction) depend on to access geomcal.arx.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It also implicitly loads geomcal.arx on first use.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="calcengine.png" style="width: 399px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/464686i3A533A619CE8691B/image-size/large?v=v2&amp;amp;px=999" role="button" title="calcengine.png" alt="calcengine.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2018 12:06:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7788370#M27304</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2018-02-19T12:06:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a calculation by a formula line the evaluate method in EXCEL VBA?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7788406#M27305</link>
      <description>&lt;P&gt;ClearScript is an embedded scripting engine, not a mathematical expression engine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Math expression engines don't support things like conditional branching, control flow/looping, etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It would be a bit of overkill for simply evaluating math expressions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/846050"&gt;@SENL1362&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;ClearScript, Microsofts freeware product, is&amp;nbsp; my best of choice to add expressions to the C# program.&lt;/P&gt;&lt;P&gt;You can add simple expressions, but&amp;nbsp; also add you're own Objects to use in calculations.&lt;/P&gt;&lt;P&gt;This also adds C# functionality to PowerShell.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But it is supported from .NET 4.0 onwards&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;See below for a few MS samples.&lt;/P&gt;&lt;P&gt;&lt;A href="https://microsoft.github.io/ClearScript/Tutorial/FAQtorial.html" target="_blank"&gt;https://microsoft.github.io/ClearScript/Tutorial/FAQtorial.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And my ow usage&lt;/P&gt;&lt;PRE&gt;using Microsoft.ClearScript.Windows;
...

using (var vbScript = new VBScriptEngine())
{
var result = vbScript.Evaluate("(1-2+3)/4*5^2");

//ClearScript(VBScript) does not support IIF, therefore we supply this as a function
vbScript.Execute("Function IIf(bClause, sTrue, sFalse)\n If CBool(bClause) Then\n IIf = sTrue\n Else\n IIf = sFalse\n End If\n End Function");
 
vbScript.AddHostObject("propVals", requiredPropertyValues);
// now we can evaluate 'user formulars' like 
//  Custom.Gemeente=discTek.Gemeente | planDoc.Custom.Plaats + iif(len(planDoc.Custom.Gemeente) &amp;gt; 0," gem. " &amp;amp; planDoc.Custom.Gemeente,"")

...
&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2018 12:27:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7788406#M27305</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2018-02-19T12:27:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a calculation by a formula line the evaluate method in EXCEL VBA?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7788414#M27306</link>
      <description>&lt;P&gt;Sorry my mistake, i didn't see the Autodesk.AutoCAD.Internal.Calculator using directive.&lt;img id="smileyembarrassed" class="emoticon emoticon-smileyembarrassed" src="https://forums.autodesk.com/i/smilies/16x16_smiley-embarrassed.png" alt="Smiley Embarassed" title="Smiley Embarassed" /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2018 12:23:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7788414#M27306</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-02-19T12:23:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a calculation by a formula line the evaluate method in EXCEL VBA?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7788426#M27307</link>
      <description>&lt;P&gt;LOL, and then use Excel for simple arithmetrics.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You're absolutely right when only used for simple calculations, but in my experiences it didn't stop with that.&lt;/P&gt;
&lt;P&gt;Sometimes the values aren't just numberes any more, but Legenda properties etc.&lt;/P&gt;
&lt;P&gt;To support that i needed tools like grep, awk etc. Furtunately MS developed ClearScript for short dynamic expressions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For more lengtly operations, like a bunch of convertion rules to apply on drawings, i convert the rules to c#, compile and run these progs. Al in just factions of seconds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2018 12:30:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7788426#M27307</guid>
      <dc:creator>SENL1362</dc:creator>
      <dc:date>2018-02-19T12:30:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a calculation by a formula line the evaluate method in EXCEL VBA?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7788470#M27308</link>
      <description>&lt;P&gt;Using Excel for evaluating simple math expressions is definitely overkill, and probably the worst-possible way to solve that problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the OP needs only to evaluate math expressions, AutoCAD has that ability without having to depend on additional libraries. AutoCAD's calculator engine also supports vector math, which ClearScript and most other general-purpose math expression engines don't support.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2018 12:47:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7788470#M27308</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2018-02-19T12:47:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a calculation by a formula line the evaluate method in EXCEL VBA?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7790323#M27309</link>
      <description>&lt;P&gt;I neglected to mention that In the example code I posted above, angles are expressed&amp;nbsp;as &lt;EM&gt;degrees&lt;/EM&gt; rather than radians. The CAL command&amp;nbsp;and&amp;nbsp;the (cal) LISP function also express angles in degrees, and I'm not sure there's any way to change that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But since that's considered non-standard for math expressions in general (e.g, System.Math, LISP, C/C++, etc.), the following revision of the Evaluate() method from the above code will interpret and return angles&amp;nbsp;as&amp;nbsp;&lt;EM&gt;radians&lt;/EM&gt; rather than degrees. So, while the CAL command or (cal) lisp function returns 45.0 for the expression 'atan(1.0)', the revised Evaluate() method shown below will return pi/4.0:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;public static double Evaluate(string expression)
{
   if(string.IsNullOrWhiteSpace(expression))
      throw new ArgumentException(nameof(expression));
   CalcEngine engine = CalcEngine.GetEngine();
   CalcValueType valueType = new CalcValueType();
   valueType.Type = ValueTypeEnum.RealType;
   CalcResult calcResult = new CalcResult(valueType);
   &lt;STRONG&gt;CalcContext context = new CalcContext();&lt;/STRONG&gt;
   &lt;STRONG&gt;context.AngleUnits = AngleUnitsEnum.Radian;&lt;/STRONG&gt;
   if(engine.EvaluateExpression(expression, &lt;STRONG&gt;context&lt;/STRONG&gt;, calcResult))
   {
      return calcResult.Result.R;
   }
   throw new ArgumentException("Failed to evaluate expression: " + expression);
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Feb 2018 01:25:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7790323#M27309</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2018-02-20T01:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a calculation by a formula line the evaluate method in EXCEL VBA?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7803088#M27310</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4476837"&gt;@ActivistInvestor&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much.&lt;/P&gt;
&lt;P&gt;Do you have more help doc of CalcEngine?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't know how to write the 'string expression'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my case i will use '+,-,*,/,^(Power),Sqrt,Sqr,(),Pi'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;best wishes&lt;/P&gt;
&lt;P&gt;swaywood&lt;/P&gt;</description>
      <pubDate>Fri, 23 Feb 2018 14:03:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7803088#M27310</guid>
      <dc:creator>swaywood</dc:creator>
      <dc:date>2018-02-23T14:03:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a calculation by a formula line the evaluate method in EXCEL VBA?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7804134#M27311</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1663708"&gt;@swaywood&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4476837"&gt;@ActivistInvestor&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much.&lt;/P&gt;&lt;P&gt;Do you have more help doc of CalcEngine?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't know how to write the 'string expression'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my case i will use '+,-,*,/,^(Power),Sqrt,Sqr,(),Pi'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;best wishes&lt;/P&gt;&lt;P&gt;swaywood&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;The CalcEngine is what evaluates expressions for AutoCAD's calculator (CAL and QUICKCALC Commands).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can see the &lt;A href="http://help.autodesk.com/view/ACD/2018/ENU/?guid=GUID-B93BD7BF-B69D-40D4-968E-1EB60F90D93E" target="_blank"&gt;docs for the calculator&lt;/A&gt; for the expression syntax, and keep in mind that the second version of the code I posted above uses &lt;STRONG&gt;&lt;EM&gt;radians&lt;/EM&gt; &lt;/STRONG&gt;rather than degrees (as the CAL and QUICKCALC command use).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With the second version of the Evaluate() method posted above,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;These functions use radians in their argument:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1" cellspacing="0" cellpadding="4"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P class="p"&gt;sin(&lt;EM&gt;angle&lt;/EM&gt;)&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P class="p"&gt;cos(&lt;EM&gt;angle&lt;/EM&gt;)&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P class="p"&gt;tang(&lt;EM&gt;angle&lt;/EM&gt;)&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And, these functions return an angle in radians:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1" cellspacing="0" cellpadding="4"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P class="p"&gt;asin(&lt;EM&gt;real&lt;/EM&gt;)&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P class="p"&gt;acos(&lt;EM&gt;real&lt;/EM&gt;)&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P class="p"&gt;atan(&lt;EM&gt;real&lt;/EM&gt;)&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is also another major difference between the CalcEngine and the (C:CAL) and (cal) LISP functions, which is in how integers are handled.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using the (CAL) (or C:CAL) lisp function:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Command: (cal "50000+12000")
-3536&lt;/PRE&gt;&lt;P&gt;Using the CAL command:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Command: CAL
&amp;gt;&amp;gt; Expression: 50000+12000
62000&lt;/PRE&gt;&lt;P&gt;Using the MYCALC command from the example posted above:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Command: MYCALC
Expression: 50000+12000
Result: 62000&lt;/PRE&gt;&lt;P&gt;Well, I guess they forgot to mention that. 8)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Feb 2018 19:27:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-do-a-calculation-by-a-formula-line-the-evaluate-method-in/m-p/7804134#M27311</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2018-02-23T19:27:43Z</dc:date>
    </item>
  </channel>
</rss>

