Bill Tillman Posted March 15, 2017 Share Posted March 15, 2017 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. Quote Link to comment Share on other sites More sharing options...
Grrr Posted March 15, 2017 Share Posted March 15, 2017 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. Quote Link to comment Share on other sites More sharing options...
Stefan BMR Posted March 16, 2017 Share Posted March 16, 2017 (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) ) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted March 16, 2017 Share Posted March 16, 2017 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 "") ) Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted March 16, 2017 Share Posted March 16, 2017 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 Quote Link to comment Share on other sites More sharing options...
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.