TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Andrea on October 06, 2006, 12:31:26 PM
-
hi all....
I work to make a little function detection...
(defun INGcommand( / g)
(while (setq g (strcase (getstring "INGcommand: ")))
(progn
(if (vl-string-search "ING" g)(alert "You have entered a ING command"))
(if (eq g "COMMAND")(exit))
(if (and
(not (vl-string-search "ING" g))
(not (eq g "COMMAND"))
)
(alert "Invalid ING command.\n Type \"Command\" to return to AutoCAd command.")
)
)
(INGcommand)
)
)
(INGcommand)
It work great....since press the ESCAPE key.
any suggestion ?
-
You can try to use (vl-catch-all-apply) function or check the errno system variable value.
-
Andrea,
you could modify or use something like this ...
;;;--------------------------------------------------------------------------
;;;--------------------------------------------------------------------------
;| #lib.
kb:getString (<Promptmsg><Default><InitBit><AllowSpaces>)
Revised Library : kwb 20051031
20051101 kwb : ESC test added.
Build 2.0 :
(SETQ tmpVal (kb:getString "Lot Description" nil (+ 1 ) T))
(SETQ tmpVal (kb:getString "Name" "Me" (+ 1 ) Nil))
(SETQ tmpVal (kb:getString nil nil nil Nil))
|;
(DEFUN kb:getString (Promptmsg ; The prompt string.
Default ; Value to return if response is <enter>
InitBit ; Initget bit
AllowSpaces ; spaces Flag < T or nil )
;
/ returnvalue)
;;------------------------------
(OR InitBit (SETQ InitBit 0))
;;------------------------------
(SETQ Promptmsg (STRCAT "\n"
(COND (Promptmsg)
("Specify String Value")
)
)
)
;;------------------------------
(IF (AND Default (= (TYPE Default) 'str) (/= Default ""))
(PROGN
(SETQ Promptmsg (STRCAT "\n" Promptmsg " << " Default " >>: "))
(IF (VL-CATCH-ALL-ERROR-P
(SETQ returnvalue (VL-CATCH-ALL-APPLY
'GETSTRING
(LIST AllowSpaces Promptmsg)
)
)
)
;; ESC was pressed.
(SETQ ReturnValue nil
Default nil
)
)
(SETQ returnvalue (IF (= returnvalue "")
Default
returnvalue
)
)
)
;; Else no default, so don't accept ENTER or SPACEBAR
;;
(PROGN (SETQ Promptmsg (STRCAT "\n" Promptmsg ": "))
(IF (= InitBit 1)
(WHILE (= ""
(SETQ returnvalue (VL-CATCH-ALL-APPLY
'GETSTRING
(LIST AllowSpaces Promptmsg)
)
)
)
)
;;
(SETQ returnvalue
(VL-CATCH-ALL-APPLY 'GETSTRING
(LIST AllowSpaces Promptmsg)
)
)
)
(IF (VL-CATCH-ALL-ERROR-P returnvalue)
;; ESC was pressed.
(SETQ ReturnValue nil)
)
)
)
;;------------------------------
returnvalue
)
;;;--------------------------------------------------------------------------
;;;--------------------------------------------------------------------------
-
<warning, I just woke up>
Abused from this (http://www.theswamp.org/index.php?topic=7259.msg89772#msg89772) post --
(defun Evaluate ( expression / result )
(vl-catch-all-apply
'(lambda ( )
(setq result
(eval expression)
)
)
)
result
)
Possible useage --
(defun INGcommand ( / g done )
(while
(and
(not done)
(setq g (Evaluate '(strcase (getstring "INGCommand: "))))
)
(cond
( (eq g "COMMAND")
(setq done t)
)
( (vl-string-search "ING" g)
(alert "You have entered a ING command")
)
( t
(alert
(strcat
"Invalid ING command.\n"
"Type \"Command\" to return"
"to AutoCAD command."
)
)
)
)
)
(princ)
)
-
Hi
(defun INGcommand(/ g)
(while (setq g (vl-catch-all-apply 'getstring (list "\nINGcommand: ")))
(if (not (vl-catch-all-error-p g))
(progn
(if (vl-string-search "ING" g)(alert "You have entered a ING command"))
(if (eq g "COMMAND")(exit))
(if (and
(not (vl-string-search "ING" g))
(not (eq g "COMMAND")))
(alert "Invalid ING command.\n Type \"Command\" to return to AutoCAd command.")
)
)
(if (member (vl-catch-all-error-message a) (list "Fonction annulée" "Function cancelled"))
(setq g T)
)
)
)
)
(INGcommand)
@+
-
<warning, I just woke up>
Abused from this (http://www.theswamp.org/index.php?topic=7259.msg89772#msg89772) post --
DejaVu
-
Thanks guys...
but...
MP...your code have same result....when user press escape it return to the AutoCAd command line.
Patrick35....see the picture below when pressing escape..
-
...when user press escape it return to the AutoCAd command line.
Without specification what are we to imagine you want aside from standard behavior?
-
oh !
I'm stupid :-o
Replace
(if (member (vl-catch-all-error-message a) (list "Fonction annulée" "Function cancelled"))
by
(if (member (vl-catch-all-error-message g) (list "Fonction annulée" "Function cancelled"))
@+
-
Sorry MP....if wasn't clear.. :|
all i need to do its to prevent user while using the escape key.
eg:
INGcommand: (user press escape here)
return to
INGcommand:
but don't know how...
-
Bravo Patrick !..
it work great !.
a simple question..
why using a list here ..
...(list "\nINGcommand: ")
-
I have to ask why? Elegant or not standard behavior is that hitting the <Esc> terminates a function/command.
Anyway, if you're bent on this approach (which I don't recommend) all you have to do is have the Evaluate function return an empty string instead of nil.
-
In the help of Autolisp
(vl-catch-all-apply 'function list)
Arguments
'function
A function. The function argument can be either a symbol identifying a defun, or a lambda expression.
list
A list containing arguments to be passed to the function.
@+
-
Merci..
there is another problem....
(defun INGcommand(/ g)
(while (setq g (strcase (vl-catch-all-apply 'getstring (list "\nINGcommand: "))))
(if (not (vl-catch-all-error-p g))
(progn
(if (vl-string-search "ING" g)
(progn
(setq g1 g)
(ing_go)
))
(if (eq g "COMMAND")(exit))
(if (and
(not (vl-string-search "ING" g))
(not (eq g "COMMAND")))
(alert "Invalid ING command.\n Type \"Command\" to return to AutoCAd command.")
)
)
(if (member (vl-catch-all-error-message g) (list "Fonction annulée" "Function cancelled"))
(setq g T)
)
)
)
)
(INGcommand)
(defun ing_go ()
(setq g T)
(if (eq g1 "ING_SAVE")
(progn
(initdia 1)
(command "_saveas"))
))
-
Try this:
(defun INGcommand (/ g)
(while
(progn
(setq g (vl-catch-all-apply 'getstring (list "INGcommand: ")))
(cond
((vl-catch-all-error-p g) ; yes, error
(alert "Escape not allowed.")
t ; stay in loop
)
((vl-string-search "ING" (setq g (strcase g)))
(alert "You have entered a ING command")
nil ; exit loop & return the INGcommand entered.
)
((eq g "COMMAND")
(exit) ; bye bye
)
(t
(alert
"Invalid ING command.\n Type \"Command\" to return to AutoCAd command."
)
t
)
)
)
)
g
)
(setq cmd (INGcommand))
-
hhhmm.....seem having same problem..
(defun goto_INGcommand ()
(if (eq g "ING_SAVE")
(progn
(initdia 1)
(command "_saveas")
))
)
(defun INGcommand ()
(setq g nil)
(while
(progn
(setq g (vl-catch-all-apply 'getstring (list "INGcommand: ")))
(cond
((vl-catch-all-error-p g) ; yes, error
(alert "Escape not allowed.")
t ; stay in loop
)
((vl-string-search "ING" (setq g (strcase g)))
(goto_INGcommand)
nil ; exit loop & return the INGcommand entered.
)
((eq g "COMMAND")
(exit) ; bye bye
)
(t
(alert
"Invalid ING command.\n Type \"Command\" to return to AutoCAd command."
)
t
)
)
)
)
g
)
(setq cmd (INGcommand))
maybe need to think for another solution....
using reactor..or something else....
Thanks. CAB.
-
Salut
(defun INGcommand(/ g)
(while (setq g (vl-catch-all-apply 'getstring (list "\nINGcommand: ")))
(if (not (vl-catch-all-error-p g))
(progn
(setq g (strcase g))
(if (vl-string-search "ING" g)
(ing_go g)
)
(if (eq g "COMMAND")(exit))
(if (and
(not (vl-string-search "ING" g))
(not (eq g "COMMAND")))
(alert "Invalid ING command.\n Type \"Command\" to return to AutoCAd command.")
)
)
(if (member (vl-catch-all-error-message g) (list "Fonction annulée" "Function cancelled"))
(setq g T)
(setq g nil)
)
)
)
)
(defun ing_go (g1)
(if (eq g1 "ING_SAVE")
(progn
(initdia 1)
(command "_saveas"))
))
(INGcommand)
-
Works for me. :-o
(defun INGcommand (/ g)
(while
(progn
(setq g (vl-catch-all-apply 'getstring (list "INGcommand: ")))
(cond
((vl-catch-all-error-p g) ; yes, error
(alert "Escape not allowed.")
t ; stay in loop
)
((vl-string-search "ING" (setq g (strcase g)))
(alert "You have entered a ING command")
nil ; exit loop & return the INGcommand entered.
)
((eq g "COMMAND")
(exit) ; bye bye
)
(t
(alert
"Invalid ING command.\n Type \"Command\" to return to AutoCAd command."
)
t
)
)
)
)
g
)
(defun c:test (/ cmd)
(setq cmd (INGcommand))
(cond
((eq cmd "ING_SAVE")
(initdia 1)
(command "_saveas")
)
(t
(alert "Invalid ING Command")
)
)
)
-
Works for me.
hug ?.. :?
hmm....bizzarre..!..
Thanks CAB nice try !.. :wink:
Patrick,..your code work perfectly. thank you. :roll:
-
Works for me.
hug ?.. :?
hmm....bizzarre..!..
Thanks CAB nice try !.. :wink:
Andrea did you copy the second test routine without any changed & test it?
Did you get an error? If it works in the test the problem is in your implementation. 8-)
-
Andrea did you copy the second test routine without any changed & test it?
Yes, CAB...
copy and paste in a new lisp file...
but the result is that return to AutoCAd command line..
-
Works for me. :-o
(defun INGcommand (/ g)
(while
(progn
(setq g (vl-catch-all-apply 'getstring (list "INGcommand: ")))
(cond
((vl-catch-all-error-p g) ; yes, error
(alert "Escape not allowed.")
t ; stay in loop
)
((vl-string-search "ING" (setq g (strcase g)))
(alert "You have entered a ING command")
nil ; exit loop & return the INGcommand entered.
)
((eq g "COMMAND")
(exit) ; bye bye
)
(t
(alert
"Invalid ING command.\n Type \"Command\" to return to AutoCAd command."
)
t
)
)
)
)
g
)
(defun c:test (/ cmd)
(setq cmd (INGcommand))
(cond
((eq cmd "ING_SAVE")
(initdia 1)
(command "_saveas")
)
(t
(alert "Invalid ING Command")
)
)
)
Alan
Work fine for me.
Gary
-
ok....let see ...
-
ok guys...
I think i have wrong start...
The program that i'm trying to do...
is to permit only some AutoCad function to the user...
like:
_SAVEAS
_OPEN
_PLOT
_PREVIEW
_LINE
_PLINE
...and some few other...
before continuing this project..
is this program a good way to do it ?
need your experience. :kewl:
-
What a waste of energy ... why didn't you say that at the start. ?
-
sorry Kerry..
your right....
but i have lurn something again....
maybe is wasting time for you..
but when i lurn.....is not wasting time for me.
I'm here to understand and lurn
how of all of guru like you, make a program better.
:oops:
-
Andrea, dont play the old "I want to learn" card.
We have been having this same discussion for years.
You continually think that people can read your mind .. and expect it.
-
this is my another way...
what is your comment about this one..
(defun loadFreactor ()
(vl-load-com)
(vlr-command-reactor nil '((:vlr-commandWillStart . startFCommand)))
)
(defun startFCommand (getcommand / CMD)
(setq CMD (nth 0 getcommand))
(cond
((and (/= CMD "TEXT")
(/= CMD "MTEXT")
(/= CMD "DTEXT")
)
(progn
(alert "Command disable.")
(exit)
)
)))
(loadFreactor)
the problem is..that the (exit) do not exit the command.
-
Kerry..please...don't start.. :x
-
ok guys...
I think i have wrong start...
The program that i'm trying to do...
is to permit only some AutoCad function to the user...
like:
_SAVEAS
_OPEN
_PLOT
_PREVIEW
_LINE
_PLINE
...and some few other...
before continuing this project..
is this program a good way to do it ?
need your experience. :kewl:
You could always just UNDEFINE certain commands. For example, you could put lines like the following in your ACAD.LSP file:
(command "undefine" "circle")
It is a simple matter for a moderately-savvy user to override this by using REDEFINE or by preceding the command name with a period ("."), but it might work for low-level users. Anyway, a moderately-savvy user could probably get around anything you try to do...
-
thanks sinc....
but i can't use undefine command..
because as you said...users can put the " . " symbol.
or use "redefine".
:|
-
thanks sinc....
but i can't use undefine command..
because as you said...users can put the " . " symbol.
or use "redefine".
:|
If that's important, then the solution you are trying to create probably won't work either. Lisp is not very robust, and is not designed to be used as a "user shell" inside of Autocad. It would be very easy for a command to error in such a way that your Lisp routine gets interrupted, and the user is right back at a normal Autocad prompt. Your user would have to manually restart your little ING thing, and it sounds like you can't trust your users to do this.
I don't think Autocad has any built-in support for what you are trying to do, and I don't think it's possible to create a robust solution in Lisp. There might be a way in some other language, but I doubt that, too. Autocad is designed so that the built-in commands can always be accessed, even if they are redefined or undefined, and I can't think of any way of changing that. I suspect it would be a challenge even if you write your own complete vertical app and run "Autocad inside".
There may be some sort of incredibly clever "trick" you can do and get the results you're after, but I can't think of what it would be... The usual solution is to just train your users... :-D
-
Ok...
thanks Sinc..
I will try another way....
599 users to train !!....ouf !. :lol: