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

; error: no function definition: nil

22 REPLIES 22
Reply
Message 1 of 23
Anonymous
1884 Views, 22 Replies

; error: no function definition: nil

Hello.

I worked with .lsp below about 4 years and now it's not working. I didn't change the file, that error just happened. What should I do to make it work with AutoCAD 2020?

(defun c:elen(/ fList firSet entSet filOut entList totLen)
  (vl-load-com)
  (setq fList '((-4 . "<OR")(0 . "*LINE")
      (0 . "CIRCLE")(0 . "ARC")
      (0 . "ELLIPSE")(-4 . "OR>")
      (-4 . "<NOT")(0 . "MLINE")
      (-4 . "NOT>"))
   filOut 0
   ); end setq
  (if
    (not
      (and
   (setq firSet(ssget "_I")
         entSet(ssget "_I" fList)
         ); end setq
   ); end and
      ); end not
    (setq entSet(ssget fList))
    (setq filOut(-(sslength firSet)(sslength entset)))
    ); end if
  (if entSet
    (progn
      (setq entList
      (mapcar 'vlax-ename->vla-object
                    (vl-remove-if 'listp
                     (mapcar 'cadr(ssnamex entSet))))
       totLen
        (apply '+
          (mapcar '(lambda (x)
                (vlax-curve-getDistAtParam x
             (vlax-curve-getEndParam x)))
             entList); end mapcar
          ); end apply
       ); end setq
      (if(/= 0 filOut)
   (princ(strcat "\n" (itoa filout)
            " were filtered out (unsupported type)"))
   ); end if
      (princ(strcat "\nTotal entities: "(itoa(length entList))
          " Total length: "(rtos totLen)); end strcat
       ); end princ
      ); end progn
    (progn
        (if(/= 0 filOut)
   (princ(strcat "\n" (itoa filout)
            " were filtered out (unsupported type)"))
   (princ "\nNothing selected")
   ); end if
    ); end progn
    ); end if
      (princ)
      ); end c:elen
22 REPLIES 22
Message 2 of 23
hak_vz
in reply to: Anonymous

@Anonymous 

What version of Acad you are using? Code looks OK and works well.

Try this

(defun c:elen(/ fList firSet entSet filOut entList totLen)
	(vl-load-com)
	(setq fList '((-4 . "<OR")(0 . "*LINE") (0 . "CIRCLE")(0 . "ARC") (0 . "ELLIPSE")(-4 . "OR>") (-4 . "<NOT")(0 . "MLINE") (-4 . "NOT>")))
	(setq filOut 0)
	(if(not(and(setq firSet(ssget "_I") entSet(ssget "_I" fList))))
		(setq entSet(ssget fList))
		(setq filOut(-(sslength firSet)(sslength entset)))
    )
	(if entSet
		(progn
			(setq 
				entList(mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr(ssnamex entSet))))
				totLen (apply '+ (mapcar '(lambda (x) (vlax-curve-getDistAtParam x (vlax-curve-getEndParam x))) entList))
			)
			(if(/= 0 filOut)
				(princ(strcat "\n" (itoa filout)" were filtered out (unsupported type)"))
				(princ(strcat "\nTotal entities: "(itoa(length entList))" Total length: "(rtos totLen)))
			)
		)
		(progn
			(if(/= 0 filOut)
				(princ(strcat "\n" (itoa filout) " were filtered out (unsupported type)"))
				(princ "\nNothing selected")
			)
		)
	)
	(princ)
)

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 3 of 23
Sea-Haven
in reply to: Anonymous

