Jump to content

Lisp hatch nhanh theo layer

Sửa lại 1 chút theo ý bạn, còn nguyên lý làm việc vẫn giữ nguyên ý bác Tuệ, chạy mượt hay không bạn tìm bác ấy nhé :)

(defun c:hlay(/ ss Tue-dxf Tue-ent-Lpoint ename ename2 ss2 lh ent fl)
(setq fl "")
(defun Tue-dxf (dxf ename)(cdr(assoc dxf (entget ename))))
(defun lh(dt tle goc)
(setvar "hpgaptol" 50.0)
(vl-cmdf "bhatch" "P" (getvar "hpname") tle goc "S" dt "" "")
)
(defun Tue-ent-Lpoint(e / i Lpoint);Tue-dxf
(if (wcmatch (Tue-dxf 0 e) "*POLYLINE")
(progn
 (if (= (type e) 'VLA-OBJECT) (setq e (vlax-vla-object->ename e)))
 (setq i -1)
 (Repeat (if (wcmatch (Tue-dxf 0 e) "*POLYLINE") (fix (1+ (vlax-curve-getEndParam e))) 2)
(setq Lpoint (append Lpoint (list (vlax-curve-getPointatParam e (setq i (1+ i))))))
 )
)
)
(if (wcmatch (Tue-dxf 0 e) "LINE")
 (setq Lpoint (append Lpoint (list (Tue-dxf 10 e) (Tue-dxf 11 e))))
)
Lpoint
)
(while (setq ent (entsel "\nDoi tuong chua layer mau :"))
 (setq  lay (Tue-dxf 8 (car ent))
fl (cond ((not (wcmatch lay fl))(strcat fl  lay ",")))
 )
)
(setq fl (vl-string-left-trim "," fl))
 (if (setq ss (ssget (list (cons 0 "*POLYLINE")
 (cons  8 (cond  ((setq tmp (vl-string-search "," fl)) (substr fl 1 (vl-string-search "," fl)))
  	(fl)
 )))))
(Progn    
 	(setq i -1)
 	(while (setq ename (ssname ss (setq i (1+ i))))
(setq ss2 (ssget "f" (Tue-ent-Lpoint ename) (list (cons 0 "*POLYLINE") (cons 8 fl))))
(lh  ss2  "1" "0")
 	)
))
)

Cám ơn bác nhiều nhé!

Nhưng hình như bác mới sửa được một ý thứ 2 trong 2 ý mà em muốn.

Còn lựa chọn mẫu hatch và scale nữa.

Mong bác giúp đỡ!

Cách dùng

  1. Tải tệp 193137_hlay.lsp về máy.
  2. 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ẽ.
  3. Gõ lệnh HLAY để chạy lisp.

Mã nguồn 193137_hlay.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/62595-y%C3%AAu-c%E1%BA%A7ulisp-hatch-nhanh-theo-layer/
(defun c:hlay(/ ss Tue-dxf Tue-ent-Lpoint ename ename2 ss2 lh ent fl)
(setq fl "")
(defun Tue-dxf (dxf ename)(cdr(assoc dxf (entget ename))))
(defun lh(dt tle goc)
(setvar "hpgaptol" 50.0)
(vl-cmdf "bhatch" "P" (getvar "hpname") tle goc "S" dt "" "")
)
(defun Tue-ent-Lpoint(e / i Lpoint);Tue-dxf
(if (wcmatch (Tue-dxf 0 e) "*POLYLINE")
(progn
 (if (= (type e) 'VLA-OBJECT) (setq e (vlax-vla-object->ename e)))
 (setq i -1)
 (Repeat (if (wcmatch (Tue-dxf 0 e) "*POLYLINE") (fix (1+ (vlax-curve-getEndParam e))) 2)
(setq Lpoint (append Lpoint (list (vlax-curve-getPointatParam e (setq i (1+ i))))))
 )
)
)
(if (wcmatch (Tue-dxf 0 e) "LINE")
 (setq Lpoint (append Lpoint (list (Tue-dxf 10 e) (Tue-dxf 11 e))))
)
Lpoint
)
(while (setq ent (entsel "\nDoi tuong chua layer mau :"))
 (setq  lay (Tue-dxf 8 (car ent))
fl (cond ((not (wcmatch lay fl))(strcat fl  lay ",")))
 )
)
(setq fl (vl-string-left-trim "," fl))
 (if (setq ss (ssget (list (cons 0 "*POLYLINE")
 (cons  8 (cond  ((setq tmp (vl-string-search "," fl)) (substr fl 1 (vl-string-search "," fl)))
  	(fl)
 )))))
(Progn    
 	(setq i -1)
 	(while (setq ename (ssname ss (setq i (1+ i))))
(setq ss2 (ssget "f" (Tue-ent-Lpoint ename) (list (cons 0 "*POLYLINE") (cons 8 fl))))
(lh  ss2  "1" "0")
 	)
))
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề [Yêu cầu]Lisp hatch nhanh theo layer. Xem đúng bài viết #193137 để đọc hướng dẫn và trao đổi thêm.

Về Thư viện AutoLisp (trang 291)