Jump to content

Bad function error for list creation


acab

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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: "" ". 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...