asd19400 发表于 2012-8-28 02:36
海盗哥,太牛了,求标注尺寸文字避让改进
哥,您用这个求助吧- (defun x_get_dxf (en n /)
- (cdr (assoc n (entget en)))
- )
- ;;;x_ssn函数(x_ssn ss)
- ;;;ss参数:选折集
- ;;;返回图元名表
- (defun x_ssn (ss / n lst)
- (repeat (setq N (sslength ss))
- (setq LST (cons (ssname SS (setq N (1- N))) LST))
- ) ;_ 结束repeat
- ) ;_ 结束defun
- ;;;修改组码en 图元名 num 组码 ch 修改为
- (defun ch_dxf (en num ch / old_num new_num ent)
- (if (setq ent (entget en)
- new_num (cons num ch)
- old_num (assoc num ent)
- ) ;_ 结束setq
- (entmod (subst new_num old_num ent))
- (entmod (reverse (cons new_num (reverse ent))))
- ) ;_ 结束if
- ) ;_ 结束defun
- ;;;获取尺寸图元文字中点坐标,文字宽度,文字角度,文字中点距线距离,图元名
- ;(dim_txt_data(car (entsel)))
- (defun dim_txt_data (dim_en / en pt1 pt2 ang pt3 dist)
- (setq en (cdr (assoc -2 (tblsearch "block" (x_get_dxf dim_en 2)))))
- ;获取尺寸块图元名
- (while (/= (x_get_dxf (setq en (entnext en)) 0) "MTEXT"))
- ;获取尺寸内文字图元名
- (setq pt1 (x_get_dxf dim_en 11);文字中点坐标
- pt2 (x_get_dxf dim_en 10);定义点
- ang (x_get_dxf en 50);角度
- pt3 (inters pt2 (polar pt2 ang 100) pt1 (polar pt1 (+ ang (/ pi 2)) 100) nil)
- dist (distance pt1 pt3)
- )
- (list pt1 (x_get_dxf en 42) ang dist dim_en)
- )
- ;;;表内元素两两组合
- ;;;(1 2 3) ((1 2)(2 3))
- (defun lst2&2 (olst / nlst)
- (repeat (1- (length olst))
- (setq nlst (cons (list (car olst) (cadr olst)) nlst))
- (setq olst (cdr olst))
- )
- (reverse nlst)
- )
- ;;;尺寸文字移动
- ;(setq en_data(cadr en_data_lst))
- (defun dim_txt_move (dis1 dis2 ang en_data / dis)
- (setq dis (- dis2 dis1))
- (ch_dxf
- (last en_data)
- 70
- (+ 128 (rem (x_get_dxf (last en_data) 70) 128))
- )
- (ch_dxf
- (last en_data)
- 11
- (polar (car en_data) ang dis)
- )
- )
- ;;;根据表内第一元素的xy排序
- (defun dim_sort (lst /)
- (setq lst (vl-sort lst (function (lambda (e1 e2) (< (car (car e1))(car (car e2)))))))
- (vl-sort lst (function (lambda (e1 e2) (< (cadr (car e1))(cadr (car e2))))))
- )
- (defun c:ttt()
- (setq ss(ssget '((0 . "DIMENSION"))) sc (getvar "userr1"))
- (vl-cmdf "_.dimedit" "_h" ss "")
- (setq en_data_lst (dim_sort(mapcar 'dim_txt_data (x_ssn ss))))
- (cond
- ((= (length en_data_lst) 2)
- (if (< (setq dis1(distance (car (nth 0 en_data_lst)) (car (nth 1 en_data_lst))))
- (setq dis2(+ (/ (cadr (nth 0 en_data_lst)) 2) (/ (cadr (nth 1 en_data_lst))2) sc))
- )
- (progn
- (dim_txt_move dis1 dis2 (+ (caddr (car en_data_lst)) pi) (car en_data_lst))
- (dim_txt_move dis1 dis2 (caddr (cadr en_data_lst)) (cadr en_data_lst))
- )
- )
- )
- ))
|