我把自己的代码和网上收集到的代码组合了下,想点选某个属性块里的属性值,得到属性标记及属性块名,然后再选择图中的属性块,再提取属性值,对属性值进行整理排序(去掉重复的属性值)
但得到的结果是 少了一个最小值的属性值
;;; 对属性值进行列表
(defun c:sxlb ( / cmd elist ename index jh lst n p qq rq ss test zhuty zity)
(setq cmd (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
(setq zity (cdr (assoc 2 (entget (car (setq qq (nentsel "\n请选择一个属性块中的属性:")))))))
(setq zhuty (cdr (assoc 2 (entget (cdr (assoc 330 (entget (car qq))))))))
(princ "\n选择要列表的属性块:")
(setq ss (ssget))
(setq p '())
(setq n (sslength ss))
(setq index (- n 1))
(repeat n
(setq ename (ssname ss index))
(setq elist (entget ename))
(if (and
(= "INSERT" (cdr (assoc 0 elist)))
(= zhuty (cdr (assoc 2 elist)))
)
(progn
(setq elist ename
test t
)
(while (and
test
(setq elist (entnext elist))
)
(setq lst (entget elist))
(cond ;
((= zity (cdr (assoc 2 lst)))
(progn
(setq jh (cdr (assoc 1 lst)))
(setq p (append
p
(list jh)
)
)
)
) ;
((= "SEQEND" (cdr (assoc 0 lst)))
(setq test nil)
)
)
) ;
) ;
)
(setq index (1- index))
)
(setq p (delsame p))
(setq p (vl-sort p '<))
(setq p (strsort p))
(setq n (vl-list-length p))
(setq index 1)
(repeat (- n 1)
(princ (nth index p))
(princ "\n")
(setq index (1+ index))
)
(princ "\n")
(princ)
)
;以下为表排序程序
(defun strsort (strlst)
(defun strbrk (str / i st1 n)
(setq i 0)
(while (not (or
(= "" (setq st1 (substr str (setq i (1+ i)))))
(setq n (distof st1))
)
)
)
(list (substr str 1 (1- i)) (if n
n
0
) str
)
)
(defun x-sort (lst do n)
(vl-sort lst '(lambda (x y)
((eval do) (nth n x)
(nth n y)
)
)
)
)
(mapcar
'last
(x-sort (x-sort (mapcar
'strbrk
strlst
) '< 1
) '< 0
)
)
)