自己写了一段代码实现了想要的效果,谁有更好的方法,可以分享学习一下- ;;;*****标注文字偏移*****
- (defun c:d1 (/ ang d data ent f h lst pt11 pt13 pt14 scale str wide)
- (setvar "cmdecho" 0)
- (vl-load-com)
- ;;更新图元函数,这个是在论坛看到“G版”的函数修改的
- (defun f (dim postion layer)
- (setq el (entget dim)
- el (subst (cons 70 (logior 70 128)) (assoc 70 el) el) ;改变位置
- el (subst (cons 11 postion) (assoc 11 el) el) ;文字插入点
- el (subst (cons 8 layer) (assoc 8 el) el) ;图层
- )
- (entmod el)
- )
- ;;创建标注获取需要参数
- (command-s "DIMLINEAR" pause pause)
- (setq ent (entlast) data (entget ent))
- (setq str (rtos (cdr (Assoc 42 data)) 2 0))
- (setq h (Vlax-Get(Vlax-Ename->Vla-Object ent) 'TextHeight))
- (setq scale (getvar "DIMSCALE"))
- (setq h (* h scale))
- ;;获取标注文字的宽度
- (setq lst (textbox (list '(0 . "TEXT") (cons 1 str) (cons 40 h) (cons 41 0.7)))) ;字宽设置以为0.7
- (setq wide (abs (- (car (nth 0 lst)) (car (nth 1 lst)))))
- ;;取得需要改变位置的数值
- (setq pt11 (Cdr(Assoc 11 data)))
- (setq pt13 (Cdr(Assoc 13 data)))
- (setq pt14 (Cdr(Assoc 14 data)))
- (setq ang (Cdr(Assoc 50 data)))
- (if (= (fix ang) 1) (setq ang (* pi (/ 90 180.0))) (setq ang 0)) ;水平标注文字上移,数值标注文字右移
- (setq d (distance pt13 pt14))
-
- (f ent (polar pt11 ang (+ (/ wide 2) (/ d 2) (/ scale 2))) "Dim")
- (prin1)
- )
|