Author Topic: LISP sometimes not possible to kill with ESC...  (Read 911 times)

0 Members and 1 Guest are viewing this topic.

ribarm

  • Water Moccasin
  • Posts: 2334
  • Marko Ribar, architect
LISP sometimes not possible to kill with ESC...
« on: May 04, 2020, 10:43:57 AM »
I have this question from title...
Very often in order to perform fast execution I don't open VLIDE and therefore, sometimes with ESC CAD can't be interuppted to break routine - my screen goes white - pale and I must terminate CAD... I want to set routine in the way it never comes to this... For example I have very extensive calculations to perform that will take very long time... So patial calculations can be stored in some global variable cumulative while routine works, but then I want to break it with ESC... If screen goes white, I have 2 options either to wait to finish and other one to close CAD... Both of these options are bad for me... I want ESC - BREAK, QUIT, EXIT routine and CAD remains active with my global variable with data stored all the way until ESC...
Is this possible with some kind of special error handler or something I don't know yet...
Thanks for reading, M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

MP

  • Seagull
  • Posts: 17630
Re: LISP sometimes not possible to kill with ESC...
« Reply #1 on: May 04, 2020, 11:03:22 AM »
Visual BASIC sports the DoEvents method which gives other processes an opportunity to execute. LISP doesn't. However, Lee tried using (command ".delay" 0) and found it kind of fakes same - at minimum it prevents or minimizes the ghosting; seemingly stalled appearance. I wrapped it in a defun and place it in any process intensive loops I execute, typically on a "perform every nth loop" basis. For what it's worth:

