Author Topic: LISP runs Fine Unless It's Called By .NET  (Read 1938 times)

0 Members and 1 Guest are viewing this topic.

Bill Tillman

  • Guest
LISP runs Fine Unless It's Called By .NET
« on: August 12, 2015, 11:30:10 AM »
I'm trying to track this bug and thought I'd ask the crew if anyone else has ever seen this kind of thing. I have a LISP program which creates a drawing. It's been running fine for years. I have recently added a C#.NET project which launches AutoCAD then loads and runs this LISP. It seems to work find but this morning I'm running into a problem. The drawing starts getting created but suddenly stops. If I click the mouse, it picks up again. But that's no good because this is supposed to be a totally automated process with no user input allowed.

So I open AutoCAD, set up the variables needed and watch the LISP run. It runs perfect, all the way through. So I then try the C# program on it and again it pauses at this same spot. I've tracked down in the LISP code where it's pausing but I don't see anything like an extra "" which has cause a similar problem in the past.

BillZndl

  • Guest
Re: LISP runs Fine Unless It's Called By .NET
« Reply #1 on: August 12, 2015, 11:40:10 AM »
Not sure if I'll be of any help but I've been loading and firing numerous lisp files for some time using a modeless form with button clicks and have not had any trouble.
Code - C#: [Select]
  1. public static void MakeDirectory()
  2.         {
  3.             Document doc = AcadApp.DocumentManager.MdiActiveDocument;
  4.             Database db = doc.Database;
  5.             doc.SendStringToExecute("(load \"make_d2\") (make_d2) ", true, false, true);
  6.         }
  7.  

Bill Tillman

  • Guest
Re: LISP runs Fine Unless It's Called By .NET
« Reply #2 on: August 12, 2015, 01:14:35 PM »
That's something I double checked. It does not appear to be in the launch of AutoCAD or the SendCommands I pass to it. It's well into the execution of the lisp that AutoCAD just stops drawing. And by "stop" I mean it makes no more lines on the model space window until I click the mouse. Then it picks up again. I've tested this setup with other LISP and it works well. This one is just kind of stumping me because I can't pin down what in the LISP code makes it stop only when .NET get's involved. But just in case, here is how AutoCAD is called from the class in C#. My first thought was there was an extra space in the SendCommands, but I've double checked that. I'm thinking there must be an extra "" somewhere in the LISP code, but it's hiding very stealth-fully if that's what it is.

Code: [Select]
    class LaunchAutoCAD
    {
        private static IAcadApplication vAcadApp = null;
        private static IAcadDocument vAcadDoc = null;       
        private static string vAcadID = "AutoCAD.Application.20";

        public static void StartAutoCAD()
        {
            try
            {
                // Check for instance of AutoCAD
                vAcadApp = (IAcadApplication)System.Runtime.InteropServices.Marshal.GetActiveObject(vAcadID);
            }
            catch (Exception) // None found so start a new instance of AutoCAD
            {
                Type AcadProg = Type.GetTypeFromProgID(vAcadID);
                vAcadApp = (IAcadApplication)System.Activator.CreateInstance(AcadProg);
            }

            if (vAcadApp != null)
            {
                vAcadApp.Visible = true;
                vAcadDoc = vAcadApp.Documents.Open(myDrawingTemplate.dwg", true);
                vAcadDoc.SendCommand("(load \"" + LispPath + "myLisp.lsp\" \"The load failed\") ");
                vAcadDoc.SendCommand(LISPVariables.PrepareAcadCmd() + " ");
                vAcadDoc.SendCommand("(setq svPath \"" + (ReadDefaults.vsSaveAutoDwgPath).Replace("\\", "/") + "\") ");
                vAcadDoc.SendCommand("(setq *erp 1) ");
                vAcadDoc.SendCommand("startLisp ");
            }
            else
            {
                Console.WriteLine("ERROR: The drawing file is missing.");
            }
        }
    }
}