Jump to content

Recommended Posts

Posted

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

Posted
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]))

Posted

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

Posted

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)???

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

Posted

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

Posted

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.

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