Code: [Select]
(defun _do-events ( / cmdecho )
    (setq cmdecho (getvar 'cmdecho))
    (setvar 'cmdecho 0)
    (gc) ;; hello jtoverka
    (repeat 2 (command ".delay" 0) (princ ""))
    (setvar 'cmdecho cmdecho)
    (princ)
)
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

ribarm

  • Water Moccasin
  • Posts: 2334
  • Marko Ribar, architect
Re: LISP sometimes not possible to kill with ESC...
« Reply #2 on: May 04, 2020, 11:50:04 AM »
Thanks MP...
That's exactly what I was looking for...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

MP

  • Seagull
  • Posts: 17630
Re: LISP sometimes not possible to kill with ESC...
« Reply #3 on: May 04, 2020, 11:53:09 AM »
Thanks Lee / MP...
That's exactly what I was looking for...

YW!
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

roy_043

  • Water Moccasin
  • Posts: 1777
  • BricsCAD 18
Re: LISP sometimes not possible to kill with ESC...
« Reply #4 on: May 04, 2020, 02:43:36 PM »
'Original' topic: https://www.theswamp.org/index.php?topic=50848.0

What is the reason for repeat?

ribarm

  • Water Moccasin
  • Posts: 2334
  • Marko Ribar, architect
Re: LISP sometimes not possible to kill with ESC...
« Reply #5 on: May 04, 2020, 03:09:17 PM »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

MP

  • Seagull
  • Posts: 17630
Re: LISP sometimes not possible to kill with ESC...
« Reply #6 on: May 04, 2020, 03:36:28 PM »
What is the reason for repeat?

It’s a Jacqueline Susann thing.
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

ribarm

  • Water Moccasin
  • Posts: 2334
  • Marko Ribar, architect
Re: LISP sometimes not possible to kill with ESC...
« Reply #7 on: May 05, 2020, 12:48:26 AM »
To my newest testings, simple error handler is enough to force BREAK with ESC - i.e. "Function canceled" error...

I had to revise my code posted at cadtutor as this suggestion by MP dramatically slows loop calculations...

I only hope that I am right with error handler... Haven't still tested long enough, but it seems that ESC works as desired...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

MP

  • Seagull
  • Posts: 17630
Re: LISP sometimes not possible to kill with ESC...
« Reply #8 on: May 05, 2020, 01:07:11 AM »
... this suggestion by MP dramatically slows loop calculations ...

... typically on a "perform every nth loop" basis ...

e.g. (if (zerop (rem (setq i (1+ i)) 5000)) (_do-events))
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

ribarm

  • Water Moccasin
  • Posts: 2334
  • Marko Ribar, architect
Re: LISP sometimes not possible to kill with ESC...
« Reply #9 on: May 05, 2020, 01:19:54 AM »
You are right MP... I've retested and white screen again appeared... But then again, I have to do testings for BricsCAD... For now it looks that white screen won't appear if there is error handler... Still I have to do intensive checking...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Water Moccasin
  • Posts: 2334
  • Marko Ribar, architect
Re: LISP sometimes not possible to kill with ESC...
« Reply #10 on: May 05, 2020, 01:24:37 AM »
You are right MP... I've retested and white screen again appeared... But then again, I have to do testings for BricsCAD... For now it looks that white screen won't appear if there is error handler... Still I have to do intensive checking...

Sh** it appeared and in BricsCAD... I think I'll go now your way, just don't know if 5000 is correct number...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

MP

  • Seagull
  • Posts: 17630
Re: LISP sometimes not possible to kill with ESC...
« Reply #11 on: May 05, 2020, 01:59:29 AM »
... don't know if 5000 is correct number ...

There is no “one size fits all” number as it’s context and hardware dependent. Non exhaustive testing will reveal a practical value to use.
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

ribarm

  • Water Moccasin
  • Posts: 2334
  • Marko Ribar, architect
Re: LISP sometimes not possible to kill with ESC...
« Reply #12 on: May 05, 2020, 02:02:15 AM »
... don't know if 5000 is correct number ...

There is no “one size fits all” number as it’s context and hardware dependent. Non exhaustive testing will reveal a practical value to use.

I've finally revised my code at cadtutor and I hardcoded 5000, so what the hell (we don't know users PC specs...)...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

MP

  • Seagull
  • Posts: 17630
Re: LISP sometimes not possible to kill with ESC...
« Reply #13 on: May 05, 2020, 02:19:02 AM »
I've finally revised my code at cadtutor and I hardcoded 5000, so what the hell (we don't know users PC specs...)...

Find what works well on your machine (e.g. 5000) and then halve it (e.g. 2500), assuming the worst pc it will run on sports half the performance of yours ...
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

ribarm

  • Water Moccasin
  • Posts: 2334
  • Marko Ribar, architect
Re: LISP sometimes not possible to kill with ESC...
« Reply #14 on: May 06, 2020, 10:05:18 AM »
When I run my LISP from BricsCAD, I get this error :

Code: [Select]
...Unknown Error in Lisp or CAD system or 'Stack Overflow'

What can I do?
In AutoCAD it works well, but I wanted faster computing and to compare results, i.e. *.pat files...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Water Moccasin
  • Posts: 2334
  • Marko Ribar, architect
Re: LISP sometimes not possible to kill with ESC...
« Reply #15 on: May 06, 2020, 10:35:48 AM »
Quote
Code: [Select]
...Unknown Error in Lisp or CAD system or 'Stack Overflow'


Here is my testing project in ZIP...
BricsCAD can hatch *.pat file, but AutoCAD can't... But AutoCAD calculated *.pat and BricsCAD failed with above mentioned error...
Do happen to know why there are errors in BricsCAD presentation of *.pat file... According to LISP there should be no errors and lacks... If you see something in my code that you think is bad, please enlighten me...
I thought that BricsCAD will calculate differently, but it failed... And BTW, I tried to interrupt calculation and when I appended *.txt file to *.pat I did get differently then *.pat calculation in one go... So still somethings wrong with my codes, but I can't quite find out what...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Water Moccasin
  • Posts: 2334
  • Marko Ribar, architect
Re: LISP sometimes not possible to kill with ESC...
« Reply #16 on: May 13, 2020, 08:03:15 AM »
Just to inform... This topic is still not solved... I run my routine again and still white screen appears after ESC... So this thing with (_do-events) doesn't really solves it... We need more methods and options to consider... Yes the problem is (while/repeat/foreach/recursion) looping, but how to solve this problem more reliably? Note sometimes this thingy (_do-events) is not applicable (foreach/recursion)... So are there any new tricks?

[EDIT : I am not saying that it isn't possible to implement (_do-events) and for (foreach/recursion), but the thing is that it slows things and still not 100% reliable...]
« Last Edit: May 13, 2020, 08:15:56 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

VovKa

  • Swamp Rat
  • Posts: 1223
  • Ukraine
Re: LISP sometimes not possible to kill with ESC...
« Reply #17 on: May 13, 2020, 09:58:08 AM »
Marko you want to do-events only with lisp? no arx?

ribarm

  • Water Moccasin
  • Posts: 2334
  • Marko Ribar, architect
Re: LISP sometimes not possible to kill with ESC...
« Reply #18 on: May 13, 2020, 10:46:24 AM »
Marko you want to do-events only with lisp? no arx?

I want to make this routine working as it's supposed to, so that when I hit ESC, it quits 100% reliably without going to white screen (Windows application - not responding - i.e. AutoCAD)...
https://www.cadtutor.net/forum/topic/70417-make-pat-files/?do=findComment&comment=565434
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

MP

  • Seagull
  • Posts: 17630
Re: LISP sometimes not possible to kill with ESC...
« Reply #19 on: May 13, 2020, 10:56:54 AM »
;;  My very quick perusal of your code suggests you're using (_do-events) very
;;  heavy handedly, i.e. invoking it every pass thru iteration loops. Do this instead:

;;  before loop

(setq
    i      0
    cycles 5000 ;; determine optimal value empirically
)


;; in processing loop

(if (zerop (rem (setq i (1+ i)) cycles)) (_do-events))

;;  cheers
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

ribarm

  • Water Moccasin
  • Posts: 2334
  • Marko Ribar, architect
Re: LISP sometimes not possible to kill with ESC...
« Reply #20 on: May 13, 2020, 11:25:08 AM »
I am doing what you suggested... And I've put 2000 instead of 5000, so I am betting on better response on ESC... I hope my code is then finished as I wanted. Now if white screen pops up again, I hope it's not by me and badly coding...  :mrgreen:
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

MP

  • Seagull
  • Posts: 17630
Re: LISP sometimes not possible to kill with ESC...
« Reply #21 on: May 13, 2020, 11:41:26 AM »
I am doing what you suggested...

Not entirely. You defined the do-events function using vl-cmdf instead of command. Use the latter.
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

MP

  • Seagull
  • Posts: 17630
Re: LISP sometimes not possible to kill with ESC...
« Reply #22 on: May 13, 2020, 12:04:02 PM »
Really long processes might benefit from this if AutoCAD loses focus:

Code: [Select]
(defun _doc ( )
    (vl-load-com)
    (setq *doc* (vla-get-activedocument (vlax-get-acad-object)))
    (defun _doc ( ) *doc*)
    *doc*
)

(defun _do-events ( / cmdecho )
    (setq cmdecho (getvar 'cmdecho))
    (setvar 'cmdecho 0)
    (gc)
    (vla-activate (_doc)) ;; <<--- new
    (repeat 2 (command ".delay" 0) (princ ""))
    (setvar 'cmdecho cmdecho)
    (princ)
)

Concept code; untested.
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

ribarm

  • Water Moccasin
  • Posts: 2334
  • Marko Ribar, architect
Re: LISP sometimes not possible to kill with ESC...
« Reply #23 on: May 13, 2020, 12:43:08 PM »
It's just me...
I prefer using (vl-cmdf) instead of both (command) and (command-s) predominately from this reasons...
In later versions of AutoCAD (command-s) was suggested to be used in error handlers if you want to use command calls, but in older versions (command-s) isn't implemented... So I experimented and I came to conclusion that (vl-cmdf) also behaves correctly in error handlers and BTW. it exist in all ACAD versions since also (command) function was introduced in ALISP... Further investigations showed that timings of execution was fastest with (vl-cmdf) - just very very small difference than (command-s)... (command) was slowest according to my testings... So if you think more over it, no matter it returns T and not nil, (vl-cmdf) can very well substitute both (command) and (command-s)... One more fact in favor of (vl-cmdf) : (command-s) must have supplied all tokens in single expression wihout breaking syntax... (vl-cmdf) here bahaves like (command), you simply can use it like this :

Code: [Select]
(vl-cmdf "_.PLINE")
(foreach p pl
  (vl-cmdf "_non" p)
)
(vl-cmdf "")

Or this snippet :

Code: [Select]
(vl-cmdf "_.PLINE")
(while (< 0 (getvar 'cmdactive))
  (vl-cmdf "\\")
)

(command-s) can't imitate this behaviour...
You'd have to do someting like this :

Code: [Select]
(apply 'command-s (cons "_.PLINE" (append (apply 'append (mapcar '(lambda ( x ) (list "_non" x)) pl)) (list ""))))

But that syntax is crazy IMHO...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

MP

  • Seagull
  • Posts: 17630
Re: LISP sometimes not possible to kill with ESC...
« Reply #24 on: May 13, 2020, 12:57:48 PM »
While I use vl-cmdf / command-s where applicable in my coding none of the "benefits" are applicable for this context imo, especially speed. Cheers.
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

VovKa

  • Swamp Rat
  • Posts: 1223
  • Ukraine
Re: LISP sometimes not possible to kill with ESC...
« Reply #25 on: May 13, 2020, 04:26:00 PM »
I want to make this routine working as it's supposed to
this is clear

what i meant was that you can try onidleacad function from ProgressBars arx library by Alexander Rivilis
original post https://www.theswamp.org/index.php?topic=8570.msg115457#msg115457
latest version http://www.maestrogroup.com.ua/support/ProgressBars.zip

MP

  • Seagull
  • Posts: 17630
Re: LISP sometimes not possible to kill with ESC...
« Reply #26 on: May 13, 2020, 04:48:06 PM »
what i meant was that you can try onidleacad function from ProgressBars arx library by Alexander Rivilis
original post https://www.theswamp.org/index.php?topic=8570.msg115457#msg115457
latest version http://www.maestrogroup.com.ua/support/ProgressBars.zip

Nice, Alexander Rivilis' work is top notch.

If you're going the third party route there's also DOS_LIB's dos_getprogress function:

\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox