I have a reactor lisp that I've pieced together that is giving me slight problem. The lisp resets the variables "dimscale" & "ltscale" to 1 upon the user saving the drawing. I do this so that when we use our batch PDF creation tool (Acroplot) the linetypes will always be correct.
Anyways, the lisp works correctly but returns the following error: "; error: bad function: 1"
(defun AtSaveCommand (calling-reactor b) (if (or (= (car b) "QSAVE") (= (car b) "SAVEAS") (= (car b) "SAVE") ) (;;; ;;;=================================================== ;;; *** run your lisp from here ;;;=================================================== (setvar "dimscale" 1) (setvar "ltscale" 1) ;;;=================================================== ;;; *** to here ;;;=================================================== ) ) ) (defun loadTheSaveReactor () (vl-load-com) (if *FileOnSave* (vlr-remove *FileOnSave*)) (setq *FileOnSave* (vlr-command-reactor nil '((:vlr-commandwillStart . AtSaveCommand))) ) ) (loadTheSaveReactor)
Like I said, it works corrctley as I wish but it serves that error.
Can someone point out why this is happening?
Thanks for any help,
Chris
You should wrap the two system variables with progn function .
(progn (setvar "dimscale" 1) (setvar "ltscale" 1) )
While you do have some paren issues, this is a case where the dimscale refuses to be reset. I have seen it with civil 3d. Just catch the error and you will be fine:
(defun ATSaveCommand (calling-reactor b) (if (wcmatch (car b) "*SAVE*") (progn (vl-catch-all-apply 'setvar (list 'dimscale 1.)) (vl-catch-all-apply 'setvar (list 'ltscale 1.)) ) ) )
Oh yes.
eg.
(defun ATSaveCommand (calling-reactor b) (if (wcmatch (car b) "*SAVE*") (mapcar 'vl-catch-all-apply '(setvar setvar) '((dimscale 1.) (ltscale 1.))) ) )
@cchiles wrote:
@ Tharwat - after seeing Alanjt's note about the parenthesis, i went back my code and I had an extra set wrapping the "run your lisp here section" that was the problem. Removed those and that one works fine too.
Thanks for the heads up
Good luck
@cchiles wrote:
... i went back my code and I had an extra set wrapping the "run your lisp here section" that was the problem. Removed those and that one works fine too.
Really? I suspect that while it may not give you the error, it actually doesn't do what you want. The (setvar "dimscale" 1) would become the 'then' argument for the (if) function, and the (setvar "ltscale" 1) would become the 'else' argument. That means it would reset one of those but not the other, with which one it does depending on the result of the test for Save-related command names.
Kent,
I'm not very well versed here (which I suspect is obvious) but this code:
(defun AtSaveCommand (calling-reactor b) (if (or (= (car b) "QSAVE") (= (car b) "SAVEAS") (= (car b) "SAVE") ) ;;;=================================================== ;;; *** run your lisp from here ;;;=================================================== (progn (setvar "dimscale" 1) (setvar "ltscale" 1) ) ;;;=================================================== ;;; *** to here ;;;=================================================== ) ) (defun loadTheSaveReactor () (vl-load-com) (if *FileOnSave* (vlr-remove *FileOnSave*)) (setq *FileOnSave* (vlr-command-reactor nil '((:vlr-commandwillStart . AtSaveCommand))) ) ) (loadTheSaveReactor)
Does indeed do what I wish which is reseting Dimscale & LTscale to 1 upon save.
I've checked it now sseveral times.
Thanks.
@cchiles wrote:Kent,
I'm not very well versed here (which I suspect is obvious) but this code:
(defun AtSaveCommand (calling-reactor b) (if (or (= (car b) "QSAVE") (= (car b) "SAVEAS") (= (car b) "SAVE") ) ;;;=================================================== ;;; *** run your lisp from here ;;;=================================================== (progn (setvar "dimscale" 1) (setvar "ltscale" 1) ) ;;;=================================================== ;;; *** to here ;;;=================================================== ) ) (defun loadTheSaveReactor () (vl-load-com) (if *FileOnSave* (vlr-remove *FileOnSave*)) (setq *FileOnSave* (vlr-command-reactor nil '((:vlr-commandwillStart . AtSaveCommand))) ) ) (loadTheSaveReactor)Does indeed do what I wish which is reseting Dimscale & LTscale to 1 upon save.
I've checked it now sseveral times.
Thanks.
Likely it's because of the reason I stated earlier (precisely why I suggested catching the error). However, as Kent said, your code was flawed and neede the two setvar functions wrapped in a progn.