Author Topic: Make LISP wait till SCRIPT completes  (Read 4608 times)

0 Members and 1 Guest are viewing this topic.

mailmaverick

  • Bull Frog
  • Posts: 494
Make LISP wait till SCRIPT completes
« on: March 02, 2015, 05:03:34 AM »
I have a lisp function which calls a script file as follows :-

Code: [Select]
(defun c:test()
-----
----- my lisp code here
-----
------
(if (findfile "D:\\ABC.scr")
(command "_script" "D:\\ABC.scr")
-----
----- my lisp code here
-----
------
) ; end defun

Now my script file, ABC.SCR is huge and takes some time to run, probably 2-3 minutes.
I want that the lines in the LISP which are below the script call, to be executed only after the completion of the script.
How to do so ?
 






tombu

  • Bull Frog
  • Posts: 288
  • ByLayer=>Not0
Re: Make LISP wait till SCRIPT completes
« Reply #1 on: March 02, 2015, 06:59:07 AM »
You can call lisp from a script, why not separate code called at the end of the script? 
Tom Beauford P.S.M.
Leon County FL Public Works - Windows 7 64 bit AutoCAD Civil 3D

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Make LISP wait till SCRIPT completes
« Reply #2 on: March 02, 2015, 07:25:15 AM »
Maybe it has changed over the years, but it was a limitation of autolisp the once a (command "_.SCRIPT" ...)  is called, Autolisp's evaluator was terminate.  Therefore it as always the last command in a routine.

I'll look for some documentation.  -David
R12 Dos - A2K

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Make LISP wait till SCRIPT completes
« Reply #3 on: March 02, 2015, 07:42:09 AM »
Maybe it has changed over the years, but it was a limitation of autolisp the once a (command "_.SCRIPT" ...)  is called, Autolisp's evaluator was terminate.  Therefore it as always the last command in a routine.

Agreed - as far as I am aware, evaluation of an AutoLISP program will cease when a Script is run from the program.

mailmaverick

  • Bull Frog
  • Posts: 494
Re: Make LISP wait till SCRIPT completes
« Reply #4 on: March 02, 2015, 09:10:13 AM »
You can call lisp from a script, why not separate code called at the end of the script?

Code: [Select]
(defun c:test()
-----
----- my lisp code 1 here
-----
------
(if (findfile "D:\\ABC.scr")
(command "_script" "D:\\ABC.scr")
)
-----
----- my lisp code 2 here
-----
------
) ; end defun

I like your suggestion. But how to get values of variables from LISP Code 1 to LISP Code 2.



Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Make LISP wait till SCRIPT completes
« Reply #5 on: March 02, 2015, 10:13:46 AM »
You can call lisp from a script, why not separate code called at the end of the script?

Code: [Select]
(defun c:test()
-----
----- my lisp code 1 here
-----
------
(if (findfile "D:\\ABC.scr")
(command "_script" "D:\\ABC.scr")
)
-----
----- my lisp code 2 here
-----
------
) ; end defun

I like your suggestion. But how to get values of variables from LISP Code 1 to LISP Code 2.

You could use vl-propagate or use the blackboard namespace (vl-bb-set / vl-bb-ref).

mailmaverick

  • Bull Frog
  • Posts: 494
Re: Make LISP wait till SCRIPT completes
« Reply #6 on: March 02, 2015, 11:04:07 AM »
You could use vl-propagate or use the blackboard namespace (vl-bb-set / vl-bb-ref).

Dear Lee, you have always opened new areas of programming, currently unexplored by me.

I never knew earlier about the concept of vl-propagate and vl-bb-set / vl-bb-ref.

But after your mentioning about the same, I read about it and came to know about it so well.

Thanks a lot.

enderprime

  • Guest
Re: Make LISP wait till SCRIPT completes
« Reply #7 on: March 02, 2015, 12:18:07 PM »
I have a number of batch tools that utilize scripts to process lists of drawings.

My general method is:

1) Separate LISP into 2 functions, one that creates and runs the main script, and one that will run in each dwg, ex: f-external and f-internal

2) In (f-external), for each dwg in the batch list, add to the main script something similar:

    "_.OPEN"
    "path-to-dwg"
    "(load \"path-to-lisp\")"
    "(f-internal)"

    Loading and executing the (f-internal) function per drawing keeps all real work inside LISP, instead of having a long script file that can only
    issue commands. This lets you do all the cool vla/vlax functions and decisions/loops that you can't do through script commands.
   
    If you are loading each drawing in its own session, such as through core console, then you can omit the open command and use the same
    script for every drawing, instead of making a long assembly line type of script.

3) In (f-internal), do all necessary work, then save and close the drawing

4) At the end of (f-internal), I append a report or log file of work done. You could also write variables to a file at this point so that the main code can read them back if needed.

As for keeping main code paused while f-internal is working, what I have been doing is creating my own .lock file that gets deleted when f-internal is finished (it may be any file type really, and does not need to contain any actual data). Somewhere in a (foreach dwg dwgs..) processing loop or in a main code block just before the main script starts running, I usually have code similar to the following:

(while (findfile "path-to-lock")
    (command "DELAY" 1000)
)

So every second it checks if the lock file still exists, and if so it waits before continuing along in the loop. If you would like to use only one lock file that exists for the duration of the batch, you could have the end of script delete the lock file instead of (f-internal) with:

"(vla-file-delete \"path-to-lock\")"

This method has been very successful for me, both in MDI and SDI batches. Hope it helps.
« Last Edit: March 02, 2015, 01:11:15 PM by ender.prime »

mailmaverick

  • Bull Frog
  • Posts: 494
Re: Make LISP wait till SCRIPT completes
« Reply #8 on: March 02, 2015, 01:02:22 PM »
Excellent explanation ender prime.

Thanks a lot !!!!