Stop lisp execution with modeless form close button

Started by Jim Short, April 25, 2015, 05:09:44 PM

Previous topic - Next topic

Jim Short

I have an animation running in a lisp expression. The expression tests a variable that stops execution when a button is pressed on a modeless dialog displayed during the animation.
;;cancel
(defun c:TahlCAM/RunSpeed/btClose#OnClicked   ()
  (setq >animate nil)
  (if (DCL_Form_IsActive TahlCAM/RunSpeed)
      (DCL_Form_Close TahlCAM/RunSpeed)
  )
)

This works as expected in Acad2004 but does not respond in Acad2010.
Can anyone suggest a solution?
To my knowledge there is only a difference in acad version and arx version.
Jim Short

owenwengerd

What exactly do you mean by "does not respond"? Is it because DCL_Form_IsActive is not returning what you expect?

Jim Short

The modeless form's titlebar has focus but is totally unresponsive to the mouse while routine is executing.

If the callback was being evaluated  (setq >animate nil) would occur.
This stops the animation and the routine continues the execution without it.

The OncCicked event works properly except when inside the lisp routine.
Acad2015 and Bricscadv15 both exhibit this behavior. Acad2004 works properly.
Jim Short

owenwengerd

Ok, I'm assuming that by "lisp animation" you mean a loop of some sort, correct? if so, then there needs to be something inside the loop that gives Windows a chance to process messages. There's no way to guess without seeing the code why it might be different in R2004, but you should probably put something inside the loop explicitly for giving AutoCAD a chance to catch up with input events while the loop runs. Maybe something as simple as (princ) or (grtext) would work.

Jim Short

I tried (princ) and (grtext). Only after pressing escape did the routine break. It broke near the (princ) which said you were on the right track. One additional detail. Bricscad crashes if I try to close without first closing the modeless form on left on the display.
Jim Short

owenwengerd

There might be undesirable command line side effects, but your animation would be much more efficient if you use the event to update your animation instead of running it in a loop.

Jim Short

Owen,
I played with the OnTimer and found that it waited till my routine was done. I am glad to find out you added that event.

I have been thinking of what you said about getting my routine out of the big loop for some time now.
Thanks for all your efforts.
Jim
Jim Short

owenwengerd

You're welcome, Jim. If OnTimer didn't work, then it sounds like you've still got something running in a loop that doesn't yield to allow message processing. The reason for using OnTimer is to eliminate the loop altogether.