Lisp lệnh MT trong chủ đề “vẽ đường chú thích thanh thép (đường mũi tên chỉ)”
Tranh thủ luyện tí ! :D
p/s:
Thanh thép phải là LINE hoặc PLINE được vẽ bằng layer "THEP" , nếu tên layer của bạn chưa đúng thì sửa lisp lại ^^
Layer và màu có lẻ là bạn chưa ưng ý, mình sẽ sửa khi bạn cho xem bản vẽ mẫu !
;lisp ve mui ten ghi chu thep
(defun c:MT( / lst_va old ss pt1 pt2 ent1 pt lst_pt)
(setq lst_va '("osmode" "cmdecho" "AUNITS")
old (mapcar 'getvar lst_va))
;=================
(cond ((not(tblsearch "block" "mui_ten"))
(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" '(0 0 0) (entlast) "")
))
;=================
(prompt "\nChon cac thanh thep can ghi chu thich !")
(setq ss (ssget '((0 . "LINE,LWPOLYLINE") (8 . "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 "DONG" 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" "S" 1 "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*** NOTE: Cac thanh thep phai duoc ve bang layer <THEP> ***")
) ;if
(mapcar 'setvar lst_va old)
)
;=================================
(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)
)
- Tải lisp
- 317597_mt.lsp
Cách dùng
- Tải tệp 317597_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 317597_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 ss pt1 pt2 ent1 pt lst_pt)
(setq lst_va '("osmode" "cmdecho" "AUNITS")
old (mapcar 'getvar lst_va))
;=================
(cond ((not(tblsearch "block" "mui_ten"))
(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" '(0 0 0) (entlast) "")
))
;=================
(prompt "\nChon cac thanh thep can ghi chu thich !")
(setq ss (ssget '((0 . "LINE,LWPOLYLINE") (8 . "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 "DONG" 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" "S" 1 "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*** NOTE: Cac thanh thep phai duoc ve bang layer <THEP> ***")
) ;if
(mapcar 'setvar lst_va old)
(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)
)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 #317597 để đọc hướng dẫn và trao đổi thêm.