Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Multiple Commands in one LISP

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
CSM_MAI
6502 Views, 7 Replies

Multiple Commands in one LISP

I currently have 5 individual commands combined into one lisp routine.  The first command looks for an envoronment value, when it finds it, it is supposed to then activate one of the other 4 commands I have in the lisp based on what it finds. For some reason AutoCAD is returning "unknown command" on the command prompt when the first command is executed. If I type in the command it was supposed to trigger, it works fine. When doing something like this, is the use of 5 separate (defun C:xxx ( )'s appropriate, or is there an easier way to achieve this? Thanks.

7 REPLIES 7
Message 2 of 8
mid-awe
in reply to: CSM_MAI

Make sure that the first command is loaded last of all. It can happen that your program runs fine but subsequent programs have not loaded.

I like to use functions for what you are doing.

(defun something (args) (command "whatever" Pause))

then:

(defun c:discover (/ discovered) (if (= (getstring "\n type something") discovered) (something args)) (princ))
Message 3 of 8
Shneuph
in reply to: CSM_MAI

Without seeing any of your code... It sounds like you should have your program organized like this then with the main one being defined as a 'command' and the rest only as functions.

 

(Defun C:MainCommand ( / ) <--- Define Command

   (cond 

     (= envvar w)

        (funct1)

         )

     (= envvar x)

        (funct2)

         )

     (= envvar y)

        (funct3)

         )

     (= envvar z)

        (funct4)

         )

     );end cond

);end command defun

 

;define functions

(defun funct1 ( / )...) <--- Sub functions (no C:)

(defun funct2 ( / )...)

(defun funct3 ( / )...)

(defun funct4 ( / )...)

 

 

This organization should work.. If you have them all defined as commands (You intend to use the sub functions directly from the command line) you can call them with (C:funct1) instead of (funct1) I think.

(Defun C:MainCommand ( / ) <--- Define Command

   (cond 

     (= envvar w)

        (C:funct1)

         )

     ...

  )

 (Defun C:funct1 ( / )...) 

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
Message 4 of 8
CSM_MAI
in reply to: CSM_MAI

Thanks for the quick responses. I was able to get it fixed by taking out the "C:" on the other 4 commands. Essentially it looks like this:

 

(defun C:maincommand ()

(setq GETS TEXT STRING CODE)

(COND

 ((= XXX "XXX") (COMMAND1))

 ((= XXX "XXX") (COMMAND2))

 ((= XXX "XXX") (COMMAND3))

 ((= XXX "XXX") (COMMAND4))

)

(PRINC)

)

 

(DEFUN COMMAND1 ()

(CODE)

(PRINC)

)

 

(DEFUN COMMAND2 ()

(CODE)

(PRINC)

)

 

(DEFUN COMMAND3 ()

(CODE)

(PRINC)

)

 

(DEFUN COMMAND4 ()

(CODE)

(PRINC)

)

 

Message 5 of 8
scot-65
in reply to: CSM_MAI

By moving the subroutines (function) above the "c:" or
"main" body of the program, and canceling out the first
and last line, one can edit without having to load, then
command running it. It is only after debugging that you
un-cancel the two lines and now you have the command.

2) A few programming languages will fail to call a subroutine
if the subroutine is placed below the calling point. With that,
it is good practice to place above and it is also easier to hunt
down the problem sub.

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 6 of 8
doni49
in reply to: CSM_MAI

If you DID want these "secondary" commands to remain callable (by the user), you could also leave the c colon in there -- just include it when you actually call the functions within lisp.

 

(defun c:sub1()
  (princ "This is Sub1")
)
(defun c:sub2()
  (princ "This is Sub2")
)
(defun c:MainCommand()
  (c:sub1)
  (c:sub2)
)

 



Don Ireland
Engineering Design Technician




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

Message 7 of 8
doni49
in reply to: doni49

Also -- if you DON'T want the secondary commands to be callable (the only place they'll be called is from within your main command), then I think you'd be better off using lambdas within each one of those test conditions.  It'll make for less "overhead".



Don Ireland
Engineering Design Technician




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

Message 8 of 8
doni49
in reply to: doni49


@doni49 wrote:

Also -- if you DON'T want the secondary commands to be callable (the only place they'll be called is from within your main command), then I think you'd be better off using lambdas within each one of those test conditions.  It'll make for less "overhead".


Forget this suggestion.  I've never tried to use lambda this way but I really thought it would work.  I just tried to write up an example -- but no good.



Don Ireland
Engineering Design Technician




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost