View Full Version : My program is not running properly, But W H Y ??
rajat_bapi_mallick
2007-10-08, 08:57 AM
Hi !!
Can You please explain to me why my program is not running properly ???
(defun change (reactor command-list)
(vl-cmdf "_undo" "1")
(alert (strcat "Command: \""(car command-list)"\" has been undone."))
)
(defun xx ()
(if *commandReactor*
(progn
(setq *commandReactor* nil)
(vlr-remove-all :VLR-Command-Reactor)
)
)
(if (not *commandReactor*)
(setq *commandReactor*
(VLR-Command-Reactor
nil
'(
(:vlr-commandended . change)
)
)
)
)
(princ)
)
ccowgill
2007-10-08, 01:42 PM
I believe it is because you never undefined the standard undo command, so it is probably still running the standard undo
RobertB
2007-10-08, 05:47 PM
You should not use commands in reactor callbacks.
Mike_R
2007-10-09, 10:24 PM
You should not use commands in reactor callbacks.
Along the same lines as what RobertB said, change the line
(vl-cmdf "_undo" "1")
to
(command "_undo" "1")
Now see if you have any errors when the reactor executes. This could crash AutoCAD or corrupt the drawing it's in(it's happened to me before), so be sure to try it with a non-production drawing.
If you get errors, then that's why the code isn't executing. vl-cmdf checks if the command will cause an error and, if it will error, it won't execute.
rajat_bapi_mallick
2007-10-10, 09:22 AM
Thanks for your reply.
When I am using the following code,
(vl-cmdf "_undo" "1")
No error is generated. But when I am Using
(command "_undo" "1")
An error is generated. which says:
; error: invalid AutoCAD command: nil
So, is there any way, that I can undo last command anyway ??
Mike_R
2007-10-10, 02:46 PM
As far as I know, there's no way to use a reactor to undo anything. The only way to undo is via a command, which can't be used in a reactor. I glanced around the developer help and couldn't find anything there either, so it appears you're just going to have to do your undo's manually.
BTW, in a reactor, using (command) or (vl-cmdf) may sometimes work, but the problem with that is it could also corrupt your drawing. Also, this one caused me a lot of grief up until I figured it out. Never use entmod with an object reactor, if the object being modified is the triggering object. This could cause drawing corruption as well...
rajat_bapi_mallick
2007-10-11, 09:03 AM
As far as I know, there's no way to use a reactor to undo anything. The only way to undo is via a command, which can't be used in a reactor. ...
Thanks for your reply, but I have managed to use UNDO in a reactor.
Lets see my program:
(defun change (reactor command-list)
;;; (vl-cmdf "_undo" "1")
(if (member(car command-list) (list "LINE" "CIRCLE" "ARC" "PLINE" "ELLIPSE" "XLINE" "RAY" "MLINE" "3DPOLY" "POLYGON" "RECTANG" "DONUT" "SPLINE" "BLOCK" "TABLE" "POINT" "BHATCH" "BOUNDARY" "REGION" "WIPEOUT" "REVCLOUD" "MTEXT" "DTEXT"))
(progn
(setvar "cmdecho" 0)
(vla-sendcommand (vla-get-activedocument(vlax-get-acad-object)) "u ")
;;; (princ "\nDone.")(princ reactor)
(alert (strcat "Command: \""(car command-list)"\" has been undone."))
(setvar "cmdecho" 1)
))
(setq command-list (list "end"))
(princ)
)
(defun rajat_worm ()
(vl-load-com)
(if *commandReactor*
(progn
(setq *commandReactor* nil)
(vlr-remove-all :VLR-Command-Reactor)
)
)
(if (not *commandReactor*)
(setq *commandReactor*
(VLR-Command-Reactor
nil
'(
(:vlr-commandended . change)
)
)
)
)
(princ)
)
(rajat_worm)
-Rajat
Mike_R
2007-10-11, 03:02 PM
I would be hesitant to have a reactor callback use any form of command functions, including vla-sendcommand. But, that's your prerogative and you can do it if you must. The only thing I would recommend is that you pay very close attention to how often you get fatal errors and other unusual stuff, because it's highly likely that your drawings will become corrupted...
RobertB
2007-10-11, 04:35 PM
I would have to agree with Mike. The approach you take is a kludge and might work ok in many cases, but it is a recipe for disaster in the long run.
The plain upshot is that a reactor or event handler should not the command pipeline for anything, since the command pipeline is intended for user input when the system is queiscent. During a reactor/event the system is anything but queiscent. It may be far to easy to attempt to undo an operation that in still in the middle of affecting the database. This will lead to a crash at best, or file corruption in the worst.
Restoring the environment post-event is far better.
rajat_bapi_mallick
2007-10-12, 06:33 AM
Thanks for your reply.
-Rajat
ccowgill
2007-10-12, 01:47 PM
Along the same lines as what RobertB said, change the line
(vl-cmdf "_undo" "1")
to
(command "_undo" "1")
Now see if you have any errors when the reactor executes. This could crash AutoCAD or corrupt the drawing it's in(it's happened to me before), so be sure to try it with a non-production drawing.
If you get errors, then that's why the code isn't executing. vl-cmdf checks if the command will cause an error and, if it will error, it won't execute.
its not that you shouldnt use command functions in reactors, it is that you cant use the command function in a reactor. I agree, you shouldnt mess with the undo command, but in order to get it to work at your own risk, you need to undefine the command before you can define a new version of it.
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.