以下是一个示例程序,它演示了如何使用Autolisp计算给定块中属性的数量和值:
(defun c:test ()
(setq blk_ent (car (entsel "\nSelect block: ")))
(setq blk_att_list (mapcar 'cdr (vl-remove-if-not '(lambda (x) (eq (type x) 'ENAME))) (entget blk_ent)))
(setq att_list (vl-remove-if-not '(lambda (x) (and (eq (type x) 'LIST) (eq (car x) 2))) blk_att_list))
(setq num_atts (length att_list))
(setq att_values (mapcar 'cadr att_list))
(setq att_value_sum (apply '+ att_values))
(setq att_value_average (/ att_value_sum num_atts))
(princ (strcat "\nNumber of attributes: " (rtos num_atts) "\nTotal attribute value: " (rtos att_value_sum) "\nAverage attribute value: " (rtos att_value_average))))
这个程序会提示用户选择一个块,并计算该块中属性的数量、总值和平均值。