Jump to content

Building a Point List


Bill Tillman

Recommended Posts

I haven't tried this in a while but what I need to do is to build a list of points which can be used to construct a polyline.

(setq pt1 '(0.0 0.0)
       pt1 (append pt1 (list (car pt1) (+ (cadr pt1 12)))
       pt1 (append pt1 (list (+ (car pt1 12) (+ (cadr pt1) 12)))
       )

But I'm not ending up with what I was intending to, which is

((0.0 0.0) (0.0 12.0) (12.0 12.0))
And this then begs the question, is it better to assembly a list of lists or just a list of the car/cadr of each point
(0.0 0.0 0.0 12.0 12.0 12.0)
When it's said and done I want to use entmake to construct the polyline using the points list.
Link to comment
Share on other sites

Here are 2 common ways to construct a list:

(defun test ( / p pL ) ; #1
 (while (setq p (getpoint "\nSpecify point: "))
   (setq pL (cons p pL)) ; items are collected in reverse order
 )
 (reverse pL)
)

(defun test ( / p pL ) ; #2
 (while (setq p (getpoint "\nSpecify point: "))
   (setq pL (append (list p) pL)) ; items are collected in order
 )
)

As for the polyline emaking, check this thread.

Link to comment
Share on other sites

(append list1 list2) is adding each element of list2 to the end of list1

Observe each or this sample:

(append (list 1) (list 2))                   -> (1 2) 
(append (list 1 2) (list 3 4))               -> (1 2 3 4)
(append (list (list 1 2)) (list (list 3 4))) -> ((1 2) (3 4))

If you want a list of points, you have to feed the append function with lists of points, each point being a list of numbers (X, Y coordinates). In your sample, all lists are list of numbers.

 

These 2 samples are equivalent:

(setq pt1 '((0.0 0.0))
     pt1 (append pt1 (list (list (caar pt1) (+ (cadar pt1) 12))))
     pt1 (append pt1 (list (list (+ (caar pt1) 12) (+ (cadar pt1) 12))))
)

(setq pt1 '((0.0 0.0))
     pt1 (cons (mapcar '+ (car pt1) '(0.0 12.0)) pt1)
     pt1 (cons (mapcar '+ (car pt1) '(12.0 0.0)) pt1)
     pt1 (reverse pt1)
)

Link to comment
Share on other sites

The next step if you dont have it pretty sure something like this

 

(command "_pline")
(while (= (getvar "cmdactive") 1 ) 
(repeat (setq x (length lst))
(command (nth (setq x (- x 1)) lst))
)
(command "")
)

Link to comment
Share on other sites

IMO prefer this

'((0.0 0.0) (0.0 12.0) (12.0 12.0))

easier to manipulate by

repeat

while

mapcar

nth

foreach

vl-sort

or transpose etc.. (pls name it if missing)

 

LISt Process

in short LeeSP :P

Link to comment
Share on other sites

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