Author Topic: Doing heavy computation in lisp without autocad freezing up  (Read 2278 times)

0 Members and 1 Guest are viewing this topic.

SIDESHOWBOB

  • Guest
Are there recommendations for how (if ever) to handle the autocad interface while something computationally heavy goes on in lisp?

As you might guess from my other posts the heavy work is being done in C++, called from lisp, but that doesn't change things greatly.  Ideally I'd like autocad to not freeze up, and to be able to indicate progress to the user as the task progresses.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Doing heavy computation in lisp without autocad freezing up
« Reply #1 on: June 22, 2012, 08:28:25 AM »
Are there recommendations for how (if ever) to handle the autocad interface while something computationally heavy goes on in lisp?

AFAIK, this is a result of how LISP is implemented in AutoCAD and hence cannot be avoided...

Previous discussions:

http://www.theswamp.org/index.php?topic=41771.0
http://www.theswamp.org/index.php?topic=39931.0

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Doing heavy computation in lisp without autocad freezing up
« Reply #2 on: June 22, 2012, 10:16:43 AM »
You mention that the "heavy work" is being done in C++. Why don't you rewrite your C++ to be threaded in the background? That way the lisp could call the C++ defun'ed function. It would then start the thread to do the calculation(s) and return to lisp. The thread can then have a call to acedInvoke to tell lisp that the calculation is complete and send it the result(s). The defun in lisp needs to be sent to vl-acad-defun though so it can be invoked from the C++ side. I know it's a lot of work to create some threaded class simply for a calculation, but that's what you get from C++ (it's the most common of the closest "3rd" generation language to being a "2nd" generation Assembly Language).

You might even design your calculating thread to send a % complete every now and again. Thus either using lisp to display the status, or directly in C++ modify the progressbar. You'd probably need to use some form of event function in your threaded class for this.

Yet something else where ADesk cause their customers hassles by not upgrading AutoLisp to any one of the Common Lisp interpreters/compilers - all of them have threading built in - a lot less work than doing it in C++.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

SIDESHOWBOB

  • Guest
Re: Doing heavy computation in lisp without autocad freezing up
« Reply #3 on: June 22, 2012, 10:30:53 AM »
AFAICT acedInvoke means delving into ARX which means my code becomes dependent on the autocad version.  If I was happy to go version-dependent I might as well rewrite the whole interface in VB or C#, which would be much easier and also achieve what you suggest right?

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Doing heavy computation in lisp without autocad freezing up
« Reply #4 on: June 22, 2012, 11:16:53 AM »
Exactly! You mean your C++ code is called from Lisp through ActiveX?

Well you could use the SendCommand to send a string representing the call to the lisp function to AutoCAD. Or you could try delving into "VL.Application.16"'s undocumented properties/methods (just remember to load it by calling vl-load-com first, though you probably already have  :ugly: ).

For some more samples, see post #15 here: http://www.theswamp.org/index.php?topic=20519.0


Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

SIDESHOWBOB

  • Guest
Re: Doing heavy computation in lisp without autocad freezing up
« Reply #5 on: June 22, 2012, 11:38:04 AM »
Yes, I do.  I have had trouble with SendCommand before, it hasn't always done what I wanted, least of all synchronously.  Thanks but I think in the long run we'll rewrite in VB or something - currently the only nice thing about lisp is it's not autocad version dependent.

BlackBox

  • King Gator
  • Posts: 3770
Re: Doing heavy computation in lisp without autocad freezing up
« Reply #6 on: June 22, 2012, 12:43:18 PM »
FWIW -

If you do end up rewriting your application in C#/VB.NET, then test for the oldest version of .NET Framework that will allow your application to fully function, and compile to that Framework version in an effort to support as much compatibility as possible with future versions.

As I understand it, even in 2013 (.NET 4.0) they've made some Extension Methods that are intended to allow calls to specific Classes that have been moved to another Namespace to still be viable (allegedly precluding unnecessary application refactoring). I'm still very much a noob, so take from this what you will.
"How we think determines what we do, and what we do determines what we get."

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Doing heavy computation in lisp without autocad freezing up
« Reply #7 on: June 22, 2012, 02:00:12 PM »
...currently the only nice thing about lisp is it's not autocad version dependent.
+1, though I'd change the word Lisp to AutoLisp / VisualLisp. Other implementations of lisp is actually quite powerful & after compiling to bitcode or even native machine code their speed of execution is comparable to the C/C++ binaries you generally find.

Why ADesk doesn't try to make some sort of consistent plugin library across versions is beyond comprehension. I mean, it actually takes them a lot of programming to "reinvent the SDK" every 2-3 versions doesn't it? Probably a situation of making more money this way by forcing everyone to upgrade on an annual iteration - probably also obtaining some royalties from M$ because every now and again the VS verions of all the 3rd party programmers need to upgrade those as well!
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.