Costinbos77 Posted January 8, 2013 Posted January 8, 2013 Hey. how to get a different result depending on what is given after Pause: choose a point = true, or enter = nil ? (if (command "_move" (entlast) "" '(0 0 0) pause) a b) Quote
GP_ Posted January 8, 2013 Posted January 8, 2013 Waiting for other replies... (setq a (entget (entlast))) (command "_move" (entlast) "" '(0 0 0) pause) (if (equal a (entget (entlast))) (setq b 1) (setq b 2)) Quote
Lee Mac Posted January 8, 2013 Posted January 8, 2013 (defun c:test ( / s p ) (if (and (setq s (ssget "_:L")) (setq p (getpoint "\nSpecify basepoint: ")) ) (if (vl-cmdf "_.move" s "" "_non" p "\\") (if (equal p (getvar 'lastpoint) 1e- (princ "\nUser pressed Enter.") (princ "\nUser clicked a point.") ) (princ "\nUser pressed Esc.") ) ) (princ) ) Quote
Costinbos77 Posted January 9, 2013 Author Posted January 9, 2013 Thanks for the replies. Somehow there is an AutoCAD variable that says whether an expression has been executed or not? Quote
Costinbos77 Posted January 9, 2013 Author Posted January 9, 2013 (edited) Here I used the decision : (defun c:Test () (setq i 1 ) ;_ end of setq (while (progn (setq nms (itoa i)) ;_ end of setq (command "text" "m"'(0 0 0) 0.2 0 nms) ;_ end of c (setq lo (entget (entlast))) ;_ end of setq (princ (strcat "\n Choose place for TEXT : " nms " ; Any = Stop ; < Pick> : ")) ;_ end of p (vl-catch-all-apply '(lambda nil (command "_move" (entlast) "" '(0 0 0) pause))) ;_ end of vl [color=red](if (equal lo (entget (entlast))) nil T) ;_ end of if[/color] ) ;_ end of prog cond (setq i (1+ i) ) ;_ end of setq ) ;_ end of wh p (entdel (entlast)) ) ; end Try this application is useful for inserting text iterated. Edited January 10, 2013 by Costinbos77 Quote
danellis Posted January 10, 2013 Posted January 10, 2013 I thought I answered the question Perhaps not in a way the OP could parse? The principal is that rather than testing for a response mid command, the function asks for the point and checks it *before* starting with the move command. dJE Quote
GP_ Posted January 10, 2013 Posted January 10, 2013 Try this application is useful for inserting text iterated. If the function is used for entering text iterated why not use the lisp n° 1? Quote
Costinbos77 Posted January 11, 2013 Author Posted January 11, 2013 That's GP_ is a lisp application no 1. I tried to get something and I did not know how to approach the problem. Many thanks to Lee Mac's help and share his experience. Quote
Lee Mac Posted January 11, 2013 Posted January 11, 2013 Perhaps not in a way the OP could parse? The principal is that rather than testing for a response mid command, the function asks for the point and checks it *before* starting with the move command. I perceived the question to be asking how to detect the user's response during the 'pause' of the Move command, not testing beforehand. The code could easily be restructured to use two point prompts and test the user's response to both prompts before calling the command, however, this would remove the object preview offered by the Move command, and furthermore, the OP would need to recreate the alternative options offered by the Move command. The reason for my subsequent response was that the OP had appeared to overlook the use of vl-cmdf in my example, in favour of an unnecessary combination of vl-catch-all-apply, an anonymous lambda function and command expression. That's GP_ is a lisp application no 1. I tried to get something and I did not know how to approach the problem. Many thanks to Lee Mac's help and share his experience. You're welcome Costinbos. Quote
pBe Posted January 11, 2013 Posted January 11, 2013 ...... the use of vl-cmdf in my example. If i understand it right, vl-cmdf by itself acts like an if expression. Since you're at a "tutorial mode"Lee can you give us an example on when vl-cmdf is more appropriate to use rather than command? [not like the example shown on the help file that is ] Quote
Costinbos77 Posted January 12, 2013 Author Posted January 12, 2013 Hey. Here's the explanation I found in AutoCAD Help : Because vl-cmdf evaluates each argument before passing the command to AutoCAD, the invalid point list is detected and the command is not executed. > Quote
Lee Mac Posted January 12, 2013 Posted January 12, 2013 If i understand it right, vl-cmdf by itself acts like an if expression. Since you're at a "tutorial mode" Lee can you give us an example on when vl-cmdf is more appropriate to use rather than command? [not like the example shown on the help file that is ] One advantage of the vl-cmdf function over the command function is that it will evaluate whether the command has been evaluated successfully and provides some feedback of the user's actions during the command call. Consider the following simple example: (defun c:test ( ) (if (vl-cmdf "_.line" "_non" "\\" "_non" "\\" "") (princ "\nSuccess!") (princ "\nFailure.") ) (princ) ) When running the above program, try pressing Esc at one of the prompts - notice that the else expression is still evaluated and the code continues evaluation since the vl-cmdf function has evaluated the supplied arguments for the command (in this case, the user pressing Esc), and has returned nil before passing the arguments to the command. If the command function was used, upon the user pressing Esc we would simply receive the error: Specify next point or [undo]: _non *Cancel* Command: ; error: Function cancelled And the code would cease evaluation. Another example of when the vl-cmdf function is useful is when calling commands such as the fillet command, for which the command may be unsuccessful even with valid input data (e.g. if the fillet radius is too large), for such cases, the vl-cmdf function would return nil indicating that the command was unsuccessful. Here are a few other examples: http://www.cadtutor.net/forum/showthread.php?61324-Break-lines-around-blocks-with-selection&p=500857&viewfull=1#post500857 http://www.cadtutor.net/forum/showthread.php?71157-Exit-from-%28while...&p=486969&viewfull=1#post486969 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.