0

I'm currently in the process of rewriting some old AutoCAD plugins from VBA to VB.NET. As it turns out, a (rather large) part of said plugin is implemented in LISP, and I've been told to leave that be. So the problem became running LISP-code in AutoCAD from .NET. Now, there are a few resources online who explain the process necessary to do so (like this one), but all of them takes for granted that the lisp-files/functions are already loaded. The VBA-function I'm currently scratching my head trying to figure out how to convert does a "(LOAD ""<file>"")", and the script is built in such a way that it auto-executes on load (it's a simple script, doesn't register functions, just runs from start to end and does it's thing).

So my question is. How can I load (and thus execute) a lisp-file in autocad from a .NET plugin?

Alxandr
  • 12,345
  • 10
  • 59
  • 95
  • Try `Autodesk.AutoCAD.Internal.AcadTaskDialogs.AutoLISPLoadSettings` And `Autodesk.AutoCAD.Internal.Utils.RegisterLispCommand(string, string)` – Daniel Möller Jul 03 '13 at 20:02
  • There's something I really can't understand about your question. Does your VBA code call the lisp files??? If so, are the lisp files already loaded? If so, they will be already loaded with .NET as well. If not, does the VBA load the lisp files??? If it does, please post the VBA lines that does so. – Daniel Möller Jul 03 '13 at 20:05
  • It would be easier if I can understand what loads what in your old plugins. – Daniel Möller Jul 03 '13 at 20:07
  • @Daniel I did post it (more or less at least). The VBA script loads (and executes) the lisp-script by issuing `ThisDrawing.SendCommand("(LOAD """")")`. – Alxandr Jul 04 '13 at 05:22
  • Ok...now, when you say script "auto-executes", you mean, when autocad is open? Or when a document is open? Or do you mean the lisp script executes itself when the vba calls load? – Daniel Möller Jul 07 '13 at 21:33
  • Does the vba code auto-execute?? Or it's the lisp that autoexecute? – Daniel Möller Jul 07 '13 at 21:34

1 Answers1

1

Ok, there are two ways to sendcommand via .NET.

The first thing you need to understand is that ThisDocument doesn't exist in .NET. ThisDocument is the document where the VBA code is written, but since your addin is document undependant, it stands alone and you must take the documents from the Application object.

You access the application with:

Autodesk.AutoCAD.ApplicationServices.Application

If you want to transform it to the same Application object as in VBA, with same methods and functions

using Autodesk.Autocad.Interop;
using Autodesk.Autocad.Interop.Common;

AcadApplication App = (AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;

The first application has MdiActiveDocument, from where you can call the Editor and send written commands, or call the SendStringToExecute as said in other answer.

The AcadApplication has ActiveDocument (an AcadDocument object that behaves exactly as in VBA). This document will have the same SendCommand your VBA has, use it the same way it's done in VBA.

If you can explain better the autoexecute part, I can help with that too.

Daniel Möller
  • 84,878
  • 18
  • 192
  • 214
  • Ah, it seems I left out an important part of the question. The problem is that after the lisp-code has executed, I need to continue running .NET-code. I "solved" it though (not a pretty solution), by creating a `` that acts as a callback and running `SendStringToExecute` with the string `(load )\r(myCallbackFunc)`. – Alxandr Jul 08 '13 at 07:04
  • Though as your answer actually answers the question, I'm marking it as resolved. – Alxandr Jul 08 '13 at 07:04