分享两个可以用到的自定义函数
 - ;表统计
- ;测试 (setq lst '(("a" 2) ( "b" 4) ("a" 5) ("c" 6) ("d" 9) ("c" 1) ("b" 4) ("r" 3) ("r" 3) ("a" 5) ))
- ;(XX-Lst-TongJi lst) 获取:'(("a" 12) ("b" 8) ("c" 7) ("d" 9) ("r" 6))
- (defun XX-Lst-TongJi(lst / rtn a b)
- (IF(= (type LST) 'LIST)
- (progn
- (while lst
- (setq a (car lst))
- (setq b nil)
- (foreach x lst
- (if (eq (car a) (car x));判断表中第一个的是否一样
- (setq b (cons (cdr x) b));把第二个组成表
- )
- )
- (setq b (reverse b))
- (setq b (apply 'mapcar (cons '+ b)));将第二个表的数值相加
- (setq rtn (cons (cons (car a) b) rtn));将每一个的第一个表与值的和组合
- (setq lst (vl-remove-if '(lambda (x) (= (car a) (car x))) lst))
- )
- (reverse rtn)
- )
- (princ "\n XX-Lst-TongJi 错了!")
- )
- )
 - ;功能:指定图元最小外接矩形的九点坐标 9点
- ;;;(xx-en--9pt 实体名 参数)
- ;上:7 8 9 中:4 5 6 下:1 2 3
- ;;;参数=1~9,上中下9位码;其他均为左下角点
- ;7 8 9
- ;4 5 6
- ;1 2 3
- (defun xx-en--9pt (s1 mode / dx dy point pointmax pointmin x1 x2 y1 y2)
- (cond
- ((and (= (type s1) 'ENAME)(= (type mode) 'INT))(setq s1 (vlax-ename->vla-object s1)))
- ((and (= (type s1) 'vla-object)(= (type mode) 'INT))(setq s1 s1))
- (t (princ "\n xx-en--9pt 错了!")(quit))
- )
- (vla-getboundingbox s1 'minpoint 'maxpoint)
- (setq pointmax (vlax-safearray->list maxpoint);取得第9点
- pointmin (vlax-safearray->list minpoint);取得第1点
- x1 (car pointmin)
- x2 (car pointmax)
- y1 (cadr pointmin)
- y2 (cadr pointmax)
- dx (/ (- x2 x1) 2.0)
- dy (/ (- y2 y1) 2.0)
- )
- (cond ((= mode 1) (setq point pointmin))
- ((= mode 2) (setq point (list (+ x1 dx) y1 0.0)))
- ((= mode 3) (setq point (list x2 y1 0.0)))
- ((= mode 4) (setq point (list x1 (+ y1 dy)0.0)))
- ((= mode 5) (setq point (list (+ x1 dx) (+ y1 dy)0.0)))
- ((= mode 6) (setq point (list x2 (+ y1 dy)0.0)))
- ((= mode 7) (setq point (list x1 y2 0.0)))
- ((= mode 8) (setq point (list (+ x1 dx) y2 0.0)))
- ((= mode 9) (setq point pointmax))
- (t (setq point pointmin))
- )
- point
- )
|