;;以含有输入内容的文本坐标为基准,插入指定的图块;;主要语句取材chtext.lsp (defun c:Tb (/ last_o tot_o ent o_str n_str st s_temp n_slen o_slen si chf chm cont ans class ename sta_x sta_y pt name1 x_offset y_offset) ;; Select objects if running standalone (setq name1 nil) (if obj_block (progn (princ "\n请点选将要插入的块(默认块为<") (princ obj_block ) (princ ">):") ) (print "请点选将要插入的块:")) (while (= name1 nil) (progn (setq p1 (getpoint )) (if p1 (progn (setq name1 (ssname (ssget p1) 0)) (setq ent (entget name1)) (setq obj_block_temp (cdr (assoc 2 ent))) (if obj_block_temp (setq obj_block obj_block_temp) (print "没有图块被选中,重新选择") ) ) (if obj_block (setq name1 1)) ) ) ) (princ "\n\t你将插入的图块名称为:《") (PRINC obj_block) (princ "》") (princ "\n请框选作为基准坐标的文字范围") (setq objs (ssget (list(cons 0 "TEXT")(cons 100 "AcDbText")))) (setq chm 0) ;统计工作次数 (if objs (progn ;; If any objects selected (if (= (type objs) 'ENAME) ;如果objs为一个实体名 (progn (setq ent (entget objs)) ;将以OBJS为名的表抽出放入ENT (princ (strcat "\nExisting string: " (cdr (assoc 1 ent)))) ) ;搜出ENT中的文字内容 (if (= (sslength objs) 1) ;又或OBJS集合里只有一个内容 (progn (setq ent (entget (ssname objs 0))) ;将集里的东西的表抽出 (princ (strcat "\nExisting string: " (cdr (assoc 1 ent)))) ) ;将其文字内容搜出来 ) ) (setq o_str (getstring "\n匹配的字符内容 : " t)) ;匹配的字符内容输入! (setq x_offset 0 y_offset 0) (setq x_offset (getint "\n输入“X”偏移量(整数): ")) ;输(整数)! (setq y_offset (getint "\n输入“Y”偏移量(整数): ")) ;输(整数)! (if (= x_offset nil) (setq x_offset 0)) (if (= y_offset nil) (setq y_offset 0)) (setq o_slen (strlen o_str)) ;求输入的字长 (if (/= o_slen 0) ;字长为非0 (progn ;则 (setq last_o 0 tot_o (if (= (type objs) 'ENAME) ;tot_o设为集合的实体数量 1 (sslength objs) ) ) ;; For each selected object... (while (< last_o tot_o ) (setq ename (ssname objs last_o)) (setq class (cdr (assoc 0 (setq ent (entget ename))))) (if (or (= "TEXT" class) ;ENT为被动手术的表 (= "MTEXT" class) ) (progn (setq chf nil si 1) (setq s_temp (cdr (assoc 1 ent))) ;ENT中的文字内容 (while (= o_slen (strlen (setq st (substr s_temp si o_slen)))) (if (= st o_str) ;o_slen为输入旧的串的长 (progn ;比较! (setq chf t) ;; 标记Found old string (setq si (+ si o_slen)) ;指针往下跳 ) (setq si (1+ si)) ;若不同,则指针只跳一 ) ) (if chf (progn ;; 替代 new string for old ;; 开始插入块 (print "TEXT:") (print (cdr (assoc 1 ent))) (setq class (cdr (assoc 10 ent))) (setq sta_x (car class) sta_y (car (cdr class))) (setq sta_x (+ sta_x x_offset)) (setq sta_y (+ sta_y y_offset)) (setq pt (list sta_x sta_y)) (print "位置:") (print pt) (command "insert" obj_block pt "" "" "") (setq chm (1+ chm)) ;统计修改次数 ) ) ) ) (setq last_o (1+ last_o)) ;做下一个目标的手术 ) ) ;; else go on to the next line... ) ) ) (print) (if (/= (type objs) 'ENAME) ;; Print total lines changed (if (/= (sslength objs) 1) (princ (strcat (rtos chm 2 0) " 个图块插入")) ) ) (terpri))(PRINC "\n\t Insert the block on the text you select.")(princ "\n\tTB command loaded.")(princ)

评论