.NET

Reply
Contributor
odurier
Posts: 21
Registered: ‎06-16-2008
Message 1 of 9 (971 Views)
Accepted Solution

AutoCAD 2013 + AccoreConsole + acadEvaluateLisp

971 Views, 8 Replies
11-12-2012 04:53 AM

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
    }
}

 

///

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.

 

 

 

ADN Support Specialist
Balaji_Ram
Posts: 733
Registered: ‎03-21-2011
Message 2 of 9 (900 Views)

Re: AutoCAD 2013 + AccoreConsole + acadEvaluateLisp

11-20-2012 04:52 AM 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

ADN Support Specialist
Balaji_Ram
Posts: 733
Registered: ‎03-21-2011
Message 3 of 9 (880 Views)

Re: AutoCAD 2013 + AccoreConsole + acadEvaluateLisp

11-21-2012 03:05 AM 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

Contributor
odurier
Posts: 21
Registered: ‎06-16-2008
Message 4 of 9 (869 Views)

Re: AutoCAD 2013 + AccoreConsole + acadEvaluateLisp

11-21-2012 05:09 AM 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.

*Expert Elite*
Alfred.NESWADBA
Posts: 9,396
Registered: ‎06-29-2007
Message 5 of 9 (866 Views)

Re: AutoCAD 2013 + AccoreConsole + acadEvaluateLisp

11-21-2012 05:47 AM 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
-------------------------------------------------------------------------
Contributor
odurier
Posts: 21
Registered: ‎06-16-2008
Message 6 of 9 (860 Views)

Re: AutoCAD 2013 + AccoreConsole + acadEvaluateLisp

11-21-2012 06:40 AM 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

ADN Support Specialist
Balaji_Ram
Posts: 733
Registered: ‎03-21-2011
Message 7 of 9 (822 Views)

Re: AutoCAD 2013 + AccoreConsole + acadEvaluateLisp

11-25-2012 08:15 AM 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

Contributor
odurier
Posts: 21
Registered: ‎06-16-2008
Message 8 of 9 (761 Views)

Re: AutoCAD 2013 + AccoreConsole + acadEvaluateLisp

11-28-2012 11:41 PM 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

Valued Mentor
mdhutchinson
Posts: 2,317
Registered: ‎11-18-2003
Message 9 of 9 (600 Views)

Re: AutoCAD 2013 + AccoreConsole + acadEvaluateLisp

03-04-2013 08:03 PM 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?

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!