text 改用 entmakex 之后
;绘制标注底线
(setq txtb (textbox (entget obj_txt)))
就出错。
- (defun C:pn3()
- (setq scale (getvar "dimscale")) ;获得全局比例
- ;;;(setq lg_layer "W_DIM");设置标注图层
- ;;; (setq txt_style "hztxt");立管标注样式
- (setq g_yesorno 1);设置是否编组,0-不编组,1-编组
- ;;;(setq txt_size (* scale 6)) ;设置标注文字高度
- (setq txt_off1 (* scale 1)) ;设置标注文字上移尺寸
- (setq txt_off2 (* scale 2)) ;设置标注文字左右移尺寸
- (setvar"cmdecho"0)
- (setq var_os (getvar "osmode"));记录捕捉
- (setq var_old_layer (getvar "clayer"));记录当前图层
- ;判断图层是否存在
- ;;;(if (= nil (tblsearch "layer" lg_layer)) (command "layer" "m" lg_layer ""))
- ;提示选择对象,获得选择点
- (setq inspt (osnap (cadr (entsel "\n选择标注对象")) "nea"))
- (while inspt
- (progn
- ;;; (setvar "clayer" lg_layer);设置当前图层
- (setvar "osmode" 0);取消捕捉
- (setq inspt1 (getpoint inspt "\n点取标注位置"))
- ;绘制连接线
- (command "line" inspt inspt1 "")
- (setq obj_line (entlast))
- (setq txt_name (getstring "\n标注内容: "))
- (setq ang (*(/ (angle inspt inspt1) pi) 180))
- (if (or (<= ang 90) (>= ang 270))
- (progn
- ;输入名称和编号
- ;;; (command "text" "J" "bl" inspt1 txt_size "0" txt_name)
- (entmakeX (list '(0 . "MTEXT")
- '(100 . "AcDbEntity")
- '(100 . "AcDbMText")
- '(70 . 0)
- '(71 . 7) ;;左对齐-下对齐
- '(72 . 1)
- '(73 . 2)
- (cons 40 (* scale 6))
- (cons 1 txt_name)
- (cons 10 inspt1)
- )
- )
-
- ;选择最后一个图元名
- (setq obj_txt (entlast))
- (command "move" obj_txt "" inspt1 (strcat "@" (rtos txt_off2) "," (rtos txt_off1)))
- ;绘制标注底线
- (setq txtb (textbox (entget obj_txt))) ;;;#### 这个如何改?####################
- ;得到文字长度
- (setq txt_l (- (caadr txtb) (caar txtb)))
- (command "line" inspt1 (strcat "@" (rtos (+ txt_l (* txt_off2 2))) ",0") "")
- (setq obj_line2 (entlast))
- )
- (progn
- ;输入名称和编号
- ;;; (command "text" "J" "br" inspt1 txt_size "0" txt_name)
- (entmakeX (list '(0 . "MTEXT")
- '(100 . "AcDbEntity")
- '(100 . "AcDbMText")
- '(70 . 0)
- '(71 . 9) ; 右对齐-下对齐
- '(72 . 1)
- '(73 . 2)
- (cons 40 (* scale 6))
- (cons 1 txt_name)
- (cons 10 inspt1)
- )
- )
- ;选择最后一个图元名
- (setq obj_txt (entlast))
- (command "move" obj_txt "" inspt1 (strcat "@-" (rtos txt_off2) "," (rtos txt_off1)))
- ;绘制标注底线
- (setq txtb (textbox (entget obj_txt))) ;;;#### 这个如何改?####################
- ;得到文字长度
- (setq txt_l (- (caadr txtb) (caar txtb)))
- (command "line" inspt1 (strcat "@-" (rtos (+ txt_l (* txt_off2 2))) ",0") "")
- (setq obj_line2 (entlast))
- )
- )
- (if (= g_yesorno 1) ;编组
- (progn
- ;建立选择集
- (setq obj_together (ssadd obj_txt (ssadd obj_line2 (ssadd obj_line))))
- ;生成匿名组
- (command "-group" "c" "*" "对象标注" obj_together "")
- )
- )
- (setvar "osmode" var_os);恢复捕捉
- (setvar "clayer" var_old_layer);恢复当前图层
- (princ)
- ;提示选择对象,获得选择点
- (setq inspt (osnap (cadr (entsel "\n选择标注对象")) "nea"))
- );end progn
- );end while
- (princ)
- )
|