Trapping (command) input

Jason Piercey

Usenet Archive
Joined
Jun 30, 2003
Messages
868
Reaction score
0
Is it possible to trap the user input from a command inside a callback to :vlr-commandWillstart/:vlr-commandEnded?

I'm trying to do this with the MOVE command. I can mimic the prompts and trap the input, but then the command fires and the native prompts are issued in addition to my wrapper.

Is there something obvious I am overlooking?
 
Hi Luis,

I am writing a routine to save previous used distances
entered by the user, and store them on a right click
menu for easy retrieval. I am doing this for the OFFSET command and would like to included the MOVE and COPY commands as well.

I have the code written for the callbacks with the offset command, as I can just (getvar "offsetdist") to get the value that was entered last.

I can write my own version of the command prompts so
I can do what I wish with the data, but getting all this to work within a callback is not appearing to be that easy.

Hope I explained that well enough.
 
did not understood exactly...

maybe this could be useful not tested:

(defun commandwillstart (reactor params)
(print params)
(print (getvar "lastprompt")))

(defun commandended (reactor params)
(print commandended)
(print (getvar "lastprompt")))

(or editor_reactor
(setq editor_reactor
(vlr-editor-reactor
"editor reactor"
'((:vlr-commandwillstart . commandwillstart)
(:vlr-commandended . commandended)))))

it will return i.e.
Command: c
COPY
("COPY")
"COPY"
Select objects: 1 found

Select objects:
Specify base point or displacement, or [Multiple]: Specify second point of displacement or <use first point as displacement>: 12

#<USUBR @0a0ce988 COMMANDENDED>
"displacement or <use first point as displacement>: 12"

then maybe by using a substr from the last ":" you might be able to save the value of "12", but don't know sir... but I think is a mickey mouse solution... :-)
 
.... but I think is a mickey mouse solution... :-)

So that means you'll get fantastically rich by using it??? look how rich the mouse is!
:-)~
 
I'll have to look at the vlr-editor-reactor this evening and see if I can make sense of it, but here is my stab at the user prompt that should return the values I am looking for.

