Jump to content
acab

Bad function error for list creation

Recommended Posts

acab

Hi there, I've been getting a "Bad function: "" Cannot invoke command from error" message every time I try to create a list. Currently I'm trying to use the vla-getboundingbox method to get the max and min of an object and can use those two points normally to draw a line. The code just stops working when I begin defining a list.

(vla-getboundingbox (vlax-ename->vla-object  newobj) 'minpoint 'maxpoint)
(setq minpoint (vlax-safearray->list minpoint)
maxpoint (vlax-safearray->list maxpoint))
(command "LINE" maxpoint minpoint "")
(setq xval (- (car maxpoint) (car minpoint))
yval (- (cadr maxpoint) (cadr maxpoint))
corner1 (list (car maxpoint) (cadr minpoint))
corner2 (list (car minpoint) (cadr maxpoint)))

If anyone could tell me what I'm doing wrong, that would be great.

Share this post


Link to post
Share on other sites
Lee Mac

The snippet of code you have posted looks syntactically correct to me.

 

Is that the exact error message that you are receiving?

 

A 'bad function' error indicates that you are trying to evaluate a non-function symbol as a function, typically arising when you have a literal list that isn't quoted (you may refer to my Error Message Troubleshooter for more information).

 

Alternatively, you could follow the first section of this tutorial to ascertain the exact expression at which the code fails.

Share this post


Link to post
Share on other sites
acab
10 hours ago, Lee Mac said:

The snippet of code you have posted looks syntactically correct to me.

 

Is that the exact error message that you are receiving?

  

A 'bad function' error indicates that you are trying to evaluate a non-function symbol as a function, typically arising when you have a literal list that isn't quoted (you may refer to my Error Message Troubleshooter for more information).

 

Alternatively, you could follow the first section of this tutorial to ascertain the exact expression at which the code fails.

 

I got rid of the previous list and instead went for 

(vla-getboundingbox (vlax-ename->vla-object  newobj) 'minpoint 'maxpoint)
(setq minpoint (vlax-safearray->list minpoint)
maxpoint (vlax-safearray->list maxpoint))
(command "LINE" maxpoint minpoint "")
(setq xval (- (car maxpoint) (car minpoint))
yval (- (cadr maxpoint ) (cadr minpoint)))
(setq lst (list (1 2 3)))

and the exact error message I'm getting is "bad function: 1" which I guess means that it interprets the 1 as a function when it shouldn't. 

Share this post


Link to post
Share on other sites
Lee Mac
18 minutes ago, acab said:

 

I got rid of the previous list and instead went for 


(vla-getboundingbox (vlax-ename->vla-object  newobj) 'minpoint 'maxpoint)
(setq minpoint (vlax-safearray->list minpoint)
maxpoint (vlax-safearray->list maxpoint))
(command "LINE" maxpoint minpoint "")
(setq xval (- (car maxpoint) (car minpoint))
yval (- (cadr maxpoint ) (cadr minpoint)))
(setq lst (list (1 2 3)))

and the exact error message I'm getting is "bad function: 1" which I guess means that it interprets the 1 as a function when it shouldn't. 

 

Exactly, the list should be:

(setq lst (list 1 2 3))

Or, as a literal:

(setq lst '(1 2 3))

 

Share this post


Link to post
Share on other sites
acab
2 minutes ago, Lee Mac said:

 

Exactly, the list should be:


(setq lst (list 1 2 3))

Or, as a literal:


(setq lst '(1 2 3))

 

My error prompt then becomes "bad function: "" ". 

Share this post


Link to post
Share on other sites
Grrr
18 minutes ago, acab said:

and the exact error message I'm getting is "bad function: 1" which I guess means that it interprets the 1 as a function when it shouldn't. 

 

In lisp the basic syntax to call a function is this:

(<CallMyFunction> <argument1> <argument2>...) ; any amount of arguments
; or just:
(<CallMyFunction>) ; without any arguments

; Then you can stack the function calls:
(<CallMyFunction3> (<CallMyFunction2> (<CallMyFunction1>)))
; Where first will run the <CallMyFunction1>, then <CallMyFunction2> that will use the arguments from the previous one
; hence it will return arguments for <CallMyFunction3>, which will run last and will return the last processed result

So you have a function and any amount of arguments (including none).

When you add ' (apostrophe) infront of the brackets that gives a totally different meaning to the expression - I call it "unevaluated list", Lee calls it "literal expression"

And as you see if you don't have anything infront of the opening bracket, this would mean that you are trying to call a function. (not in all cases, but in most (cond))

 

To sum up, you tried calling a function 1, with arguments 2 and 3, then the result of it to be included in the new list via list function:

(setq lst (list (1 2 3)))

So don't play with your brackets just like that! *slapping through the typing hands* :D

 

Also you might want to check this tutorial

Share this post


Link to post
Share on other sites
acab

@Grrr @Lee Mac Thanks for the help with the brackets. I don't know what was causing the other "Bad Function: "" " error but after I restarted my autoCAD I was able to define lists again. No idea why I was having problems. 

Share this post


Link to post
Share on other sites
Lee Mac
12 hours ago, acab said:

@Grrr @Lee Mac Thanks for the help with the brackets. I don't know what was causing the other "Bad Function: "" " error but after I restarted my autoCAD I was able to define lists again. No idea why I was having problems. 

 

The likely issue is that you have another program redefining a standard function to the empty string, e.g.

(setq car "")

(Don't do this)

Edited by Lee Mac

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×