Lisp lệnh TOADO TD trong chủ đề “các pro giúp mình sửa lisp này với”
mình có lisp xuất tọa độ này,nhưng tọa độ xuất ra là ở 1 block hơi xấu. mình muốn sửa việc xuất các thông số X, Y, tên nút ra block này, Cảm ơn mọi người https://www.cadviet.com/upfiles/3/117742_cm_1.dwg
;************************* Ch¬ng tr×nh chÝnh
(DEFUN C:TOADO()
(setq os (getvar "OSMODE"))
(command "UNDO" "G")
; T¹o kiÓu ch÷ míi
(setq cst (getvar "TEXTSTYLE"))
(command "STYLE" "VNARIALNARROW" ".VNARIAL NARROW" "" "" "" "" "")
; ThiÕt lËp kiÓu ghi kÝch thíc
(setvar "DIMASZ" 4);kÝch thíc mòi tªn
(setvar "DIMTXT" 4); kichs thíc ch÷
(setvar "DIMTAD" 0); ch÷ c©n gi÷a
; T×m khèi BANGTOADO (nÕu cha cã th× t¹o ra)
(if (not (tblsearch "BLOCK" "BANGTOADO"))
(progn
(setvar "OSMODE" 0)
(setq cla (getvar "CLAYER") cec (getvar "CECOLOR"))
(setvar "CLAYER" "0")
(setvar "CECOLOR" "BYBLOCK")
(setq ssline (ssadd))
(command "PLINE" '(0 0) '(30.5 0) '(30.5 13.5) '(0 13.5) "c")
(ssadd (entlast) ssline)
(command "LINE" '(7.5 0) '(7.5 13.5) "")
(ssadd (entlast) ssline)
(command "LINE" '(7.5 6.75) '(30.5 6.75) "")
(ssadd (entlast) ssline)
(command "CIRCLE" '(3.75 6.75) 3.5)
(ssadd (entlast) ssline)
(command "ATTDEF" "" "SH" "Sè hiÖu" "" "Middle" '(3.75 6.75) 4 0)
(setq ssatt_sh (ssadd))(ssadd (entlast) ssatt_sh)
(command "ATTDEF" "" "XXXXXX.XXXX" "To¹ ®é X" "" '(8.1 8.1) 4 0)
(setq ssatt_xx (ssadd))(ssadd (entlast) ssatt_xx)
(command "ATTDEF" "" "YYYYYY.YYYY" "To¹ ®é Y" "" '(8.1 1.1) 4 0)
(setq ssatt_yy (ssadd))(ssadd (entlast) ssatt_yy)
(command "BLOCK" "BANGTOADO" '(0 0) ssline ssatt_sh ssatt_xx ssatt_yy "")
(setvar "CLAYER" cla)(setvar "CECOLOR" cec)
);progn
);if
(if (not tenmocChinh)
(setq tenmocChinh "1")
);if
(if (not tenmocPhu)
(setq tenmocPhu "")
);if
(if (not tenmoc)
(setq tenmoc (strcat tenmocChinh tenmocPhu))
)
(if (not sle)
(setq sle 2)
);if
(if (not ShowMode)(setq ShowMode "X"))
(setq loop T)
(while loop
(setvar "OSMODE" os)
(initget "M T X L"); Mèc - Thêng - XÞn - Sè lÎ
(setq mark (getpoint (strcat "\nsè LÎ <" (itoa sle) ">/H×nh thøc (Thêng/XÞn) <" ShowMode ">/tªn Mèc <" tenmoc ">/<ChØ ®iÓm>: ")))
(cond
((= mark "M")
(setq tenmoc0 (getstring (strcat "\nTªn Mèc míi (theo d¹ng : 1, 1a, A, A1...) <" tenmoc ">: ")))
(if (/= tenmoc0 "")
(progn
; ph©n tÝch tªn mèc ®Ó nhËn biÕt chÝnh-phô
(tachMoc tenmoc0)
(if (or (>= (ascii tenmocChinh) 57)(<= (ascii tenmocChinh) 48)); mèc chÝnh lµ ch÷
(setq tenmocChinh (strcase tenmocChinh))
);if
(setq tenmoc (strcat tenmocChinh tenmocPhu))
);progn
);if
)
((= mark "T")
(setq ShowMode "T")
)
((= mark "X")
(setq ShowMode "X")
)
((= mark "L")
(setq sle0 (getint (strcat "\nSè ch÷ sè thËp ph©n (Tèi ®a=2; tèi thiÓu=0) <" (itoa sle) ">: ")))
(if sle0
(progn
(if (< sle0 0)(setq sle0 0))
(if (> sle0 2)(setq sle0 2))
(setq sle sle0)
);progn
);if
)
(T
(if mark
(progn
(cond
((= ShowMode "T");thêng
(setq toadoX (cadr (trans mark 1 0)))
(setq toadoY (car (trans mark 1 0)))
(setq p (getpoint mark "\nVÞ trÝ: "))
(setvar "OSMODE" 0)
(command "LEADER" mark p "" (rtos toadoX 2 sle) (rtos toadoY 2 sle) "")
;(command "PLINE" mark p "@11,0" "")
;(command "TEXT" (list (+ (car p) 0.5) (+ (cadr p) 0.5)) "" "0" (rtos toadoX 2 4))
;(command "TEXT" "TL" (list (+ (car p) 0.5) (- (cadr p) 0.5)) "" "0" (rtos toadoY 2 4))
)
((= ShowMode "X");XÞn
(setq toadoX (cadr (trans mark 1 0)))
(setq toadoY (car (trans mark 1 0)))
(setq p (getpoint mark "\nVÞ trÝ: "))
(setvar "OSMODE" 0)
(command "LEADER" mark p "" "" "Block" "BANGTOADO" p 1 1 0 tenmoc (rtos toadoX 2 sle) (rtos toadoY 2 sle))
; t¨ng gi¸ trÞ mèc
(tachmoc tenmoc)
(if (= tenmocPhu ""); kh«ng cã mèc phô
(if (and (<= (ascii tenmocChinh) 57)(>= (ascii tenmocChinh) 48)); mèc chÝnh lµ sè
(setq tenmoc (itoa (+ (atoi tenmocChinh) 1)))
(progn; else mèc chÝnh lµ ch÷
(setq tenmocASCII (+ (ascii tenmocChinh) 1))
(while (or (= (strcase (chr tenmocASCII)) "I")(= (strcase (chr tenmocASCII)) "O")
(= (strcase (chr tenmocASCII)) "V")(= (strcase (chr tenmocASCII)) "X")
(= (strcase (chr tenmocASCII)) "J"))
(setq tenmocASCII (+ tenmocASCII 1))
);while
(setq tenmoc (chr tenmocASCII))
);progn else
);if
;else cã mèc phô
(if (and (<= (ascii tenmocChinh) 57)(>= (ascii tenmocChinh) 48)); mèc chÝnh lµ sè (mèc phô lµ ch÷)
(progn
(setq tenmocASCII (+ (ascii tenmocPhu) 1))
(while (or (= (strcase (chr tenmocASCII)) "I")(= (strcase (chr tenmocASCII)) "O")
(= (strcase (chr tenmocASCII)) "V")(= (strcase (chr tenmocASCII)) "X")
(= (strcase (chr tenmocASCII)) "J"))
(setq tenmocASCII (+ tenmocASCII 1))
);while
(setq tenmocPhu (chr tenmocASCII))
(setq tenmoc (strcat tenmocChinh tenmocPhu))
);progn
(progn; else mèc chÝnh lµ ch÷ (mèc phô lµ sè)
(setq tenmocPhu (itoa (+ (atoi tenmocPhu) 1)))
(setq tenmoc (strcat tenmocChinh tenmocPhu))
);progn
);if
);if
)
);cond
(setvar "OSMODE" os)
);progn
(setq loop nil);else
);if
)
) ; end of cond
) ; end of while
(setvar "TEXTSTYLE" cst)
) ; end of program
(Defun C:TD()
(c:toado)
)
;******************************* Thèng kª *****************************************
(defun C:TK()
(command "UNDO" "G")
(setq tableStatus "")
(setq btk (ssget "X" '((2 . "BANGTHONGKE"))))
(if btk
(setq TableStatus "On Board")
(progn;else
(if (tblsearch "BLOCK" "BANGTHONGKE")
(setq TableStatus "Hiding Block")
(setq TableStatus "Doesn't Exist")
);if
);progn else
);if
(if (or (= TableStatus "Doesn't Exist") (= TableStatus "Hiding Block"))
(setq sp (getpoint "\nX¸c ®Þnh vÞ trÝ gãc trªn-tr¸i cña b¶ng: "))
(progn ;else (On Board)
(setq btk_name (ssname btk 0))
(setq btk_ent (entget btk_name))
(setq sp (cdr(assoc 10 btk_ent)))
);progn else
);if
(setq luuChu '() luuSo '())
(setq bang (ssget "X" '((2 . "BANGTOADO"))))
(if bang
(progn
(setq i 1 chu_i 1 so_i 1)
(repeat (sslength bang)
(setq b_i (ssname bang (- i 1)))
; doc doi tuong thuoc tinh SH
(setq bi_sh (entnext b_i))
(setq bi_sh_ent (entget bi_sh))
(setq sh (cdr(assoc 1 bi_sh_ent)))
; ®äc gi¸ trÞ toa ®é X
(setq bi_X (entnext bi_sh))
(setq bi_X_ent (entget bi_X))
(setq X (cdr(assoc 1 bi_X_ent)))
; ®äc gi¸ trÞ toa ®é Y
(setq bi_Y (entnext bi_X))
(setq bi_Y_ent (entget bi_Y))
(setq Y (cdr(assoc 1 bi_Y_ent)))
; cap nhat vao bang luu
(tachMoc sh)
(if (and (<= (ascii tenmocChinh) 57)(>= (ascii tenmocChinh) 48)); mèc chÝnh lµ sè
(progn
(setq luuSo (cons (list so_i sh X Y) luuSo))
(setq so_i (+ so_i 1))
);progn
(progn ; else mèc chÝnh lµ ch÷
(setq luuChu (cons (list chu_i sh X Y) luuChu))
(setq chu_i (+ chu_i 1))
)
);if
(setq i (+ i 1))
);repeat
; s¾p xÕp theo thø tù t¨ng dÇn cña sè hiÖu (SH) trong danh s¸ch luuChu
(setq i 1)
(while (<= i (- (length luuChu) 1))
(setq j (+ i 1))
(while (<= j (length luuChu))
(setq SH_tmpi (cadr (assoc i luuChu)))
(tachMoc SH_tmpi)
(setq SHi (ascii tenmocChinh))
(setq SH_tmpj (cadr (assoc j luuChu)))
(tachMoc SH_tmpj)
(setq SHj (ascii tenmocChinh))
(cond
((< SHj SHi); ch÷ sau cã m· ascii nhá h¬n sè tríc th× ®æi chç
(setq Xi (caddr (assoc i luuChu)))
(setq Yi (cadddr (assoc i luuChu)))
(setq Xj (caddr (assoc j luuChu)))
(setq Yj (cadddr (assoc j luuChu)))
(setq luuChu (subst (list i SH_tmpj Xj Yj) (assoc i luuChu) luuChu))
(setq luuChu (subst (list j SH_tmpi Xi Yi) (assoc j luuChu) luuChu))
)
((= SHj SHi); cïng tªn mèc - > kiÓm tra mèc phô
(tachMoc SH_tmpi)
(setq ChisoPhu_i tenmocPhu)
(tachMoc SH_tmpj)
(setq ChisoPhu_j tenmocPhu)
(if (< ChisoPhu_j ChisoPhu_i);sè sau nhá h¬n sè tríc th× ®æi chç
(progn
(setq Xi (caddr (assoc i luuChu)))
(setq Yi (cadddr (assoc i luuChu)))
(setq Xj (caddr (assoc j luuChu)))
(setq Yj (cadddr (assoc j luuChu)))
(setq luuChu (subst (list i SH_tmpj Xj Yj) (assoc i luuChu) luuChu))
(setq luuChu (subst (list j SH_tmpi Xi Yi) (assoc j luuChu) luuChu))
);progn
);if
)
);cond
(setq j (+ j 1))
);while j
(setq i (+ i 1))
);while i
; s¾p xÕp theo thø tù t¨ng dÇn cña sè hiÖu (SH) trong danh s¸ch luuSo
(setq i 1)
(while (<= i (- (length luuSo) 1))
(setq j (+ i 1))
(while (<= j (length luuSo))
(setq SH_tmpi (cadr (assoc i luuSo)))
(tachMoc SH_tmpi)
(setq SHi (atoi tenmocChinh))
(setq SH_tmpj (cadr (assoc j luuSo)))
(tachMoc SH_tmpj)
(setq SHj (atoi tenmocChinh))
(cond
((< SHj SHi); sè sau nhá h¬n sè tríc th× ®æi chç
(setq Xi (caddr (assoc i luuSo)))
(setq Yi (cadddr (assoc i luuSo)))
(setq Xj (caddr (assoc j luuSo)))
(setq Yj (cadddr (assoc j luuSo)))
(setq luuSo (subst (list i SH_tmpj Xj Yj) (assoc i luuSo) luuSo))
(setq luuSo (subst (list j SH_tmpi Xi Yi) (assoc j luuSo) luuSo))
)
((= SHj SHi); cïng tªn mèc - > kiÓm tra mèc phô
(tachMoc SH_tmpi)
(setq ChisoPhu_i (ascii tenmocPhu))
(tachMoc SH_tmpj)
(setq ChisoPhu_j (ascii tenmocPhu))
(if (< ChisoPhu_j ChisoPhu_i);ký tù sau cã m· ascii nhá h¬n sè tríc th× ®æi chç
(progn
(setq Xi (caddr (assoc i luuSo)))
(setq Yi (cadddr (assoc i luuSo)))
(setq Xj (caddr (assoc j luuSo)))
(setq Yj (cadddr (assoc j luuSo)))
(setq luuSo (subst (list i SH_tmpj Xj Yj) (assoc i luuSo) luuSo))
(setq luuSo (subst (list j SH_tmpi Xi Yi) (assoc j luuSo) luuSo))
);progn
);if
)
);cond
(setq j (+ j 1))
);while j
(setq i (+ i 1))
);while i
; bæ sung tiªu ®Ò vµo danh s¸ch
(setq luuChu (cons (list 0 "Mèc" "X" "Y") luuChu))
; KÎ b¶ng
(setq os (getvar "OSMODE"))
(setvar "OSMODE" 0)
(setq n (length luuChu) m (length luuSo))
(setq i 0 dem 0 test nil kc 15 objs (ssadd))
(repeat (+ n m)
(if (and (< dem n) (not test))
(setq luu luuChu test nil)
(progn
(setq luu luuSo)
(if (not test)
(setq test T dem 1)
);if
);progn
);if
; ghi so hieu
(setq start (list (car sp) (- (cadr sp) (* (getvar "TEXTSIZE") i 1.8))))
(command "TEXT" "M" start "" "" (cadr (assoc dem luu)))
(ssadd (entlast) objs)
; ghi X
(setq start (list (+ (car start) (/ kc 1.5)) (cadr start)))
(command "TEXT" "M" start "" "" (caddr (assoc dem luu)))
(ssadd (entlast) objs)
; ghi Y
(setq start (list (+ (car start) kc) (cadr start)))
(command "TEXT" "M" start "" "" (cadddr (assoc dem luu)))
(ssadd (entlast) objs)
; KÎ ®êng n»m ngang phÝa trªn
(command "LINE" (list (- (car sp) (/ kc 5)) (+ (cadr start) (* (getvar "TEXTSIZE") 0.9)))
"@35,0" "")
(ssadd (entlast) objs)
(setq i (+ i 1) dem (+ dem 1))
);repeat
;vex ddwowngf ker cuoois cungf
(command "LINE" (list (- (car sp) (/ kc 5)) (- (cadr start) (* (getvar "TEXTSIZE") 0.9)))
"@35,0" "")
(ssadd (entlast) objs)
;VÏ ®êng däc
(command "LINE" (list (- (car sp) (/ kc 5)) (+ (cadr sp) (* (getvar "TEXTSIZE") 0.9)))
(list (- (car sp) (/ kc 5)) (- (cadr start) (* (getvar "TEXTSIZE") 0.9))) "")
(ssadd (entlast) objs)
(command "LINE" (list (- (car sp) (/ kc 5) -35) (+ (cadr sp) (* (getvar "TEXTSIZE") 0.9)))
(list (- (car sp) (/ kc 5) -35) (- (cadr start) (* (getvar "TEXTSIZE") 0.9))) "")
(ssadd (entlast) objs)
(cond
((= TableStatus "On Board")
(COMMAND "BLOCK" "BANGTHONGKE" "Y" sp objs "")
)
((= TableStatus "Hiding Block")
(COMMAND "BLOCK" "BANGTHONGKE" "Y" sp objs "")
(command "INSERT" "BANGTHONGKE" sp "1" "1" "0")
)
((= TableStatus "Doesn't Exist")
(COMMAND "BLOCK" "BANGTHONGKE" sp objs "")
(command "INSERT" "BANGTHONGKE" sp "1" "1" "0")
)
);cond
(setvar "OSMODE" os)
);progn
);if
(command "UNDO" "E")
)
Tệp .lsp gốc không còn trên máy chủ. Hãy chép mã nguồn bên dưới (lấy từ bài viết gốc) vào một tệp văn bản, lưu với đuôi .lsp.
Cách dùng
- Chép mã nguồn, lưu thành tệp 229035_toado_td.lsp.
- Trong AutoCAD gõ lệnh APPLOAD, chọn tệp vừa tải rồi bấm Load. Cũng có thể kéo thả tệp .lsp vào cửa sổ bản vẽ.
- Gõ lệnh TOADO TD để chạy lisp.
Thảo luận gốc
Lisp được chia sẻ trong chủ đề các pro giúp mình sửa lisp này với. Xem đúng bài viết #229035 để đọc hướng dẫn và trao đổi thêm.