Brick_top Posted November 9, 2009 Share Posted November 9, 2009 Hi there, I have this code that I asked someone to write me a couple of years ago, and I don't even remember where I got in touch with him over the net I know how to use it and how some individual parts work. It makes a list of the vertices of a polyline. Could someone give me a detailed explantion of what it does exactly? (defun cdrs (key lst / pair rtn) (while (setq pair (assoc key lst)) (setq rtn (cons (cdr pair) rtn) lst (cdr (member pair lst)) ) ) (reverse rtn) ) thanks a lot! Quote Link to comment Share on other sites More sharing options...
JohnM Posted November 9, 2009 Share Posted November 9, 2009 ;;; its a sub-function for the bigger program ;;; when it is called you need to pass it 2 variables example: (cdrs 10 and the polyline list from the autolisp entget function) ;;; the variable KEY is the first item in a dotted pair like (10 100.500 200.600) ;;; the variable LST is the list of entity information like if you use (entget(entlast)) (defun cdrs (key lst / pair rtn) ;_while pair is not nil loop. (while (setq pair (assoc key lst)); pair = the first occurrence of the key item in the list (setq rtn (cons (cdr pair) rtn);_a list of the items are being made lst (cdr (member pair lst));_remaking the list to be passed back on the next loop ;;;with out the previous (assoc key lst) so it will get thew next item in the list );_setq );_while (reverse rtn);_flip the list so the fitst item the while loop retrives is now the first in the list );_defun ;;; this sub-function can be tested by the following call ;;; first draw a polyline then make the call (cdrs 10 (entget(entlast))) Quote Link to comment Share on other sites More sharing options...
Brick_top Posted November 9, 2009 Author Share Posted November 9, 2009 Thanks a lot, I'm going to read it Quote Link to comment Share on other sites More sharing options...
Brick_top Posted November 10, 2009 Author Share Posted November 10, 2009 I still don't understand how does the loop goes from the one code 10 to the next Sorry Quote Link to comment Share on other sites More sharing options...
VVA Posted November 10, 2009 Share Posted November 10, 2009 I still don't understand how does the loop goes from the onde code 10 to the next Sorry ;;; its a sub-function for the bigger program ;;; when it is called you need to pass it 2 variables example: (cdrs 10 and the polyline list from the autolisp entget function) ;;; the variable KEY is the first item in a dotted pair like (10 100.500 200.600) ;;; the variable LST is the list of entity information like if you use (entget(entlast)) (defun cdrs (key lst / pair rtn) ;_while pair is not nil loop. (while (setq pair (assoc key lst)); pair = the first occurrence of the key item in the list (setq rtn (cons (cdr pair) rtn);_a list of the items are being made lst (cdr ;_[color="Red"]2. Cdr find in 1. And save in lst variable ;_Next pass member find next code 10[/color] (member pair lst) ;[color="Red"]_1. Find first code 10[/color] ) ;_remaking the list to be passed back on the next loop ;;;with out the previous (assoc key lst) so it will get thew next item in the list );_setq );_while (reverse rtn);_flip the list so the fitst item the while loop retrives is now the first in the list );_defun ;;; this sub-function can be tested by the following call ;;; first draw a polyline then make the call (cdrs 10 (entget(entlast))) Another variant this function (defun pl-list-massoc (key alist) (mapcar 'cdr (vl-remove-if-not (function (lambda (x) (= key (car x)))) alist))) ;_ end of defun Use (vl-load-com)(pl-list-massoc 10 (entget(car(entsel "\nSelect a polyline:")))) Quote Link to comment Share on other sites More sharing options...
Brick_top Posted November 10, 2009 Author Share Posted November 10, 2009 Ok thanks a lot! I can understand it now 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.