kasra Posted April 23, 2010 Posted April 23, 2010 Hi all. I'm trying to get minimum and maximum values of x coordinate and y coordinate of a polyline in this code. but it returns this error: error: bad argument type: numberp: nil Can anyone tell me what is wrong?? thanks.... (DEFUN C:TEST (/ NOVERTEX ENTCNT) (SETQ SH (SSGET '((0 . "LWPOLYLINE")))) (SETQ NOVERTEX (CDR (ASSOC 90 (ENTGET (SSNAME SH 0))))) (SETQ VERTEXLISTX (LIST)) (SETQ VERTEXLISTY (LIST)) (FOREACH A (ENTGET (SSNAME SH 0)) (IF (= 10 (CAR A)) (PROGN (SETQ VERTEXLISTX (APPEND VERTEXLISTX (LIST (CADR A))) );_SETQ (SETQ VERTEXLISTY (APPEND VERTEXLISTY (LIST (CADDR A))) );_SETQ );_PROGN );_IF );_FOREACH (SETQ ENTCNT 0) (WHILE (<= (+ ENTCNT 1) NOVERTEX) (PROGN (SETQ MINX (MIN (NTH ENTCNT VERTEXLISTX) (NTH (+ ENTCNT 1) VERTEXLISTX))) (SETQ MAXX (MAX (NTH ENTCNT VERTEXLISTX) (NTH (+ ENTCNT 1) VERTEXLISTX))) (SETQ MINY (MIN (NTH ENTCNT VERTEXLISTY) (NTH (+ ENTCNT 1) VERTEXLISTY))) (SETQ MAXY (MAX (NTH ENTCNT VERTEXLISTY) (NTH (+ ENTCNT 1) VERTEXLISTY))) (SETQ ENTCNT (+ ENTCNT 1)) );_PROGN );_WHILE );_DEFUN Quote
jammie Posted April 23, 2010 Posted April 23, 2010 error: bad argument type: numberp: nil This happens when using (nth ) when the is outside the scope of a list Sample (setq tempList (list "abc" "def" "ghi")) (nth 4 tempList) On the final loop (WHILE (<= (+ ENTCNT 1) NOVERTEX) the error arrises at (SETQ MINX (MIN (NTH ENTCNT VERTEXLISTX) [color="Red"](NTH (+ ENTCNT 1) VERTEXLISTX)[/color])) Quote
jammie Posted April 23, 2010 Posted April 23, 2010 For an alternative method of sorting the points Swap (SETQ ENTCNT 0) (WHILE (<= (+ ENTCNT 1) NOVERTEX) (PROGN (SETQ MINX (MIN (NTH ENTCNT VERTEXLISTX) (NTH (+ ENTCNT 1) VERTEXLISTX))) (SETQ MAXX (MAX (NTH ENTCNT VERTEXLISTX) (NTH (+ ENTCNT 1) VERTEXLISTX))) (SETQ MINY (MIN (NTH ENTCNT VERTEXLISTY) (NTH (+ ENTCNT 1) VERTEXLISTY))) (SETQ MAXY (MAX (NTH ENTCNT VERTEXLISTY) (NTH (+ ENTCNT 1) VERTEXLISTY))) (SETQ ENTCNT (+ ENTCNT 1)) );_PROGN );_WHILE For (SETQ MINX (apply 'min VERTEXLISTX)) (SETQ MAXX (apply 'max VERTEXLISTX)) (SETQ MINY (apply 'min VERTEXLISTy)) (SETQ MAXY (apply 'max VERTEXLISTy)) Quote
kasra Posted April 23, 2010 Author Posted April 23, 2010 Dear jammie, So thanks for your complete guildance. Your alternative code is great. But there is one question: By increasing "entcnt" to 4, shouldn't the loop stop when (novertex=4)??? Quote
Kerry Brown Posted April 23, 2010 Posted April 23, 2010 By increasing "entcnt" to 4, shouldn't the loop stop when (novertex=4)??? Yes, The While loop stops when ( BUT, on the last run through, when you are dealing with the last vertex ; you use this (nth (+ ENTCNT 1) VERTEXLISTX) effectively asking for the index AFTER the last one ... Quote
Kerry Brown Posted April 23, 2010 Posted April 23, 2010 Just for comparison, perhaps have a look at something like this (defun c:doit (/ sh ll ur) (vl-load-com) (setq SH (ssget '((0 . "LWPOLYLINE")))) (vla-getboundingbox (vlax-ename->vla-object (ssname SH 0)) 'll 'ur ) (setq ll (vlax-safearray->list ll) ur (vlax-safearray->list ur) ) (alert (strcat "LowerLeft : " (vl-prin1-to-string ll) "\nUpperRight : " (vl-prin1-to-string ur) ) ) Quote
kasra Posted April 24, 2010 Author Posted April 24, 2010 OK. I'm so thankful about your description and altenative code. It is perfect and has a few arguman vs. my code. It is so faster by using activex functions. I hope that i learn this method as soon as possible. Quote
Recommended Posts
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.