More LISP help

Discussion in 'AutoCAD' started by Xolo, Jun 27, 2004.

  1. Xolo

    Xolo Guest

    Hey everyone,

    I'm trying to run a LISP that calls up several other LISPS (only if needed
    to draw something) but I'm not sure how to make AutoLISP load the LISPS.
    I've already found out how to make the other LISPS run, but I don't want to
    have a whole bunch of LISPS loaded unless they are needed to draw something.

    Also, is there a way in AutoLISP to unload the same LISPS when they are done
    drawing what's required?

    Thanks for all the help,

    Xolo
     
    Xolo, Jun 27, 2004
    #1
  2. Xolo

    Chip Harper Guest

    (load "yourlisp")
    (while (> (getvar "cmdactive") 0) (command pause))
    (c:yourlisp function) ; if not setup to autorun
    (while (> (getvar "cmdactive") 0) (command pause))
     
    Chip Harper, Jun 27, 2004
    #2
  3. Xolo

    Xolo Guest

    Chip,

    Does this bit of code do everything, load and unload the LISP (I'm assuming
    the cmdactive part only uses it while needed)?

    Also, is the (command pause) necessary to allow user input or is it to
    facilitate something else?

    Thanks

    Xolo
     
    Xolo, Jun 27, 2004
    #3
  4. You can build a VLX that can be unloaded, but .LSP and FAS
    cannot be unloaded.

    To do 'demand-loading' of your LISP, you need to identify
    a dependent function in the .LSP file you must load, and
    then just do this:

    (if (not somefunction)
    (load "filename.lsp")
    )

    (somefunction ...)

    Where "somefunction' is a dependent function that is
    defined in "filename.lsp". You can test to see if the
    function's symbol is nil at the point where it is first
    needed, and if it is nil, then you can just load the
    ..lsp file that defines it.

    I don't know what Chip is getting at with the CMDACTIVE
    sysvar, but its use has no relation to demand-loading.



    AutoCAD based Security Planning Solutions:
    http://www.caddzone.com/securityplanning
     
    Tony Tanzillo, Jun 27, 2004
    #4
  5. Xolo

    Chip Harper Guest

    The command pause will only pause the running code to allow the second code
    to run and do what ever. Once lisp is loaded it's loaded. No way to unload
    it that I know of.
     
    Chip Harper, Jun 27, 2004
    #5
  6. Xolo

    Xolo Guest

    Tony,

    I tried using the (load "filename.lsp") but it doesn't seem to work to load
    the LISPS. Do I need to have the LISPS that are called up in a certain
    folder for them to load or do I just need the path to them in the Support
    File Search Path? Should I call out the entire path for the LISPS to be
    loaded?

    Thanks,

    Xolo
     
    Xolo, Jun 27, 2004
    #6
  7. Xolo

    Walt Engle Guest

    In loading lsp routines, the normal method is:
    (load "filename")

    without the ".lsp".
     
    Walt Engle, Jun 27, 2004
    #7
  8. There seems to be some confusion here.

    Pausing in a call to (command) allows direct user responses
    to prompts issued by built-in or ObjectARX based commands,
    it does't permit 'the second code' to run, whatever that is.



    AutoCAD based Security Planning Solutions:
    http://www.caddzone.com/securityplanning
     
    Tony Tanzillo, Jun 28, 2004
    #8
  9. 'but it doesn't seem to work to load the LISPS'.

    You'll need to be more specific than this. What
    exactly happens when you try to load the LISP
    file? Is there an error? If so, what is it?




    AutoCAD based Security Planning Solutions:
    http://www.caddzone.com/securityplanning
     
    Tony Tanzillo, Jun 28, 2004
    #9
  10. Xolo

    Chip Harper Guest

    I had occasion to create a lisp that basicly ran a series of other
    lisps..the master lisp ( the one calling the others) would print to screen
    that the utility was complete when in fact I had one still running. By
    adding the command pause the master lisp would pause until the secondary
    lisp would finish...then resume calling the next etc.
     
    Chip Harper, Jun 28, 2004
    #10
  11. Xolo

    CAB2k Guest

    This may help your understanding


    Code:
    (defun c:my-main-routine ( / my-local-functions-a my-local-functions-b)
    (defun my-local-functions-a ()
    ;; note the routine my-local-functions-a is not available
    ;; to outside routines
    (prompt "\nMy Local A.")
    )
    (defun my-local-functions-b ()
    (prompt "\nMy Local B.")
    )
    ;(some code here)
    (my-local-functions-a) ; go do A
    (my-local-functions-b) ; go do B
    (my-global-functions-c) ; go do C
    
    ;; *********************************
    (if (null my-global-functions-d)
    ;;  function not loaded so load it
    (load "my-global-functions-d")
    )
    ;; *********************************
    
    ;(some code here)
    
    (princ)
    ) ; end of my-main-routine
    
    (defun my-global-functions-c ()
    ;; note the routine my-global-functions-c is available
    ;; to outside routines
    (prompt "\nMy Global C.")
    )

    ================ Quote from S Madsen =============================
    A function name is but a symbol. There's no real difference between SETQ'ing a
    symbol and DEFUN'ing it.

    First time the parent function calls the nested DEFUN, it will evaluate it just
    like any other expression and, much like using SETQ, it will cause the function
    symbol to be assigned. Not declaring a nested DEFUN as local can cause bugs that
    are hard to find. "So what! I would never call a DEFUN nested within another
    DEFUN from the outside". Besides creating needless global symbols, it could just
    happen that a routine with the same name was run. Especially when not being
    aware of the fact that a nested DEFUN becomes global if not declared local
    within the parent, it might be assumed that there will be no name conflicts.

    Say you like the name getValue and (perhaps subconsciously) use the name for
    both a main level function and a nested function:

    Code:
    (defun getThisValue (/ a)
    (defun getValue ()
    (princ "Level 2")
    (setq a 1.0)
    )
    (getValue)
    )
    
    (defun getValue (/ a)
    (princ "Level 1")
    (setq a 2.0)
    )
    
    (defun doIt (/ x y z)
    (setq x (getValue))
    (terpri)
    (setq y (getThisValue))
    (terpri)
    (setq z (getValue))
    (princ)
    ) 

    Try load the 3 functions above and run DOIT. Here's a test output:

    _$ (doIt)
    Level 1
    Level 2
    Level 2

    Which function does the last call in DOIT run?
    Try run it again without reloading it:

    _$ (doIt)
    Level 2
    Level 2
    Level 2

    Why will the main level function GETVALUE never be run? Try inspect the value of
    variable a. If it was declared local to both functions called by DOIT, why is it
    not nil?
    ====================== End Quote ==================
     
    CAB2k, Jun 28, 2004
    #11
  12. Xolo

    Doug Broad Guest

    Hi Tony,

    Just curious. Wouldn't setting the subr's and variables
    of a loaded LSP file to nil accomplish virtually the same effect
    as "unloading" a VLX? I've never done it but it seems
    like it would recover memory with a (gc) call. It seems like
    such a cleanup routine could be added to selected files if
    the effects of unloading were important.

    Regards,
    Doug
     
    Doug Broad, Jun 28, 2004
    #12
  13. Xolo

    ECCAD Guest

    Actually, the .lsp file can reside anywhere.
    Example, loading myfile.lsp from K:\lisp folder.
    (load "K:/lisp/myfile.lsp")
    Notice use of / and not \
    Or,
    (load "K:\\lisp\\myfile.lsp")

    Bob
     
    ECCAD, Jun 28, 2004
    #13
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.