请帮我理解
您好,我有一段代码,几年前我请别人给我写的,我甚至不记得我在哪里通过网络与他联系过我知道如何使用它以及一些单独的部件是如何工作的。
它列出了多段线的顶点。
有人能给我详细解释一下它到底做什么吗?
(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) )
谢谢!
;;; 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 KEYis 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)))
非常感谢,我要读了 我仍然不明白循环是如何从一个代码10转到下一个代码10的
很抱歉
;;; 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 KEYis 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 ;_2. Cdr find in 1. And save in lst variable
;_Next pass member find next code 10
(member pair lst) ;_1. Find first code 10
)
;_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)))
此功能的另一个变体
(defun pl-list-massoc (key alist)
(mapcar 'cdr (vl-remove-if-not (function (lambda (x) (= key (car x)))) alist))) ;_ end of defun
使用
(vl-load-com)(pl-list-massoc 10 (entget(car(entsel "\nSelect a polyline:")))) 好的,非常感谢!我现在能理解了
页:
[1]