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
@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
Maybe I am missing something (ssget '((0 . "*LINE,ARC,CIRCLE,ELLIPSE"))) will only get these type of objects.
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>")))
test
Miljenko Hatlak
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
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
@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.
@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.
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
@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)))
@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.
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.