Does anybody know why some programs list "Command:" twice while others exit cleanly and list "Command:" at the end of the program only once (as they should, I guess)?
Here's a simple example where command is listed twice after the program is run:
(defun c:test () (if (setq Ent (car (entsel))) (progn (setq ELst (entget Ent '("ACAD"))) (setq XData (assoc -3 ELst)) (if XData (progn (foreach XDe (cadr XData) (print XDe) ) ) (prompt "\nThis is a test.") ) ) ) ;end if (princ) ) ;end defun
When I run the program I get:
Command: test
Select object:
This is a test.
Command:
Command:
How can I get rid of the extra "Command:" line?
Thanks.
Solved! Go to Solution.
Solved by john.uhden. Go to Solution.
Solved by hmsilva. Go to Solution.
@Anonymous wrote:
Does anybody know why some programs list "Command:" twice while others exit cleanly and list "Command:" at the end of the program only once (as they should, I guess)?
Here's a simple example where command is listed twice after the program is run:
(defun c:test () (if (setq Ent (car (entsel))) (progn (setq ELst (entget Ent '("ACAD"))) (setq XData (assoc -3 ELst)) (if XData (progn (foreach XDe (cadr XData) (print XDe) ) ) (prompt "\nThis is a test.") ) ) ) ;end if (princ) ) ;end defunWhen I run the program I get:
Command: test
Select object:
This is a test.
Command:Command:
How can I get rid of the extra "Command:" line?
Does it put up two of them under all possible conditions, i.e. when you select an object that has extended data and when you select one that doesn't and when you miss in picking something? Or does it put up only one under one or another of those conditions? I'm just wondering whether the extra might be caused by a nil return from one or another of the (if) test functions.
By the way, I would suggest a slight re-arrangement at the beginning. This line:
(if (setq Ent (car (entsel)))
will, if the User misses when picking something, not merely return nil but will generate an error, because (entsel) will return nil, so (car) won't have an entity-selection list to get the first item from. That error can be avoided by doing something like this:
(if (setq esel (entsel)); nil return here just goes to 'else' expression, without error
(progn ; then [User successfully picked on something]
(setq Ent (car esel)); moved out of (if) test expression
....
Thanks for your reply.
I re-arranged the code as you suggested. It still puts up two "Command:" lines at the end of the program under ALL conditions (XData, no XData, missing picking object). Do you think the extra "Command:" is generated by an error I cannot catch?
(defun c:test (/ esel EList Xdata XDe) (if (setq esel (entsel "\nSelect obj to list XData:")) (progn (setq ELst (entget (car esel) '("ACAD"))) (setq XData (assoc -3 ELst)) (if XData (progn (terpri) (foreach XDe (cadr XData) (print XDe) ) ) (prompt "\nNo XData.") ) ) ) ;end if (princ) )
@Anonymous wrote:
Does anybody know why some programs list "Command:" twice while others exit cleanly and list "Command:" at the end of the program only once (as they should, I guess)?
..
How can I get rid of the extra "Command:" line?
Thanks.
HS20EXR,
some programs list "Command:" twice, because the first command listed is the last value return.
A simple test, with
(defun c:test1 (/ p) (if (setq p (getpoint "\nPick a point: ")) (vl-cmdf "point" p) );; if );; test
We'll have this command line echo:
Command: test1
Pick a point: point
Current point modes: PDMODE=0 PDSIZE=0.0000
Specify a point:
Command: T
Command:
As your code ends with the princ function, the command line displays nothing, because there is nothing to return, nor nil or T, but there is an empty echo...
To suppress that echo, you'll probably have to deal with the CMDECHO SysVar and some Error Handling...
With your code, if you have Express Tools, the easiest way is
(defun c:test ( / esel ELst Xdata XDe) (acet-error-init (list (list "cmdecho" 0 );; list T );; list );; acet-error-init (if (setq esel (entsel "\nSelect obj to list XData:")) (progn (setq ELst (entget (car esel) '("ACAD"))) (setq XData (assoc -3 ELst)) (if XData (progn (terpri) (foreach XDe (cadr XData) (print XDe) ) ) (prompt "\nNo XData.") );; if );; progn (prompt "\nNo Obj.") );end if (acet-error-restore) );; test
HTH
Henrique
I realized I still get the second "Command" line in case of error - hitting ESC when asked to pick an obj. Whould you know what error function to use to get rid of it?
I tried
(defun *error* (msg) (princ msg) (setvar "cndecho" 1) (princ) )
but doesn't seem to be working.
@Anonymous wrote:
I realized I still get the second "Command" line in case of error - hitting ESC when asked to pick an obj. Whould you know what error function to use to get rid of it?
I tried
(defun *error* (msg) (princ msg) (setvar "cndecho" 1) (princ) )but doesn't seem to be working.
I don't know.
I will do some tests...
Henrique
@Anonymous wrote:
I realized I still get the second "Command" line in case of error - hitting ESC when asked to pick an obj. Whould you know what error function to use to get rid of it?
I tried
(defun *error* (msg) (princ msg) (setvar "cndecho" 1) (princ) )but doesn't seem to be working.
That n in "cndecho" might be the culprit, since it would generate an error about a non-existent System Variable -- correct it to an m and see whether it still does it.
@Anonymous wrote:
I realized I still get the second "Command" line in case of error - hitting ESC when asked to pick an obj. Whould you know what error function to use to get rid of it?
...
HS20EXR,
again, using Express Tools
(defun c:test ( / esel ELst Xdata XDe) (acet-error-init (list (list "cmdecho" 0 );; list 0 );; list );; acet-error-init (if (setq esel (entsel "\nSelect obj to list XData:")) (progn (setq ELst (entget (car esel) '("ACAD"))) (setq XData (assoc -3 ELst)) (if XData (progn (terpri) (foreach XDe (cadr XData) (print XDe) ) ) (prompt "\nNo XData.") );; if );; progn (prompt "\nNo Obj.") );end if (acet-error-restore) );; test
Hope that helps
Henrique
Henrique, I am getting the following errors in some programs that use (acet-error-init) (acet-error-restore) :
(*pop-error-mode*) underflow.AutoCAD variable setting rejected: OSMODE nil
(*pop-error-mode*) underflow.
After that, none of the programs that use (acet-error-init) (acet-error-restore) work. Would you have any suggetions?
I ran into this years ago, probably starting with R15.
Your function does not call any AutoCAD (command)s. If you include just one (command ...) then your excessive echo will go away.
What I always use is:
(setvar "cmdecho" 0) (command "_.expert" (getvar "expert")) ;; NOTE - Reset cmdecho somewhere before your function completes.
John F. Uhden
Thanks for the suggestion,
(defun c:te () (defun *error* (msg) (princ msg) (setvar 'osmode osmode) (setvar 'cmdecho 1) (princ) ) ;defun ;;; (acet-error-init (list (list "cmdecho" 0) 0)) (setvar 'cmdecho 0) (command "_.expert" (getvar "expert")) (setq osmode (getvar 'osmode)) (setq obj1 (entlast)) (setq p1 (getpoint "Pick a point ")) (setvar 'osmode 0) (command "_copy" obj1 "" p1 "" 3) (setvar 'osmode osmode) (setvar 'cmdecho 1) ;;; (acet-error-restore) )
What I get after I run it is: Command: te Pick a point 3
1.
If I activate (acet-error-init (list (list "cmdecho" 0) 0)) and (acet-error-restore) it runs cleanly, but for some programs I get the errors I mentioned in the first post and I cannot run any programs that use that code until I close and open the drawing again.
Actually I tried your suggestion for some different programs and it seems to work. Thank you, I appreciate your help.
I'm running 2002, so things may have changed, but I don't understand
(command "_copy" obj1 "" p1 "" 3)
I could understand
(command "_copy" obj1 "" p1 p2)
What purpose are the "" and 3 at the end of the copy command?
I think that's where your problem is.
John F. Uhden
"" & 3 are supposed to copy the object at 3 units distance. I tested the code and it worked for me, but it's not a very good example. Anyway, I tried your suggested code on a few programs and it worked nicely, I got rid of the extra echo. Thank you, it's a simple and nice solution, I appreciate your help.
I came across a program that keeps giving me the extra "command" after I exit it. I was wondering if you had any idea how to fix it. It emulates LINE command and it resets DYNMODE variable to 0 (it gets set to 2 from other program I run and cannot reset back unless I do it manually). iset cmdecho to 1 so I can see the prompts on the screen.
(defun c:test (/ *error*) (defun *error* (msg) (princ msg) (princ) ) (command "_.expert" (getvar "expert")) (setvar 'cmdecho 1) (setvar 'dynmode 0) (command "_.line") (while (/= (getvar "cmdactive") 0) (command pause)(terpri) ) (princ) )
Can't find what you're looking for? Ask the community or share your knowledge.