Maybe I am missing something (ssget '((0 . "*LINE,ARC,CIRCLE,ELLIPSE"))) will only get these type of objects.

Message 4 of 23
Kent1Cooper
in reply to: Anonymous

It's not clear to me from your description whether it was working in AutoCAD 2020 but has stopped working, or whether it was working in previous versions but has never worked in 2020.

 

By the way, though the question of selection-set filtering is probably irrelevant to the error message described, you can simplify that.  And you should omit XLINEs as well as MLINEs [your selection will find them, but the function to get their length will fail].  To find all finite (vlax-curve...)-class objects using *LINE to cover LINE/SPLINE/LWPOLYLINE/POLYLINE, but omitting XLINE & MLINE:


(ssget '((0 . "*LINE,ARC,CIRCLE,ELLIPSE") (-4 . "<NOT") (0 . "XLINE,MLINE") (-4 . "NOT>")))

Kent Cooper, AIA
Message 5 of 23
Anonymous
in reply to: hak_vz

I use 2020 and yours code didn't work as well 😞
Message 6 of 23
Anonymous
in reply to: Kent1Cooper

Worked in ACAD2020 and stopped work in ACAD2020. Where should I add this line?
Message 7 of 23
hak_vz
in reply to: Anonymous

test

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 8 of 23
hak_vz
in reply to: Anonymous

Try this but I doubt that problem is with selection filter

 

 

(defun c:elen(/ fList firSet entSet filOut entList totLen)
	(vl-load-com)
	(setq fList '((-4 . "<OR")(0 . "*LINE") (0 . "CIRCLE")(0 . "ARC") (0 . "ELLIPSE")(-4 . "OR>") (-4 . "<NOT")(0 . "MLINE,XLINE")(-4 . "NOT>")))
	(setq filOut 0)
	
	(if(not(and(setq firSet(ssget "_I") entSet(ssget "_I" fList))))
		(setq entSet(ssget fList))
		(setq filOut(-(sslength firSet)(sslength entset)))
    )
	(if entSet
		(progn
			(setq 
				entList(mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr(ssnamex entSet))))
				totLen (apply '+ (mapcar '(lambda (x) (vlax-curve-getDistAtParam x (vlax-curve-getEndParam x))) entList))
			)
			(if(/= 0 filOut)
				(princ(strcat "\n" (itoa filout)" were filtered out (unsupported type)"))
				(princ(strcat "\nTotal entities: "(itoa(length entList))" Total length: "(rtos totLen 2 2)))
			)
		)
		(progn
			(if(/= 0 filOut)
				(princ(strcat "\n" (itoa filout) " were filtered out (unsupported type)"))
				(princ "\nNothing selected")
			)
		)
	)
	(princ)
)

 

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 9 of 23
Anonymous
in reply to: hak_vz

Still doesn't work. Maybe I need to reinstall ACAD
Message 10 of 23
hak_vz
in reply to: Anonymous

I don' think you need  to reinstall if other lisps are working ok. We will find the problem but it needs some effort.

This error message appears in case when some of used function returns nil that compiler can recognize as function (nil). Maybe implied selection "_I" causes some error or these line has to be written again. There can be some other issues. Does this happen with all drawings or in some particular.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 11 of 23
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:
Worked in ACAD2020 and stopped work in ACAD2020. Where should I add this line?

So it is apparently not version-related.  Something else has changed.

 

You should be able to replace this:

 

(setq fList '((-4 . "<OR")(0 . "*LINE")
  (0 . "CIRCLE")(0 . "ARC")
  (0 . "ELLIPSE")(-4 . "OR>")
  (-4 . "<NOT")(0 . "MLINE")
  (-4 . "NOT>"))
  filOut 0
); end setq

 

with this:

 

(setq
  fList '((0 . "*LINE,ARC,CIRCLE,ELLIPSE") (-4 . "<NOT") (0 . "XLINE,MLINE") (-4 . "NOT>"))
  filOut 0
); end setq

 

But again, I don't see how that change could fix the error you're getting -- it's only a simplified selection-set filter list, and the error is not about selection.

Kent Cooper, AIA
Message 12 of 23
pbejse
in reply to: Anonymous


@Anonymous wrote:

Hello.

I worked with .lsp below about 4 years and now it's not working. I didn't change the file, that error just happened. What should I do to make it work with AutoCAD 2020?


There doesnt seem to be any obvious reason for the posted code to not work in 2020. 

Is there any lisp program that works on 2020? Are there any other programs loaded at startup? 

Did the error appeared after you run the program?

 

Judging by the error message, the program is trying to evaluate a variable with an undefined function

((if nil
  	princ po) "\nSay Hello to little friend")

Since po is not a defined function, that same error message will appear

 

To make it easy for everybody, debug the lisp code by using VLIDE

Command: VLIDE

Open the lisp file.

On the menu, go to Debug and choose Break on Error.

load the lisp via Ctrl+Alt+E <-- very important

 

Go back to Autocad drawing session and run your code. if theres an error, vlide will be activated.

To see where the error on the code, go to Debug / Last Break source, the line with error will be highlghted.

 

Otherwise just post a sample drawing where the code does not work.

 

Message 13 of 23
Anonymous
in reply to: pbejse

Broke on this:

 (mapcar 'vlax-ename->vla-object
                    (vl-remove-if 'listp
                     (mapcar 'cadr(ssnamex entSet))))
Message 14 of 23
Anonymous
in reply to: Kent1Cooper

Yeah, no fix 😞

Message 15 of 23
pbejse
in reply to: Anonymous

Lets test if we change the way the program iterates thru the selection

 

(defun c:elen(/ fList firSet entSet filOut entList totLen)
	(vl-load-com)
	(setq fList '((-4 . "<OR")(0 . "*LINE") (0 . "CIRCLE")(0 . "ARC")
		      (0 . "ELLIPSE")(-4 . "OR>") (-4 . "<NOT")(0 . "MLINE") (-4 . "NOT>")))
	(setq filOut 0 totLen 0)
	(if(not(and(setq firSet(ssget "_I") entSet(ssget "_I" fList))))
		 (setq entSet(ssget fList))
		(setq filOut(-(sslength firSet)(sslength entset)))
    )
	(if entSet
		(progn
		  (repeat (setq i (sslength entSet))
		    (setq e (ssname entSet (setq i (1- i))))
		    	(setq totLen (+ totLen (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e)))))
			(if(/= 0 filOut)
				(princ(strcat "\n" (itoa filout)" were filtered out (unsupported type)"))
				(princ(strcat "\nTotal entities: "(itoa(length entList))" Total length: "(rtos totLen)))
			)
		)
		(progn
			(if(/= 0 filOut)
				(princ(strcat "\n" (itoa filout) " were filtered out (unsupported type)"))
				(princ "\nNothing selected")
			)
		)
	)
	(princ)
)

 

if that fails, let see where or what object cause the error

 

(defun c:eDen (/ fList errors firSet entSet filOut entList totLen)
	(vl-load-com)
	(setq fList '((-4 . "<OR")(0 . "*LINE") (0 . "CIRCLE")(0 . "ARC")
		      (0 . "ELLIPSE")(-4 . "OR>") (-4 . "<NOT")(0 . "MLINE") (-4 . "NOT>")))
	(setq filOut 0 totLen 0)
	(if(not(and(setq firSet(ssget "_I") entSet(ssget "_I" fList))))
		 (setq entSet(ssget fList))
		(setq filOut(-(sslength firSet)(sslength entset)))
    )
	(if entSet
		(progn
		  (repeat (setq i (sslength entSet))
		    (setq e (ssname entSet (setq i (1- i)))
			  ent (entget e))
		    (print (Cdr (assoc 0 ent)))
		    (if (not (vl-catch-all-error-p
			  (Setq theLength (vl-catch-all-apply 'vlax-curve-getdistatparam
					    (list e (vlax-curve-getendparam e)))))
			     )
			(setq totLen (+ totLen theLength))
		      	(setq errors (cons (list (Cdr (assoc 0 ent))) errors)) 
		    )
		    )
			(if(/= 0 filOut)
				(princ(strcat "\n" (itoa filout)" were filtered out (unsupported type)"))
				(princ(strcat "\nTotal entities: "(itoa(length entList))" Total length: "(rtos totLen)))
			)
		)
		(progn
			(if(/= 0 filOut)
				(princ(strcat "\n" (itoa filout) " were filtered out (unsupported type)"))
				(princ "\nNothing selected")
			)
		)
	)(if errors (print errors))
   (princ)
)

 

command: Eden

 

 

Message 16 of 23
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

Broke on this:

 (mapcar 'vlax-ename->vla-object
                    (vl-remove-if 'listp
                     (mapcar 'cadr(ssnamex entSet))))

Again, this may not fix the problem, but I notice the fact that it's converting everything to VLA objects.  That's not necessary for what the routine does with them -- (vlax-curve...) functions can take just entity names, without conversion.  That much should be replaceable with just:

 

(vl-remove-if 'listp (mapcar 'cadr (ssnamex entSet)))

Kent Cooper, AIA
Message 17 of 23
Anonymous
in reply to: pbejse

OK, I tried some lines, plines and circle, got this:

Select objects: Specify opposite corner: 9 found
Select objects:
"LINE" ; error: no function definition: VLAX-CURVE-GETENDPARAM
Message 18 of 23
Anonymous
in reply to: Kent1Cooper

Tried, now this:

Command: ELEN
; error: no function definition: VLAX-CURVE-GETENDPARAM
Message 19 of 23
pbejse
in reply to: Anonymous


@Anonymous wrote:
Tried, now this:

Command: ELEN
; error: no function definition: VLAX-CURVE-GETENDPARAM

 

There's your answer.

 

This query by @Kent1Cooper  was never really confirmed by you @Anonymous 

- It's not clear to me from your description whether it was working in AutoCAD 2020 but has stopped working, or whether it was working in previous versions but has never worked in 2020.-

 

I guess it is now, the code at post # 1 clearly shows (vl-load-com) is loaded and should be working but the error that you get  right there shows otherwise.

 

That means the ActiveX function are not loaded despite you run (vl-load-com). Only a clean uninstall / reinstall of AutoCAD can solve your issue.

 

Message 20 of 23
jtoverka
in reply to: Anonymous

In your other lisps, are you using variables with the same name as a function?

If it worked before and over time now it doesn't, and you know for a fact that nothing changed, it's obviously not the code that it broke in. So why is everyone trying to change this code? lol


Look at the error, it says no function definition: nil

Well where did it break at? You cannot overwrite special form lisp functions.

So the following are the possibilities. Somewhere, one of these functions are used as variables and it got overwritten with nil.

 

;; ssget
;; sslength
;; mapcar
;; cadr
;; ssnamex
;; vl-remove-if
;; listp
;; vlax-curve-getDistAtParam
;; vlax-curve-getEndParam
;; itoa
;; strcat
;; length
;; rtos
;; +
;; /=
;; princ

 

 

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report