Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Lisp causing a ; error: bad function: 1

11 REPLIES 11
Reply
Message 1 of 12
cchiles
8051 Views, 11 Replies

Lisp causing a ; error: bad function: 1

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

Thanks in advance!
-Chris
Tags (3)
11 REPLIES 11
Message 2 of 12
_Tharwat
in reply to: cchiles

You should wrap the two system variables with progn function .

 

(progn
      (setvar "dimscale" 1)
       (setvar "ltscale" 1)
     )

 

Message 3 of 12
cchiles
in reply to: _Tharwat

Thanks Tharwat but now I'm getting: < bad function: 1 >
It's still working btw.
Thanks.
Thanks in advance!
-Chris
Message 4 of 12
_Tharwat
in reply to: cchiles

No it does not give any error now on my try , are there any other codes in the same routine ?
Message 5 of 12
alanjt_
in reply to: cchiles

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.))
    )
  )
)

 

Message 6 of 12
cchiles
in reply to: alanjt_

Thanks Alanjt - that's it.
There's always for than 1 way to skin a cat... or 1000 really.
Thanks in advance!
-Chris
Message 7 of 12
cchiles
in reply to: _Tharwat

@ 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 in advance!
-Chris
Message 8 of 12
alanjt_
in reply to: cchiles

Oh yes.

 

eg.

(defun ATSaveCommand (calling-reactor b)
  (if (wcmatch (car b) "*SAVE*")
    (mapcar 'vl-catch-all-apply '(setvar setvar) '((dimscale 1.) (ltscale 1.)))
  )
)

 

Message 9 of 12
_Tharwat
in reply to: cchiles


@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 Smiley Happy

 

Good luck

Message 10 of 12
Kent1Cooper
in reply to: cchiles


@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 Cooper, AIA
Message 11 of 12
cchiles
in reply to: Kent1Cooper

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.

Thanks in advance!
-Chris
Message 12 of 12
alanjt_
in reply to: cchiles


@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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost