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.
Solved! Go to Solution.
Solved by doni49. Go to Solution.
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 ( / )...)
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)
)
Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.
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
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
@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