Hello Forum,
I have the following code to redefine a block after a command has ended:
(vl-load-com) ;********************************************************* (defun Redefine() (command "_.INSERT" "reactortest=reactortest" nil) (princ "Block redefined.") ) ;**************************************** (vlr-command-reactor nil '((:vlr-commandEnded . endCommand))) ;****************************************************** (defun endCommand (calling-reactor endcommandInfo / thecommandend) ; Get the name of the command. (setq thecommandend (nth 0 endcommandInfo)) ; Check name of the command. (cond ((= thecommandend "PLINE") (Redefine)) );cond (princ) );defun (princ)
It doesn't work because INSERT is an interactive function and can't be called while a reactor is active.
Is there another way to redefine a block that can be used in a reactor? The block is in one of the default search path's.
Thank you.
Solved! Go to Solution.
Solved by Ertqwa. Go to Solution.
Solved by jsowinski. Go to Solution.
You're right that you can't use (command) in a reactor. However, I've had some success using (vla-sendcommand). I'm using AutoCAD Architecture 2013 and I was able to redefine a test block. I changed the command line in your Redefine function. Update the block name where the text is red.
(defun Redefine(/ doc)
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(cond
((tblobjname "block" "reactortest")
(vla-sendcommand doc "-insert \"reactortest=reactortest\"\rY\r\003")) ; <<< REDEFINE A BLOCK? YES!
((vla-sendcommand doc "-insert \"reactortest=reactortest\"\r\003")) ; <<< INSERT A NEW BLOCK DEFINITION.
); _end cond
(princ "Block redefined.")
)
Hope that works for you.
Hi, great thanks.
I've found a piece of code (author Lee Mac) that also worked:
(defun ReDef ( block / *error* oc spc doc block ) (defun *error* ( msg ) (and oc (setvar 'CMDECHO oc)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ) ) (setq spc (if (or (eq AcModelSpace (vla-get-ActiveSpace (setq doc (vla-get-ActiveDocument (vlax-get-acad-object) ) ) ) ) (eq :vlax-true (vla-get-MSpace doc)) ) (vla-get-ModelSpace doc) (vla-get-PaperSpace doc) ) ) (setq oc (getvar 'CMDECHO)) (setvar 'CMDECHO 0) (if (setq block (findfile block)) (progn (vla-delete (vla-insertblock spc (vlax-3D-point '(0. 0. 0.)) block 1. 1. 1. 0. ) ) (vl-cmdf "_.attsync" "_N" (vl-filename-base block)) ) ) (setvar 'CMDECHO oc) (princ) )
Thanks.