Jump to content

error: no function definition: nil


Recommended Posts

Posted

Hello you lovely people.

 

I understand that adding (princ) to the end of my routine should stop autocad trying to run the returned nil as a command however regardless of where I insert (princ) I do not seem to be able to achieve this. Could somebody please put me out of my misery and tell me where it should go.

 

n.b. I am aware that the routine is not great, using if where cond should be etc but please ignore that for now.

 

(defun c:NLPTEST ( / ssloc rowno floorcur wallsh roomsh windowsh windowscillh balcsh flooraod ssfloor sswalls ssrooms sswindosw sswindowscill ssbalcs setlaywall setlayroom setlaywindow setlaywindowcill setlaybalc sswallssolids sswindowssolids ssroomssolids ssrestsolids)
 (Setq ssloc (strcat (getvar 'dwgprefix) "Macro template.xlsx"))
 (setq rowno 5)
 (repeat 10
 (if (= (getCellsFunction ssloc "NLP Heights" (strcat "B" (itoa rowno))) nil)
   (setq rowno (+ rowno 1))
   (
 (setq floorcur (getCellsFunction ssloc "NLP Heights" (strcat "Y" (itoa rowno))))
 (setq wallsh (getCellsFunction ssloc "NLP Heights" (strcat "B" (itoa rowno))))
 (setq roomsh (getCellsFunction ssloc "NLP Heights" (strcat "C" (itoa rowno))))
 (setq windowsh (getCellsFunction ssloc "NLP Heights" (strcat "D" (itoa rowno))))
 (setq windowscillh (getCellsFunction ssloc "NLP Heights" (strcat "E" (itoa rowno))))
 (setq balcsh (getCellsFunction ssloc "NLP Heights" (strcat "I" (itoa rowno))))
 (setq flooraod (getCellsFunction ssloc "NLP Heights" (strcat "F" (itoa rowno))))
 (setq setlaywall (getCellsFunction ssloc "NLP Heights" (strcat "M" (itoa rowno))))
 (setq setlayroom (getCellsFunction ssloc "NLP Heights" (strcat "O" (itoa rowno))))
 (setq setlaywindow (getCellsFunction ssloc "NLP Heights" (strcat "Q" (itoa rowno))))
 (setq setlaywindowcill (getCellsFunction ssloc "NLP Heights" (strcat "S" (itoa rowno))))
 (setq setlaybalc (getCellsFunction ssloc "NLP Heights" (strcat "U" (itoa rowno))))
 (setq ssfloor (ssget "x" (list (cons 8 (vl-princ-to-string floorcur)))))
 (setq sswalls (ssget "x" (list (cons 8 (vl-princ-to-string setlaywall)))))
 (setq ssrooms (ssget "x" (list (cons 8 (vl-princ-to-string setlayroom)))))
 (setq sswindows (ssget "x" (list (cons 8 (vl-princ-to-string setlaywindow)))))
 (setq sswindowscill (ssget "x" (list (cons 8 (vl-princ-to-string setlaywindowcill)))))
 (setq ssbalcs (ssget "x" (list (cons 8 (vl-princ-to-string setlaybalc)))))
 (command "move" ssfloor "0,0,0" (strcat "0,0," (rtos flooraod)))
 (command "-layer" "s" setlaywall "")
 (command "extrude" sswalls "" wallsh)
 (command "-layer" "s" setlayroom "")
 (if (/= ssrooms nil)
   (  
 (command "extrude" ssrooms "" roomsh)
 ))
 (command "-layer" "s" setlaywindow "")
 (if (/= sswindows nil)
   (  
 (command "extrude" sswindows "" windowsh)
 ))
 (command "-layer" "s" setlaywindowcill "")
 (if (/= sswindowscill nil)
   (  
 (command "extrude" sswindowscill "" windowscillh)
 ))
 (command "-layer" "s" setlaybalc "")
 (if (/= ssbalcs nil)
   (  
 (command "extrude" ssbalcs "" balcsh)      
 ))
 (setq sswallssolids(ssget "x" (list (cons 8 (vl-princ-to-string setlaywall)))))
 (setq ssrestsolids(ssget "x" (list (cons 8 (vl-princ-to-string setlayroom)))))
 (command "-layer" "s" setlaywall "")
 (if (= ssrestsolids nil)
   (setq rowno (+ rowno 1))
   ((command "subtract" sswallssolids ssrestsolids)
   (setq rowno (+ rowno 1)))
   )
 )    
   )
   )
 )

 

I believe it is this line near the end that is returning the offending nil to the command line:

 

(

(command "extrude" ssbalcs "" balcsh)

))

 

Thanks

 

Steve

Posted

Sorted, I was obvs being a dumb@ss.

 

Added it here, which I thought I had tried already and it worked, sorry for wasting time but thanks for reading.

 

( 
(command "extrude" ssbalcs "" balcsh)
(princ)
))

Posted

After a cursory glance, change:

    (if (= ssrestsolids nil)
   (setq rowno (+ rowno 1))
   ((command "subtract" sswallssolids ssrestsolids)
   (setq rowno (+ rowno 1)))
   )

to:

(if (= ssrestsolids nil)
   (setq rowno (+ rowno 1))
   (progn
       (command "subtract" sswallssolids ssrestsolids)
       (setq rowno (+ rowno 1))
   )
)

Posted (edited)

Here, you had some lacks in the code... Lee is right, but it could be much cleaner...

(Your if statements are good - no need for cond if everything works as should...)

 

(defun c:NLPTEST (/              ssloc          rowno          floorcur       wallsh
                 roomsh         windowsh       windowscillh   balcsh         flooraod
                 ssfloor        sswalls        ssrooms        sswindosw      sswindowscill
                 ssbalcs        setlaywall     setlayroom     setlaywindow   setlaywindowcill
                 setlaybalc     sswallssolids  sswindowssolids               ssroomssolids
                 ssrestsolids
                )
 (setq ssloc (strcat (getvar 'dwgprefix) "Macro template.xlsx"))
 (setq rowno 5)
 (repeat 10
   (if (= (getCellsFunction ssloc "NLP Heights" (strcat "B" (itoa rowno))) "")
     (progn
       (setq rowno (+ rowno 1))
       (setq floorcur (getCellsFunction ssloc "NLP Heights" (strcat "Y" (itoa rowno))))
       (setq wallsh (getCellsFunction ssloc "NLP Heights" (strcat "B" (itoa rowno))))
       (setq roomsh (getCellsFunction ssloc "NLP Heights" (strcat "C" (itoa rowno))))
       (setq windowsh (getCellsFunction ssloc "NLP Heights" (strcat "D" (itoa rowno))))
       (setq windowscillh (getCellsFunction ssloc "NLP Heights" (strcat "E" (itoa rowno))))
       (setq balcsh (getCellsFunction ssloc "NLP Heights" (strcat "I" (itoa rowno))))
       (setq flooraod (getCellsFunction ssloc "NLP Heights" (strcat "F" (itoa rowno))))
       (setq setlaywall (getCellsFunction ssloc "NLP Heights" (strcat "M" (itoa rowno))))
       (setq setlayroom (getCellsFunction ssloc "NLP Heights" (strcat "O" (itoa rowno))))
       (setq setlaywindow (getCellsFunction ssloc "NLP Heights" (strcat "Q" (itoa rowno))))
       (setq setlaywindowcill (getCellsFunction ssloc "NLP Heights" (strcat "S" (itoa rowno))))
       (setq setlaybalc (getCellsFunction ssloc "NLP Heights" (strcat "U" (itoa rowno))))
       (setq ssfloor (ssget "_x" (list (cons 8 floorcur))))
       (setq sswalls (ssget "_x" (list (cons 8 setlaywall))))
       (setq ssrooms (ssget "_x" (list (cons 8 setlayroom))))
       (setq sswindows (ssget "_x" (list (cons 8 setlaywindow))))
       (setq sswindowscill (ssget "_x" (list (cons 8 setlaywindowcill))))
       (setq ssbalcs (ssget "_x" (list (cons 8 setlaybalc))))
       (if ssfloor
         (command "_.move" ssfloor "" "_non" "0,0,0" "_non" (strcat "0,0," flooraod))
       )
       (if sswalls
         (progn (command "_.-layer" "_s" setlaywall "") (command "_.extrude" sswalls "" wallsh))
       )
       (if ssrooms
         (progn (command "_.-layer" "_s" setlayroom "") (command "_.extrude" ssrooms "" roomsh))
       )
       (if sswindows
         (progn (command "_.-layer" "_s" setlaywindow "") (command "_.extrude" sswindows "" windowsh))
       )
       (if sswindowscill
         (progn (command "_.-layer" "_s" setlaywindowcill "") (command "_.extrude" sswindowscill "" windowscillh))
       )
       (if ssbalcs
         (progn (command "_.-layer" "_s" setlaybalc "") (command "_.extrude" ssbalcs "" balcsh))
       )
       (setq sswallssolids (ssget "_x" (list (cons 8 setlaywall))))
       (setq ssrestsolids (ssget "_x" (list (cons 8 setlayroom))))
       (command "_.-layer" "_s" setlaywall "")
       (if ssrestsolids
         (progn (command "_.subtract" sswallssolids ssrestsolids) (setq rowno (+ rowno 1)))
         (setq rowno (+ rowno 1))
       )
     )
   )
 )
 (princ)
)

Excel output of sub function is always in string format - no need for (vl-princ-to-string) and so on...

HTH.

Edited by marko_ribar
Posted

Another suggestion variables can be made on the fly and do not have to be hard coded so you could replace all the setq's with something similar to this example. Need to add the excel bit. Same with the 6 ssgets a bit easier using a list.

 

Sorry was a bit lazy as did not have the Macro xls to try it.

 

;by T.Willey at Augi.com
(setq VarList '("one" "two" "three")) ;variable name
(setq ValueList '(1 2 3)) ; matching values
(mapcar
'(lambda (a b)
(set (read a) b)
)
VarList
ValueList
)

 

Command: !one
1

Command: !two
2

Command: !three
3

Posted

BIGAL, this way is easier for the variables to be localised:

(defun test ( / syms vars one two three)
 (setq syms '(one two three))
 (setq vars '(1 2 3))
 (mapcar 'set syms vars)
)

Just copy the content of "syms" to be localised for the defun.

 

However I'd go with assoc list, like this:

(setq CellsL
 (mapcar
   '(lambda (x)
     (list (car x) (getCellsFunction ssloc "NLP Heights" (strcat (cadr x) (itoa rowno))) )
   )
   '(
     ("floorcur" "Y") ("wallsh" "B") ("roomsh" "C") ("windowsh" "D") ("windowscillh" "E") ("balcsh" "I")
     ("flooraod" "F") ("setlaywall" "M") ("setlayroom" "O") ("setlaywindow" "Q") ("setlaywindowcill" "S") ("setlaybalc" "U")  
   )
 )
)

 

And just acess the required variable like:

(cadr (assoc "setlaywall" CellsL))

Posted

Thanks Grr the code could be a lot shorter now. A simple method where you need to set a lot of variables.

Posted

Hi

 

Thanks for the responses:

 

Lee - Progn is something I need to look at a bit more carefully, now I understand it a little better it explains some issues in previous routines. Also big thanks for all the content and LISPs you have put out, I have found them immensely helpful while traversing the minefield that is AutoLISP.

 

Marco - Again thanks for taking the time to respond, I have tried the revised routine as you have posted it and although I get no error messages when running it doesn't seem to do anything.

 

Previously it would work until the break on error which highlighted the following:

 

( 
(command "extrude" ssbalcs "" balcsh) 
))

 

Now however there is no error but nothing happens, any idea why this might be?

 

Bigal/Grrr - Very useful info, will look to incorporate your suggestions in future however I am definitely a novice at the moment so just looking to get things working before I try and streamline them and confuse myself even further.

 

Just to note that I had misspelled one of the variables sswindosw should have been sswindows.

Posted

Now however there is no error but nothing happens, any idea why this might be?

...

 

It might be that B column of xlsx file is not empty and it suppose to be empty... So if (getCellsFunction) returns in first if condition not empty string ("") - maybe (getCellFunction) has in return somewhere (if (= rtn "") (setq rtn nil)) and ends with : rtn so that return would instead of "" be nil like in your posted code... So quick fix, but I don't suggest it is that you replace :

(if (= (getCellsFunction ssloc "NLP Heights" (strcat "B" (itoa rowno))) "")

with :

(if (null (getCellsFunction ssloc "NLP Heights" (strcat "B" (itoa rowno))))

But I'd rather go another way and change (getCellsFunction) to return 'STR like it should (if it's empty cell then "" should be return of (getCellsFunction) evaluation)...

Posted

Success!

 

Thanks for the help guys, managed to cobble together what I wanted from all the responses, probably didn't help that I didn't post the file or spreadsheet to properly explain what I was trying to achieve. On the off chance it helps anyone else the following routine works:

 

(defun c:LICHFIELDSTEST ( / ssloc rowno floorcur wallsh roomsh windowsh windowscillh balcsh flooraod ssfloor sswalls ssrooms sswindows sswindowscill ssbalcs setlaywall setlayroom setlaywindow setlaywindowcill setlaybalc sswallssolids sswindowssolids ssroomssolids ssrestsolids)
 (Setq ssloc (strcat (getvar 'dwgprefix) "Macro template.xlsx"))
 (setq rowno 5)
 (repeat 10
 (if (= (getCellsFunction ssloc "Lichfields Heights" (strcat "B" (itoa rowno))) nil)
   (setq rowno (+ rowno 1))
   (progn
 (setq floorcur (getCellsFunction ssloc "Lichfields Heights" (strcat "Y" (itoa rowno))))
 (setq wallsh (getCellsFunction ssloc "Lichfields Heights" (strcat "B" (itoa rowno))))
 (setq roomsh (getCellsFunction ssloc "Lichfields Heights" (strcat "C" (itoa rowno))))
 (setq windowsh (getCellsFunction ssloc "Lichfields Heights" (strcat "D" (itoa rowno))))
 (setq windowscillh (getCellsFunction ssloc "Lichfields Heights" (strcat "E" (itoa rowno))))
 (setq balcsh (getCellsFunction ssloc "Lichfields Heights" (strcat "I" (itoa rowno))))
 (setq flooraod (getCellsFunction ssloc "Lichfields Heights" (strcat "F" (itoa rowno))))
 (setq setlaywall (getCellsFunction ssloc "Lichfields Heights" (strcat "M" (itoa rowno))))
 (setq setlayroom (getCellsFunction ssloc "Lichfields Heights" (strcat "O" (itoa rowno))))
 (setq setlaywindow (getCellsFunction ssloc "Lichfields Heights" (strcat "Q" (itoa rowno))))
 (setq setlaywindowcill (getCellsFunction ssloc "Lichfields Heights" (strcat "S" (itoa rowno))))
 (setq setlaybalc (getCellsFunction ssloc "Lichfields Heights" (strcat "U" (itoa rowno))))
 (setq ssfloor (ssget "x" (list (cons 8 (vl-princ-to-string floorcur)))))
 (setq sswalls (ssget "x" (list (cons 8 (vl-princ-to-string setlaywall)))))
 (setq ssrooms (ssget "x" (list (cons 8 (vl-princ-to-string setlayroom)))))
 (setq sswindows (ssget "x" (list (cons 8 (vl-princ-to-string setlaywindow)))))
 (setq sswindowscill (ssget "x" (list (cons 8 (vl-princ-to-string setlaywindowcill)))))
 (setq ssbalcs (ssget "x" (list (cons 8 (vl-princ-to-string setlaybalc)))))
 (if ssfloor
         (command "_.move" ssfloor "" "0,0,0" (strcat "0,0," (rtos flooraod)))
       )
       (if sswalls
         (progn (command "_.-layer" "_s" setlaywall "") (command "_.extrude" sswalls "" wallsh))
       )
       (if ssrooms
         (progn (command "_.-layer" "_s" setlayroom "") (command "_.extrude" ssrooms "" roomsh))
       )
       (if sswindows
         (progn (command "_.-layer" "_s" setlaywindow "") (command "_.extrude" sswindows "" windowsh))
       )
       (if sswindowscill
         (progn (command "_.-layer" "_s" setlaywindowcill "") (command "_.extrude" sswindowscill "" windowscillh))
       )
       (if ssbalcs
         (progn (command "_.-layer" "_s" setlaybalc "") (command "_.extrude" ssbalcs "" balcsh))
       )
 (setq sswallssolids(ssget "x" (list (cons 8 (vl-princ-to-string setlaywall)))))
 (setq ssrestsolids(ssget "x" (list (cons 8 (vl-princ-to-string setlayroom)))))
 (command "-layer" "s" setlaywall "")
 (if (= ssrestsolids nil)
   (setq rowno (+ rowno 1))
   (progn
     (command "subtract" sswallssolids "" ssrestsolids "")
     (setq rowno (+ rowno 1))
     )
   )
 )
   )
   )
 )

 

One of the main offenders was the line (command "subtract" sswallssolids ssrestsolids ) which should have been (command "subtract" sswallssolids "" ssrestsolids "").

 

Thanks again all.

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