.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

AutoCAD 2013 + AccoreConsole + acadEvaluateLisp

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
odurier
2082 Views, 8 Replies

AutoCAD 2013 + AccoreConsole + acadEvaluateLisp

Hello,

I feel that 'acedEvaluateLisp' does not work when used in console mode

Do you have a solution.?

 

Script:

 

(command "netload" "d:/dev/test/bin/debug/test.dll")
cmdtest
(eval a)
(princ "\nFin du traitement")

 


Sample Test.dll:

 

///

 

using System;
using System.Collections.Generic;
using System.Windows.Forms;

using System.Text;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Windows;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Interop;  



namespace Test
{
    
    /// <summary>
    /// Classe générale des outils AutoCAD
    /// </summary>
    public class Test : IExtensionApplication
    {
 
        /// <summary>
        /// Init
        /// </summary>
        /// <returns></returns>
        public void Initialize()
        {
            try
            {
            }
            catch (System.Exception ex)
            {
                //LaMethodeDeLog(this.GetType(), System.Reflection.MethodBase.GetCurrentMethod().Name, ex);

                MessageBox.Show(ex.Message);

            }
            finally
            {

            }
        }

        /// <summary>
        /// Init
        /// </summary>
        /// <returns></returns>
        public void Terminate()
        {
            try
            {
            }
            catch (System.Exception ex)
            {
                
            }
            finally
            {

            }
        }
        /// <summary>
        /// Gabarit Commande AutoCAD
        /// </summary>
        /// <returns></returns>
        [Autodesk.AutoCAD.Runtime.CommandMethod("testapp", "cmdtest", Autodesk.AutoCAD.Runtime.CommandFlags.Transparent)]
        public void cmdtest()
        {
            try
            {
                string Strlisp = "(setq a 10)";

                ResultBuffer res = AcadEvalLisp(Strlisp);

                

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
            }
        }

   


        #region Fonction externe AcedInvoke
        // Type of resbuf element
        const int RTNONE = 5000; /* No result */
        const int RTREAL = 5001; /* Real number */
        const int RTPOINT = 5002; /* 2D point X and Y only */
        const int RTSHORT = 5003; /* Short integer */
        const int RTANG = 5004; /* Angle */
        const int RTSTR = 5005; /* String */
        const int RTENAME = 5006; /* Entity name */
        const int RTPICKS = 5007; /* Pick set */
        const int RTORINT = 5008; /* Orientation */
        const int RT3DPOINT = 5009; /* 3D point - X, Y, and Z */
        const int RTLONG = 5010; /* Long integer */
        const int RTVOID = 5014; /* Blank symbol */
        const int RTLB = 5016; /* list begin */
        const int RTLE = 5017; /* list end */
        const int RTDOTE = 5018; /* dotted pair */
        const int RTNIL = 5019; /* nil */
        const int RTDXF0 = 5020; /* DXF code 0 for ads_buildlist only */
        const int RTT = 5021; /* T atom */
        const int RTRESBUF = 5023; /* resbuf */
        const int RTMODELESS = 5027; /* interrupted by modeless dialog */

        // Error return code
        const int RTNORM = 5100; /* Request succeeded */
        const int RTERROR = -5001; // Some other error
        const int RTCAN = -5002; // User cancelled request -- Ctl-C
        const int RTREJ = -5003; // AutoCAD rejected request -- invalid
        const int RTFAIL = -5004; // Link failure -- Lisp probably died
        const int RTKWORD = -5005; // Keyword returned from getxxx() routine
        const int RTINPUTTRUNCATED = -5008; // Input didn't all fit in the buffer



        [System.Security.SuppressUnmanagedCodeSecurity]
        [DllImport("accore.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl, EntryPoint = "?acedEvaluateLisp@@YAHPEB_WAEAPEAUresbuf@@@Z")]
        extern public static int acedEvaluateLisp(string lispLine, out IntPtr result);


 

        /// <summary>
        /// Evalue une fonction Lisp
        /// </summary>
        /// <param name="arg">string: Argument de la fonction</param>   
        /// <returns>ResultBuffer : resultat de buffer</returns>
        static public ResultBuffer AcadEvalLisp(string arg)
        {

            IntPtr rb = IntPtr.Zero;

            acedEvaluateLisp(arg, out rb);


            if (rb != IntPtr.Zero)
            {
                try
                {

                    ResultBuffer rbb = DisposableWrapper.Create(typeof(ResultBuffer), rb, true) as ResultBuffer;
                    return rbb;
                }
                catch
                {
                    return null;
                }
            }
            return null;

        }

       



        #endregion
    }
}

 

///

8 REPLIES 8
Message 2 of 9
Balaji_Ram
in reply to: odurier

Hi Olivier,

 

Sorry for the delay.

 

I am working on it and will get back to you soon based on what I find.

 



Balaji
Developer Technical Services
Autodesk Developer Network

Message 3 of 9
Balaji_Ram
in reply to: odurier

Hi Olivier,

 

I did reproduce the behavior both with a .Net and CRX module loaded from the script file.

There is no issue with the DllImport being used with AccoreConsole and that works. So I suppose the issue is with the acedEvaluateLisp method.

 

I have brought this to the notice of our engineering team.

So far I havent found any way to make this work but will let you know if I hear any other way to overcome it.

 



Balaji
Developer Technical Services
Autodesk Developer Network

Message 4 of 9
odurier
in reply to: Balaji_Ram

Hi Balaji_Ram

Thank you for your help.
I hope a developer will find a solution.

The console is an excellent product development. There only point that stops me in its implementation.

Good day.

Message 5 of 9
Alfred.NESWADBA
in reply to: odurier

Hi,

 

not that beautiful, but maybe a workaround: have you tried if the COM access to the VL.APPLICATION functionality is working?

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 6 of 9
odurier
in reply to: Alfred.NESWADBA

Hi

No, because my problem is as follows:
My application:
Load custom client lisp and check if the lisp is loaded correctly (synchronous)
Execute functions in this lisp and get the result in my application (synchronous)

I'm not sure I can do that with VL.APPLICATION

Message 7 of 9
Balaji_Ram
in reply to: odurier

Hi Olivier,

 

I heard back from our engineering team and the key to make this work is to invoke the command directly in your script file by using its name and not to invoke it using "(command <command name>)".

 

I tested this and it worked ok.

 

To try the attached files,

 

1) Unzip the attached files to "C:\Temp"

2) Build the .Net dll

3) Run the "RunAccore.bat"

 

The resbuf from the evaluated Lisp expression has the correct values.

Hope this helps.

 

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

Message 8 of 9
odurier
in reply to: Balaji_Ram

hi,

It works.
I had 2 problems

1) in the example the (eval) method does not work then (princ) gives me the result of the call lisp
2) in my project, I would not load properly my lisp file

Sorry for the time spent on my problem which was not one.

Autodesk thank you for your help

Message 9 of 9
mdhutchinson
in reply to: odurier

I looked at this core console. it seems lisp files will not load correctly into core console. in a way that will allow them to run when called from the console command prompt.  I thought I was doing something wrong... ?  is this a core limitation with no work a round?...or is this what your acadEvaluateLisp is for?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost