warning: local variable used as function error

warning: local variable used as function error

stanovb
Advocate Advocate
2,179 Views
34 Replies
Message 1 of 35

warning: local variable used as function error

stanovb
Advocate
Advocate

I have some variables listed here.

stanovb_0-1661125611604.png

I then define the dialog box that works with this program:

stanovb_1-1661125748023.png

I then setup the various dialog box tiles:

stanovb_2-1661125851534.png

I then define the action tiles:

stanovb_3-1661125988459.png

I then have some if statement conditions where I remove some tabs & rename some other tabs based on what's selected in the dialog box. I had the dialog box working before but now i'm getting these errors.

; warning: local variable used as function: WALKUP
; warning: local variable used as function: RECTANGULAR
; warning: local variable used as function: PULLFORWARD
; warning: local variable used as function: WALKUP
; warning: local variable used as function: PULLFORWARD
; warning: local variable used as function: WALKUP
; warning: local variable used as function: DOORSCHED
; warning: local variable used as function: RECTANGULAR
; warning: local variable used as function: PULLFORWARD
; warning: local variable used as function: WALKUP
; warning: local variable used as function: DOORSCHED

 

I'm wondering if for some reason its not getting to the dialog definition. Some of the guys that helped me out before taught me how to set an alert to show where the program is getting to, maybe I can try that. This program works with my other thread that has a long message chain.

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/are-there-ang-good-tutorials-on-usin...

 

This is what defines the (= ln16 "SAO") variable. That works now, but I'm trying to get my updatecover routine working. This program looks at various elements & deletes & renames tabs based on selections that the user makes in "SAO select.DCL". I have an older routine that worked with some other project types & loads a different dialog box so the logic was working before.

 

I am trying to figure out what is making it say I'm using  a local variable as a function. I was trying to add onto an existing program but I must have something in there that's causing the error. i will post the updatecover file as well as the older version & also the dcl file. The 184kb file is the newer one. it should have the added variables listed at the top of this post. I hope this does not create a problem for anyone that looks at this.

0 Likes
2,180 Views
34 Replies
Replies (34)
Message 2 of 35

paullimapa
Mentor
Mentor

Your code should not have variables like walkup & RECTANGULAR looking like functions.

For example, these are all function call statements when surrounded with parentheses:

(walkup) 

(RECTANGULAR)

 

Another example:

