Lisp lệnh MT trong chủ đề “vẽ đường chú thích thanh thép (đường mũi tên chỉ)”
Đã chỉnh sửa theo ý bạn
Song, như vậy là nếu thép nằm ở nhiều layer thì phải ghi nhiều lần, OK !
Cad 2015 mình ko cài nên ko biết, mình 2014 chạy rầm rầm :D :D :D
>>> Đây bạn:
P/s: Đã chỉnh sửa (khai thêm biến cục bộ cho đủ) lúc 16h26 ngày 21/10/2014_Nếu cdhn đã lỡ down thì down lại, tranh sai sót đáng tiếc !!!
;lisp ve mui ten ghi chu thep
(defun c:MT( / lst_va old lay lay_thep ss pt1 pt2 ent1 pt lst_pt)
(setq lst_va '("osmode" "cmdecho" "AUNITS")
old (mapcar 'getvar lst_va))
;=================
(if (not(tblsearch "layer" "DONG_MAU_DO")) (MakeLayer "DONG_MAU_DO" 1 nil nil T))
(setq lay (getvar 'clayer))
(setvar 'clayer "DONG_MAU_DO")
;=================
(cond ((not(tblsearch "block" "mui_ten_hiep"))
(entmake (list
'(0 . "TRACE")
'(100 . "AcDbEntity")
;(cons 8 "0")
'(100 . "AcDbTrace")
'(10 0 0 0)
'(11 0 0 0)
'(12 -2.5 -0.5 0)
'(13 -2.5 0.5 0)
)
)
(command "-block" "mui_ten_hiep" '(0 0 0) (entlast) "")
))
;=================
(setq lay_thep (assoc 8 (entget (car (entsel "\nChon thanh thep mau: ")))))
(prompt "\nChon cac thanh thep can ghi chu thich !")
(setq ss (ssget (append '((0 . "LINE,LWPOLYLINE")) (list lay_thep)))
pt1 (getpoint "\nXac dinh 2 diem tren duong dong ghi chu !\nChon diem goc: ")
pt2 (getpoint pt1 "\nChon diem phia ngon mui ten: ")
)
(mapcar 'setvar lst_va '(0 0 3))
(if (and ss pt1 pt2)
(progn
(MAKELINE pt1 pt2 nil nil nil nil nil)
(setq ent1 (entlast))
(foreach elem (ss2lst ss)
(setq lst1 (acet-geom-intersectwith ent1 elem 1)
pt (car (vl-sort lst1 '(lambda (x y) (< (distance pt1 x) (distance pt1 y)))))
lst_pt (cons pt lst_pt))
(command "-insert" "mui_ten_hiep" "S" 20 "R" (angle pt1 pt2) pt)
) ;for
(setq lst_pt (vl-sort lst_pt '(lambda (x y) (> (distance pt1 x) (distance pt1 y)))))
(entmod (subst (cons 11 (car lst_pt)) (assoc 11 (setq info (entget ent1))) info))
)
(princ "\n*** Dau vao chu hop ly ***")
) ;if
(mapcar 'setvar lst_va old)
(setvar 'clayer lay)
(princ)
)
;=================================
(defun MakeLine (PT1 PT2 Linetype LTScale Layer Color xdata)
(entmakex (list '(0 . "LINE")
(cons 8 (if Layer Layer (getvar "Clayer")))
(cons 6 (if Linetype Linetype "bylayer"))
(cons 48 (if LTScale LTScale 1))
(cons 62 (if Color Color 256))
(cons 10 PT1) (cons 11 PT2)))
)
;===================================
(defun ss2lst (ss / ename i lst)
;chuyen ss thanh list
(setq i 0)
(repeat (sslength ss)
(setq ename (ssname ss i)
i (1+ i)
lst (cons ename lst))
)
(reverse lst)
)
;================================
(defun MakeLayer (name color linetype lineWeight plot)
(entmakex (list '(0 . "LAYER")
(cons 100 "AcDbSymbolTableRecord")
(cons 100 "AcDbLayerTableRecord")
(cons 2 name)
(cons 70 0)
(cons 62 (if color color 7))
(cons 6 (if linetype linetype "Continuous"))
(cons 290 (if plot 1 0))
(cons 370 (if lineWeight (fix (* 100 lineWeight)) -3))))
)
- Tải lisp
- 317772_mt.lsp
Cách dùng
- Tải tệp 317772_mt.lsp về máy.
- 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 MT để chạy lisp.
Mã nguồn 317772_mt.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/112275-v%E1%BA%BD-%C4%91%C6%B0%E1%BB%9Dng-ch%C3%BA-th%C3%ADch-thanh-th%C3%A9p-%C4%91%C6%B0%E1%BB%9Dng-m%C5%A9i-t%C3%AAn-ch%E1%BB%89/
;lisp ve mui ten ghi chu thep
(defun c:MT( / lst_va old lay lay_thep ss pt1 pt2 ent1 pt lst_pt)
(setq lst_va '("osmode" "cmdecho" "AUNITS")
old (mapcar 'getvar lst_va))
;=================
(if (not(tblsearch "layer" "DONG_MAU_DO")) (MakeLayer "DONG_MAU_DO" 1 nil nil T))
(setq lay (getvar 'clayer))
(setvar 'clayer "DONG_MAU_DO")
;=================
(cond ((not(tblsearch "block" "mui_ten_hiep"))
(entmake (list
'(0 . "TRACE")
'(100 . "AcDbEntity")
;(cons 8 "0")
'(100 . "AcDbTrace")
'(10 0 0 0)
'(11 0 0 0)
'(12 -2.5 -0.5 0)
'(13 -2.5 0.5 0)
)
)
(command "-block" "mui_ten_hiep" '(0 0 0) (entlast) "")
))
;=================
(setq lay_thep (assoc 8 (entget (car (entsel "\nChon thanh thep mau: ")))))
(prompt "\nChon cac thanh thep can ghi chu thich !")
(setq ss (ssget (append '((0 . "LINE,LWPOLYLINE")) (list lay_thep)))
pt1 (getpoint "\nXac dinh 2 diem tren duong dong ghi chu !\nChon diem goc: ")
pt2 (getpoint pt1 "\nChon diem phia ngon mui ten: ")
)
(mapcar 'setvar lst_va '(0 0 3))
(if (and ss pt1 pt2)
(progn
(MAKELINE pt1 pt2 nil nil nil nil nil)
(setq ent1 (entlast))
(foreach elem (ss2lst ss)
(setq lst1 (acet-geom-intersectwith ent1 elem 1)
pt (car (vl-sort lst1 '(lambda (x y) (< (distance pt1 x) (distance pt1 y)))))
lst_pt (cons pt lst_pt))
(command "-insert" "mui_ten_hiep" "S" 20 "R" (angle pt1 pt2) pt)
) ;for
(setq lst_pt (vl-sort lst_pt '(lambda (x y) (> (distance pt1 x) (distance pt1 y)))))
(entmod (subst (cons 11 (car lst_pt)) (assoc 11 (setq info (entget ent1))) info))
)
(princ "\n*** Dau vao chu hop ly ***")
) ;if
(mapcar 'setvar lst_va old)
(setvar 'clayer lay)
(princ)
)
;=================================
(defun MakeLine (PT1 PT2 Linetype LTScale Layer Color xdata)
(entmakex (list '(0 . "LINE")
(cons 8 (if Layer Layer (getvar "Clayer")))
(cons 6 (if Linetype Linetype "bylayer"))
(cons 48 (if LTScale LTScale 1))
(cons 62 (if Color Color 256))
(cons 10 PT1) (cons 11 PT2)))
)
;===================================
(defun ss2lst (ss / ename i lst)
;chuyen ss thanh list
(setq i 0)
(repeat (sslength ss)
(setq ename (ssname ss i)
i (1+ i)
lst (cons ename lst))
)
(reverse lst)
)
;================================
(defun MakeLayer (name color linetype lineWeight plot)
(entmakex (list '(0 . "LAYER")
(cons 100 "AcDbSymbolTableRecord")
(cons 100 "AcDbLayerTableRecord")
(cons 2 name)
(cons 70 0)
(cons 62 (if color color 7))
(cons 6 (if linetype linetype "Continuous"))
(cons 290 (if plot 1 0))
(cons 370 (if lineWeight (fix (* 100 lineWeight)) -3))))
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề vẽ đường chú thích thanh thép (đường mũi tên chỉ). Xem đúng bài viết #317772 để đọc hướng dẫn và trao đổi thêm.