(defun myCommandPrompt (/ ss p1 p2 input)
(setq ss (ssget))
(initget 1) (setq p1 (getpoint "\nSpecify base point or displacement: ")) (setq p2 (getpoint "\nSpecify second point of displacement or <use first point as displacement>: " )
)

(setq input (getvar "lastprompt"))

(cond
((wcmatch input "*`@*`<*")
(substr input (+ 2 (vl-string-position (ascii "@") input)) (strlen input))
)

(p2
(strcat
(vl-princ-to-string (distance p1 p2))
"<"
(vl-princ-to-string (rtd (angle p1 p2)))
)
)

(t
(strcat
(vl-princ-to-string (distance '(0 0 0) p1))
"<"
(vl-princ-to-string (rtd (angle '(0 0 0) p1)))
)
)
)
)

So with that I can trap the user input, but how to
use that info in a callback and not let the native
command prompts be issued.

Once the core AutoCAD command starts am I
out of luck on supressing the command prompts?
 
I think i found a way - need the rtd function to tested please and I will put it here....
 
Ok this is what i have:

(defun commandwillstart (reactor params)
;;; (print params)
;;; (print (getvar "lastprompt"))

(if (eq (car params) "MOVE")
(progn (vla-sendcommand
(vla-get-activedocument (vlax-get-acad-object))
"(VL-CMDF) ")
(vla-sendcommand
(vla-get-activedocument (vlax-get-acad-object))
"(c:test) "))))

(defun commandended (reactor params)
(print commandended)
(print (getvar "lastprompt")))

(or editor_reactor
(setq editor_reactor
(vlr-editor-reactor
"editor reactor"
'((:vlr-commandwillstart . commandwillstart)
(:vlr-commandended . commandended)))))

(defun c:test (myCommandPrompt))

(defun rtd (arg)
(/ (* arg 180.0) pi))

(defun myCommandPrompt (/ ss p1 p2 input)
(setq ss (ssget))
(initget 1)
(setq p1 (getpoint "\nSpecify base point or displacement: ")) (setq p2 (getpoint "\nSpecify second point of displacement or <use first point as displacement>: " )
)

(setq input (getvar "lastprompt"))

(cond
((wcmatch input "*`@*`<*")
(substr input
(+ 2 (vl-string-position (ascii "@") input))
(strlen input))
)

(p2
(strcat
(vl-princ-to-string (distance p1 p2))
"<"
(vl-princ-to-string (rtd (angle p1 p2)))
)
)

(t
(strcat
(vl-princ-to-string (distance '(0 0 0) p1))
"<"
(vl-princ-to-string (rtd (angle '(0 0 0) p1)))
)
)
)
)
 
Thanks for your efforts, Luis. I'll have to look at
this a little later. I've got to get some stuff done
at the moment...... (real work, <grrr>)
 
Luis,

Thanks, that puts me on the right path. Sure wish there was some way to get rid of the command line echo. I may have to cleverly name my functions so they appear to be some sort of extra information for the user wrapped in a set of ;)

Is there any particular reason you used the vlr-editor-reactor instead of the vlr-command-reactor ?

Luis Esquivel said:
Ok this is what i have:
<snip>
 
Jason,
Why don't you just redefine the commands?
That seems far easier than using reactors.

Regards,
Doug
 
.... i have never had done any redefine or at least that i remember... :-)

btw: if anyone here would like to know how Robert Bell looks a like... have a chance to visit the augi.com... just to put a face to a helper friend!

now, to answer why editor reactor is because if i remember correctly i read about the tendency of getting rid of the command reactors but don't take my word, lately i been having problems with my mind (where it is now?)

luis.
 
Not sure why. This started out to be simple (don't
they always) just the offset command. Then I got
a wild hair....... Besides this gave me an excuse to
do something with reactors <g>. I'll think about it
some more, thanks Doug.
 
and actualy you can use in the vla-sendcommand

(vla-sendcommand
(vla-get-activedocument (vlax-get-acad-object))
"myCommand ")

i will try to get rid of the echo, i see ya tomorrow, g'nite

[L]
 
Think I'm not going to worry about the move/copy
commands, might take a different approach with them
at a later time. But the offset command is what my
original intent was and it works so I'm (for once <g>)
going to leave well enough alone
 
A very crude demonstration of redefinition:

;;Very crude distance memory demonstration
;;Little or no error checking.
;;D. C. Broad, Jr. 12/16/03
;;Copyright 2003 - may be distributed and used
;;without fee as long as this copyright notice is
;;included

(command "undefine" "offset")

;;Turn a list of numbers into a keyword list
(defun keydistances (lst / i)
(setq i 64)
(mapcar
'(lambda (x)
(setq i (1+ i))
(strcat (chr i) "-" (rtos x)" "))
lst))

;;Offset command replacement to remember
;;offset distances
(defun c:offset( / keys keystring prmpt dist ndx lastdist) (if offlist ;;list of offset distances (global (progn (setq lastdist (car offlist));;last distance offset (if (> (length offlist) 1) ;;menu if offset used more than once (setq keys (keydistances (cdr offlist)) keystring (apply 'strcat keys)) (setq keystring "")) (setq prmpt (strcat "\nOffset distance or [Through/" (vl-string-translate "/" " " keystring) "]<" (rtos lastdist)">: ")) (initget (strcat "T " keystring)) (setq dist (getdist prmpt)) (cond ((= (type dist) 'str) (cond ((= "T" dist)(command ".offset" "t")) (t (setq ndx (- (ascii (substr dist 1 1)) 64)) (command ".offset" (nth ndx offlist)) ))) (dist (if (not (member dist offlist)) (setq offlist (cons dist offlist))) (command ".offset" dist)) (t (command ".offset" "")))) (progn (initget 1) (setq dist (getdist "\nOffset distance or [Through]: ") offlist (list dist)) (command ".offset" dist)))
(princ))

(princ "Offset command redefined --D. C. Broad")(princ)
;-----------------end code

Jason Piercey said:
Think I'm not going to worry about the move/copy
commands, might take a different approach with them
at a later time. But the offset command is what my
original intent was and it works so I'm (for once <g>)
going to leave well enough alone
<snip>
 
I see where you're going.... I've done similar things
like that for other routines. For this application I've got per document/session storage (MDI if you will). Also included a adjustable MRU. I think it'll work out nicely. Just about done with it anyhow.

Thanks for sharing your ideas.
 
Luis:
See my response to the vla-sendcommand thread.

Luis Esquivel said:
and actualy you can use in the vla-sendcommand

(vla-sendcommand
(vla-get-activedocument (vlax-get-acad-object))
"myCommand ")

i will try to get rid of the echo, i see ya tomorrow, g'nite

[L]

Jason Piercey said:
Luis,

Thanks, that puts me on the right path. Sure wish there was some way to get rid of the command line echo. I may have to cleverly name my functions so they appear to be some sort of extra information for the user wrapped in a set of ;)

Is there any particular reason you used the vlr-editor-reactor instead of the vlr-command-reactor ?
 
Back
Top