(if (and(pullforward(walkup)(doorsched)(rectangular)))

 

Should be coded like this:

(if (and pullforward walkup doorsched rectangular)

 

Since (and) is a built-in lisp function call, that's surrounded by parentheses but the others are variables so they should not be.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 35

stanovb
Advocate
Advocate

Thanks for the tip. Still got some editing to do. Some of the sheets its deleting are wrong, but the error in question  is fixed. There is some code that needs to be edited for the correct sheets to be removed & renamed. The interesting thing is its running this code:

stanovb_0-1661137102677.png

Not sure why its going there.

0 Likes
Message 4 of 35

stanovb
Advocate
Advocate

hmm. it doesn't seem to like how I'm trying to combine an "and" statement with multiple "not" statements. I haven't found the right combination yet. Right now ive got:

(cond (and square (not doorsched)(not pullforward)(not walkup))
(PROGN
(command "layout" "d" "DM-100.00 (2)")
(command "layout" "d" "A-100.00 (2)")
(command "layout" "d" "A-100.00 (3)")
(command "layout" "d" "A-100.00 (4)")
(command "layout" "d" "A-100.00 (5)")
(command "layout" "d" "A-100.00 (6)")
(command "layout" "d" "A-100.00 (7)")
(command "layout" "d" "A-100.00 (8)")
(command "layout" "d" "A-100.00 (9)")
(command "layout" "d" "A-100.00 (10)")
(command "layout" "d" "A-201.00")
(command "layout" "d" "Brand Review (2)")
);end progn
)

 

I also tried:

(and rectangular (not doorsched)(not pullforward)(not walkup))

 

& ive tried:

(and rectangular (not (doorsched  pullforward  walkup)))

 

Its supposed to be leaving A-100.00, but its deleting it. Its supposed to deleting A-100.00 (9), A-100.00 (10), A-201.00, & Brand Review (2). It gives me an error :

 

Cannot find layout "DM-100.00 (2)", nothing deleted.
Cannot find layout "A-100.00 (2)", nothing deleted.
Cannot find layout "A-100.00 (3)", nothing deleted.
Cannot find layout "A-100.00 (4)", nothing deleted.
Cannot find layout "A-100.00 (6)", nothing deleted.
Cannot find layout "A-100.00 (7)", nothing deleted.
Cannot find layout "A-100.00 (8)", nothing deleted.
Unknown command "00".

0 Likes
Message 5 of 35

paullimapa
Mentor
Mentor

First of all, to test your combination, just do this at the Autocad command line.

Define square using something like (setq square 1).

Then test it at the command line by entering: (and square (not doorsched)(not pullforward)(not walkup))

If it returns T that means your combination worked because all the other variables have not been defined.

You can go one step further by defining one of the variables at the command line by entering: (setq walkup 1)

Then test it again at the command line by entering: (and square (not doorsched)(not pullforward)(not walkup))

If it returns nil then that confirms your combination is working.

Next as to why it's not working is the way you're using the (cond) function which is incorrect.

Since there's really only one condition you're testing, then use the (if) function:

(if (and square (not doorsched)(not pullforward)(not walkup))
(PROGN
(command "layout" "d" "DM-100.00 (2)")
(command "layout" "d" "A-100.00 (2)")
(command "layout" "d" "A-100.00 (3)")
(command "layout" "d" "A-100.00 (4)")
(command "layout" "d" "A-100.00 (5)")
(command "layout" "d" "A-100.00 (6)")
(command "layout" "d" "A-100.00 (7)")
(command "layout" "d" "A-100.00 (8)")
(command "layout" "d" "A-100.00 (9)")
(command "layout" "d" "A-100.00 (10)")
(command "layout" "d" "A-201.00")
(command "layout" "d" "Brand Review (2)")
);end progn
) ; end if

 

For multiple conditions then you use something like this:

(cond

((and (not doorsched)(not pullforward)(not walkup))
 ; place your code when this condition is met here

)

((not square)

 ; place your code when this condition is met here

)

(t

 ; when all conditions fail, place your code when this condition is met here

)

) ; end cond

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 6 of 35

stanovb
Advocate
Advocate

ok. Thanks for the tip again. yeah, I had the if function at first & it didn't seem like it wanted to work so I was trying something else.

0 Likes
Message 7 of 35

stanovb
Advocate
Advocate

I tried your suggestions & I got the expected results so I think that part of the code is probably ok. Something appears to be deleting the desired tabs before it gets to the code I'm writing now, because I get a message saying it cant find the tabs

Cannot find layout "DM-100.00 (2)", nothing deleted.
Cannot find layout "A-100.00 (2)", nothing deleted.
Cannot find layout "A-100.00 (3)", nothing deleted.
Cannot find layout "A-100.00 (4)", nothing deleted.
Cannot find layout "A-100.00 (6)", nothing deleted.
Cannot find layout "A-100.00 (7)", nothing deleted.
Cannot find layout "A-100.00 (8)", nothing deleted.
Unknown command "00". Press F1 for help.

 

Its also deleting some tabs that its not supposed to. One strange thing is it appears to be going to another block of code that it should be skipping because when Maryland is selected it runs this alert message.

stanovb_0-1661219997065.png

It should be skipping this because the alert message is within another if statement that's within a projectname variable. I do not know why its running this code.

stanovb_1-1661220242830.png

I added the variables to the watch window, but they seem to be still set to nil. That makes sense for some of them but square should be set to something because I selected it from the dialog box.

 

Maybe I should record another screencast. 

0 Likes
Message 8 of 35

paullimapa
Mentor
Mentor

Your If statement tests when = projectname then runs the (command "-layer.....code)

paulli_apa_0-1661238355570.png

But if doesn't = projectname will run everything after within (progn:

paulli_apa_1-1661238458498.png

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 9 of 35

stanovb
Advocate
Advocate

Thanks. I see what you mean. If I put that first command under the progn statement it should run everything when the projectname is true. I'm still not sure why its deleting the tabs its not supposed to, but ill keep trying. I might have to go back to the drawing board on this.

0 Likes
Message 10 of 35

stanovb
Advocate
Advocate

I think I figured it out. I'm not sure why, but it works with a nested if under the rectangular or square variable, but not just an and statement,

 

stanovb_0-1661304900773.png

 

0 Likes
Message 11 of 35

paullimapa
Mentor
Mentor
if it works....go for it!!!

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 12 of 35

stanovb
Advocate
Advocate

This is a tough one when you have two variables that you are trying to test if they are true. I got the one variable figured out but I'm trying to figure out how to code pullforward or walkup is true and (not doorsched) is true.

 

I got :

((and (or pullforward(not doorsched)walkup))


(PROGN
(command "layout" "d" "DM-100.00 (2)")
(command "layout" "d" "A-100.00")
(command "layout" "d" "A-100.00 (2)")
(command "layout" "d" "A-100.00 (3)")
(command "layout" "d" "A-100.00 (4)")
(command "layout" "d" "A-100.00 (6)")
(command "layout" "d" "A-100.00 (7)")
(command "layout" "d" "A-100.00 (8)")
(command "layout" "d" "A-100.00 (9)")
(command "layout" "d" "A-100.00 (10)")
(command "layout" "d" "Brand Review (2)")
(command "layout" "R" "A-100.00 (5)" "A-100.00")
);end progn
)

 

 

0 Likes
Message 13 of 35

paullimapa
Mentor
Mentor

Again run tests on the AutoCAD commandline:

(if (and(not doorsched)(or pullforward walkup)) ; test conditions

(progn....then your code when returns T) ; then

(progn...else your code when returns nil) ; else

) ; if

 

Sample Test cases:
(setq pullforward 1 walkup nil doorsched nil)
(and(not doorsched)(or pullforward walkup))

AutoCAD returns: T

 

(setq pullforward nil walkup 1 doorsched nil)
(and(not doorsched)(or pullforward walkup))

AutoCAD returns: T

 

(setq pullforward 1 walkup 1 doorsched nil)
(and(not doorsched)(or pullforward walkup))

AutoCAD returns: T

 

(setq pullforward nil walkup nil doorsched nil)
(and(not doorsched)(or pullforward walkup))

AutoCAD returns: nil

 

(setq pullforward 1 walkup 1 doorsched 1)
(and(not doorsched)(or pullforward walkup))

AutoCAD returns: nil

 

and etc.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 14 of 35

stanovb
Advocate
Advocate

so I copied this to the command line:

setq square 1 pullforward 1 walkup 1 doorsched nil)
(if square
(if(and(not doorsched)(or pullforward walkup))
(PROGN
(ALERT "Got to square not doorsched(or pullforward walkup)")
)
)
)

I get the the alert message so that makes me think that this logic works. When I run the program though I get:

; error: no function definition: nil

 

https://autode.sk/3AoqCC9

0 Likes
Message 15 of 35

paullimapa
Mentor
Mentor
Place an alert right before this sequence of code and see if it appears just so you know exactly where the problem occurs. Also don’t include parentheses in the alert message. Make it simple but include enough info so you know where the problem occurs

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 16 of 35

paullimapa
Mentor
Mentor
I see that you are missing an open parenthesis before setq square or is that a typo?

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 17 of 35

stanovb
Advocate
Advocate

its interesting that if I select square & I don't select walkup, & pullforward during the process it runs the code that its supposed to but I don't see the alert, but if I select pullforward or walkup I get the alert from the square no pullforward no walkup block of code but i get an error saying the function is not defined. This makes me think its not getting down there but the flow of the code is going through the other block of code. i know you told me to put it before the sequence but it seemed like it didn't run at all when i did that. By the way that was a typo before to answer your last post.

 

stanovb_0-1661623542108.png

 

0 Likes
Message 18 of 35

paullimapa
Mentor
Mentor

you have to be very careful how you are entering your code...look at these errors:

paulli_apa_0-1661626072114.png

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 19 of 35

stanovb
Advocate
Advocate

I've seen other conditional statements like that with the "and" keyword .

stanovb_3-1661627087311.png

 

 

 

That block of code seems to work. It at least it deletes & renames the right tabs. I was under the impression, the inside left parenthesis captures this: 

stanovb_0-1661626514017.png

and the outside parenthesis captures all of this:

stanovb_1-1661626643615.png

Am I wrong about that? I tried to do this with nested if statements, but as the conditions became  a little more complicated I had problems with it. I guess I'm not sure how to write a statement that has one variable being true with an "and" clause & an "or" clause all working together. I tried to google it, but but couldn't find one that was exactly what I'm trying to do.

0 Likes
Message 20 of 35

paullimapa
Mentor
Mentor

you are wrong...try the changes I told you first before you reply.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes