;| 2003/3/19 Locking AutoCAD LINEs by converting LINES into spacebar content text with underline and TXT.SHX style. Using the underline to simulate the native lines. Design Idea by Koz Jono Yeoh. Each version of AutoCAD has the same and most common text style file "TXT.SHX", so the underline texts can be displayed normally in most all AutoCAD platform. By doing so, the end point of lines can NOT be osnap by any AutoCAD (assistant) commands or methods. To convert back the underlines into common lines, we MUST run AutoCAD WMFOUT and WMFIN to make a back converting operation. Even in this case, the proper location can NOT be revived 100%. 2004/11/15 Enhanced version The new version can convert lines in block definition so that exploding the blocks will still get the text underlines instead of normal lines. 2005/03/24 Enhanced version Add option on exploding complex entities such as MTEXT/MLINE/DIMENSION/LWPOLYLINE |; (Defun C:AutoXLock (/ get-block-list GatherBlock txt2line mkstyle mkblock cmdecho osmode regen expert sset dxf8 ssp sn yn ssx blk conv ab expss expii n ) (Defun get-block-list (/ TempTablet TabletValue Rtn) (setq TempTablet (tblnext "Block" t)) (while TempTablet (setq TabletValue (cdr (assoc 2 TempTablet))) (if (/= (strcase "Block") "BLOCK") (setq Rtn (cons TabletValue rtn)) (if (null (wcmatch TabletValue "`**")) (setq Rtn (cons TabletValue rtn)) ) ) (setq TempTablet (tblnext "Block")) ) (if (= (strcase "Block") "LTYPE") (setq Rtn (append (list "BYLAYER" "BYBLOCK") Rtn ) ) ) (setq rtn (vl-remove "" rtn)) (if acad_strlsort (setq Rtn (acad_strlsort Rtn)) ) Rtn ) (Defun txt2line (Obj / DXF10 DXF11 DXF8 DXF62 Scale Rtn) (setq DXF8 (cdr (assoc 8 (entget Obj))) DXF10 (cdr (assoc 10 (entget Obj))) DXF11 (cdr (assoc 11 (entget Obj))) DXF10 (list (car DXF10) (cadr dxf10)) DXF11 (list (car DXF11) (cadr dxf11)) DXF62 (cdr (assoc 62 (entget Obj))) Scale (/ (distance DXF10 DXF11) 1.0) ) (if (or (null DXF62) (= DXF62 0)) (setq DXF62 (cdr (assoc 62 (tblsearch "Layer" DXF8)))) ) (if (entmake (list (cons 0 "INSERT") (cons 2 "TXT2LINE") (cons 8 "0") (cons 10 (polar DXF10 (angle DXF10 DXF11) (* 0.5 (distance DXF10 DXF11)) ) ) (cons 41 Scale) (cons 42 Scale) (cons 50 (angle DXF10 DXF11)) ) ) (progn (entdel Obj) (command "_.Explode" (entlast)) (command "_.Change" (setq rtn (entlast)) "" "_P" "_C" DXF62 "" ) ) ) rtn ) (Defun mkstyle (/ Rtn) (if (null (setq Rtn (tblsearch "Style" "XLOCK"))) (progn (command "_.Style" "XLOCK" "TXT.SHX") (while (/= (getvar "CmdNames") "") (command "")) ) ) (setq Rtn (tblsearch "Style" "XLOCK")) Rtn ) (Defun mkblock (/ Rtn) (if (null (setq Rtn (tblsearch "Block" "TXT2LINE"))) (progn (entmake (list (cons 0 "BLOCK") (cons 2 "TXT2LINE") (list 10 0.0 0.0 0.0) (cons 70 2) ) ) (entmake (list (cons 0 "TEXT") (cons 1 "%%U ") (cons 7 "XLOCK") (cons 8 "0") (list 10 -0.35 0.2 0.0) (cons 40 1.0) (cons 41 1.0) (cons 50 0.0) (cons 71 0) (cons 72 0) (cons 73 0) ) ) (entmake (list (cons 0 "ENDBLK"))) ) ) (setq Rtn (tblsearch "Block" "TXT2LINE")) Rtn ) (setq cmdecho (getvar "cmdecho") osmode (getvar "osmode") expert (getvar "expert") regen (getvar "regenmode") ) (setvar "cmdecho" 0) (setvar "osmode" 0) (setvar "regenmode" 0) (setvar "expert" 5) (if (mkstyle) (progn (repeat 3 (command "_.purge" "_block" "*" "_n")) (mkblock) (princ (if (= (getvar "SysCodePage") "ANSI_936") "\n 预处理复杂实体, 请等候..." "\n Exploding complex objects, please wait..." ) ) (if (and (setq expss (ssget "_x" (list (cons 0 "DIMENSION,MLINE,*POLYLINE") (cons 67 (abs (1- (getvar "tilemode")))) ) ) ) (setq expii -1) ) (repeat (sslength expss) (command "_.explode" (ssname expss (setq expii (1+ expii))) ) ) ) (if (and (setq expss (ssget "_x" (list (cons 0 "MTEXT") (cons 67 (abs (1- (getvar "tilemode")))) ) ) ) (setq expii -1) ) (repeat (sslength expss) (command "_.explode" (ssname expss (setq expii (1+ expii))) ) ) ) (princ (if (= (getvar "SysCodePage") "ANSI_936") (princ "完成!\n") (princ "Done!\n") ) ) (if (and (setq sset (ssget "_x" '((0 . "LINE")))) (setq n -1) ) (repeat (sslength sset) (if (= (getvar "SysCodePage") "ANSI_936") (princ (strcat "\r 正在转换 " (itoa (1+ (setq n (1+ n)))) "/" (itoa (sslength sset)) "; 请稍候......" ) ) (princ (strcat "\r Converting " (itoa (1+ (setq n (1+ n)))) " of " (itoa (sslength sset)) " lines, please wait......" ) ) ) (txt2line (ssname sset n)) ) ) (foreach blk (get-block-list) (command "_.insert" blk "0,0,0") (while (/= (getvar "cmdnames") "") (command "") ) (command "_.explode" (entlast)) (setq ssx (ssget "p") n -1 ssp (ssadd) ) (terpri) (if ssx (progn (repeat (sslength ssx) (if (= (getvar "SysCodePage") "ANSI_936") (princ (strcat "\r 转换图块[" blk "]内第[" (itoa (+ n 2)) "]个实体..." ) ) (princ (strcat "\r Processing " (itoa (+ n 2)) " nested objects in block " blk ) ) ) (setq sn (ssname ssx (setq n (1+ n)))) (if (= (cdr (assoc 0 (entget sn))) "LINE") (setq sn (txt2line sn) conv T ) ) (if sn (ssadd sn ssp) ) ) (if conv (command "_.Block" blk "0,0,0" ssp "") (command "_.erase" ssx "") ) (if (= (getvar "SysCodePage") "ANSI_936") (princ "完成!\n") (princ "Done!\n") ) ) ) ) ) ) (setvar "osmode" osmode) (setvar "expert" expert) (setvar "regenmode" regen) (setvar "cmdecho" cmdecho) (princ) ) (Defun C:XLock (/ get-block-list GatherBlock txt2line mkstyle mkblock cmdecho osmode regen expert sset dxf8 ssp sn yn ssx blk conv ab expss expii n ) (Defun get-block-list (/ TempTablet TabletValue Rtn) (setq TempTablet (tblnext "Block" t)) (while TempTablet (setq TabletValue (cdr (assoc 2 TempTablet))) (if (/= (strcase "Block") "BLOCK") (setq Rtn (cons TabletValue rtn)) (if (null (wcmatch TabletValue "`**")) (setq Rtn (cons TabletValue rtn)) ) ) (setq TempTablet (tblnext "Block")) ) (if (= (strcase "Block") "LTYPE") (setq Rtn (append (list "BYLAYER" "BYBLOCK") Rtn ) ) ) (setq rtn (vl-remove "" rtn)) (if acad_strlsort (setq Rtn (acad_strlsort Rtn)) ) Rtn ) (Defun txt2line (Obj / DXF10 DXF11 DXF8 DXF62 Scale Rtn) (setq DXF8 (cdr (assoc 8 (entget Obj))) DXF10 (cdr (assoc 10 (entget Obj))) DXF11 (cdr (assoc 11 (entget Obj))) DXF10 (list (car DXF10) (cadr dxf10)) DXF11 (list (car DXF11) (cadr dxf11)) DXF62 (cdr (assoc 62 (entget Obj))) Scale (/ (distance DXF10 DXF11) 1.0) ) (if (or (null DXF62) (= DXF62 0)) (setq DXF62 (cdr (assoc 62 (tblsearch "Layer" DXF8)))) ) (if (entmake (list (cons 0 "INSERT") (cons 2 "TXT2LINE") (cons 8 "0") (cons 10 (polar DXF10 (angle DXF10 DXF11) (* 0.5 (distance DXF10 DXF11)) ) ) (cons 41 Scale) (cons 42 Scale) (cons 50 (angle DXF10 DXF11)) ) ) (progn (entdel Obj) (command "_.Explode" (entlast)) (command "_.Change" (setq rtn (entlast)) "" "_P" "_C" DXF62 "" ) ) ) rtn ) (Defun mkstyle (/ Rtn) (if (null (setq Rtn (tblsearch "Style" "XLOCK"))) (progn (command "_.Style" "XLOCK" "TXT.SHX") (while (/= (getvar "CmdNames") "") (command "")) ) ) (setq Rtn (tblsearch "Style" "XLOCK")) Rtn ) (Defun mkblock (/ Rtn) (if (null (setq Rtn (tblsearch "Block" "TXT2LINE"))) (progn (entmake (list (cons 0 "BLOCK") (cons 2 "TXT2LINE") (list 10 0.0 0.0 0.0) (cons 70 2) ) ) (entmake (list (cons 0 "TEXT") (cons 1 "%%U ") (cons 7 "XLOCK") (cons 8 "0") (list 10 -0.35 0.2 0.0) (cons 40 1.0) (cons 41 1.0) (cons 50 0.0) (cons 71 0) (cons 72 0) (cons 73 0) ) ) (entmake (list (cons 0 "ENDBLK"))) ) ) (setq Rtn (tblsearch "Block" "TXT2LINE")) Rtn ) (setq cmdecho (getvar "cmdecho") osmode (getvar "osmode") expert (getvar "expert") regen (getvar "regenmode") ) (setvar "cmdecho" 0) (setvar "osmode" 0) (setvar "regenmode" 0) (setvar "expert" 5) (if (mkstyle) (progn (repeat 3 (command "_.purge" "_block" "*" "_n")) (mkblock) (initget "Yes No") (setq ab (getkword (if (= (getvar "SysCodePage") "ANSI_936") "\n 是否炸开复杂实体{多重文本/尺寸标注/多线段/多重直线} [是Yes/否No] :" "\n Explode complex MTEXT/MLINE/DIMENSION/POLYLINE [Yes/No] :" ) ) ) (initget "Yes No") (setq YN (getkword (if (= (getvar "SysCodePage") "ANSI_936") "\n 是否锁定图块内实体 (本操作将需要一些时间) [是Yes/否No] :" "\n Lock named blocks (This may take a while) [Yes/No] :" ) ) ) (if (not (equal ab "No")) (progn (princ (if (= (getvar "SysCodePage") "ANSI_936") "\n 预处理复杂实体, 请等候..." "\n Exploding complex objects, please wait..." ) ) (if (and (setq expss (ssget "_x" (list (cons 0 "DIMENSION,MLINE,*POLYLINE") (cons 67 (abs (1- (getvar "tilemode")))) ) ) ) (setq expii -1) ) (repeat (sslength expss) (command "_.explode" (ssname expss (setq expii (1+ expii))) ) ) ) (if (and (setq expss (ssget "_x" (list (cons 0 "MTEXT") (cons 67 (abs (1- (getvar "tilemode")))) ) ) ) (setq expii -1) ) (repeat (sslength expss) (command "_.explode" (ssname expss (setq expii (1+ expii))) ) ) ) (princ (if (= (getvar "SysCodePage") "ANSI_936") "完成!" "Done!" ) ) ) ) (princ (if (= (getvar "SysCodePage") "ANSI_936") "\n 请选择转换的直线 <无>:" "\n Select converted lines :" ) ) (if (setq sset (ssget (list (cons 0 "LINE")))) (progn (setq n -1) (repeat (sslength sset) (if (= (getvar "SysCodePage") "ANSI_936") (princ (strcat "\r 正在转换 " (itoa (1+ (setq n (1+ n)))) "/" (itoa (sslength sset)) "; 请稍候......" ) ) (princ (strcat "\r Converting " (itoa (1+ (setq n (1+ n)))) " of " (itoa (sslength sset)) " lines, please wait......" ) ) ) (txt2line (ssname sset n)) ) ) ) (if (not (equal YN "No")) (progn (foreach blk (get-block-list) (command "_.insert" blk "0,0,0") (while (/= (getvar "cmdnames") "") (command "") ) (command "_.explode" (entlast)) (setq ssx (ssget "p") n -1 ssp (ssadd) ) (terpri) (if ssx (progn (repeat (sslength ssx) (if (= (getvar "SysCodePage") "ANSI_936") (princ (strcat "\r 转换图块[" blk "]内第[" (itoa (+ n 2)) "]个实体..." ) ) (princ (strcat "\r Processing " (itoa (+ n 2)) " nested objects in block " blk ) ) ) (setq sn (ssname ssx (setq n (1+ n)))) (if (= (cdr (assoc 0 (entget sn))) "LINE") (setq sn (txt2line sn) conv T ) ) (if sn (ssadd sn ssp) ) ) (if conv (command "_.Block" blk "0,0,0" ssp "") (command "_.erase" ssx "") ) (if (= (getvar "SysCodePage") "ANSI_936") (princ "完成!\n") (princ "Done!\n") ) ) ) ) ) ) ) ) (setvar "osmode" osmode) (setvar "expert" expert) (setvar "regenmode" regen) (setvar "cmdecho" cmdecho) (princ) ) ;;; Codes for transfer between "%%U " and " " ;;; XL0: "%%U " => " " ;;; XL1: " " => "%%U " (Defun C:XL0 (/ sset n ent) (if (setq sset (ssget "x" (list (cons 0 "TEXT") (cons 1 "%%U ") (cons 7 "XLOCK")) ) ) (progn (setq n -1) (repeat (sslength sset) (setq ent (entget (ssname sset (setq n (1+ n)))) ent (subst (cons 1 " ") (assoc 1 ent) ent) ) (entmod ent) ) ) ) (princ) ) (Defun C:XL1 (/ sset n ent) (if (setq sset (ssget "x" (list (cons 0 "TEXT") (cons 1 " ") (cons 7 "XLOCK")) ) ) (progn (setq n -1) (repeat (sslength sset) (setq ent (entget (ssname sset (setq n (1+ n)))) ent (subst (cons 1 "%%U ") (assoc 1 ent) ent) ) (entmod ent) ) ) ) (princ) )