Lisp lệnh SCL trong chủ đề “Viết lisp theo yêu cầu [phần 2]”
Chào bác SSG, Thiep xin góp 1 lisp khác theo hướng sử dụng hàm acet-geom-intersectwith trong expresstool
Tip: nếu có 1 pline giao với n pline khác, nó sẽ bị scale n lần. Chương trình không kiểm tra việc đó, bạn phải tự chịu trách nhiệm lấy. SSG
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 82931_scl.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 SCL để chạy lisp.
Mã nguồn 82931_scl.lsp (trích từ bài viết gốc)
;;;-------------------------------------------------------------
(defun C:SCI( / ss k p) ;;;SCale at Intersections
(vl-load-com)
(setq
ss (ssget '((0 . "LINE,LWPOLYLINE")))
k (getreal "\nScale factor:")
oldos (getvar "osmode")
)
(setvar "osmode" 0)
(foreach p (intss ss)
(setq ss (ssget "C" p p '((0 . "LINE,LWPOLYLINE"))))
(command "scale" ss "" p k)
)
(setvar "osmode" oldos)
(princ)
)
;;;-------------------------------------------------------------
(defun ss2ent (ss / i Le e)
(setq i 0 Le nil)
(repeat (sslength ss)
(setq
e (ssname ss i)
Le (append Le (list e))
i (1+ i)
)
)
Le
)
;;;-------------------------------------------------------------;
(defun DelSame(L / Ln x) ;;;Delete Same items in List
(foreach x L (if (not (member x Ln)) (setq Ln (append Ln (list x)))))
Ln
)
;;;;-------------------------------------------------------------;
(defun int2e (e1 e2 / obj1 obj2 Li a1)
(setq
obj1 (vlax-EName->vla-Object e1)
obj2 (vlax-EName->vla-Object e2)
)
(setq a1 (vlax-Invoke obj1 "IntersectWith" obj2 acExtendNone))
(if a1
(while a1
(setq Li (append Li (list (list (car a1) (cadr a1) (caddr a1)))))
(repeat 3 (setq a1 (cdr a1)))
)
)
Li
)
;;;-------------------------------------------------------------;;
(defun intss (ss / L e1 e2 p Lp)
(setq L (ss2ent ss))
(foreach e1 L
(foreach e2 L (if (setq p (int2e e1 e2)) (setq Lp (append Lp p))))
)
(DelSame Lp)
)
;;;-------------------------------------------------------------
;| Lisp scale *LINEs with basepoint at the intersect points
12/2009
Require: install Expess tool
---------------------------------------------------------|;
(defun SS-enlst (ss / c L)
(setq c -1)
(repeat (sslength ss)
(setq L (cons (ssname ss (setq c (1+ c))) L))
)
(reverse L)
)
;;;-----------------------
(defun c:scL (/ ss Len1 Len2 po Lpo ok)
(acet-sysvar-set
(list "cmdecho" 0 "osmode" 32)
)
(prompt "\nSelect LINES or POLYLINES or LWPOLYLINES")
(Setq ss (ssget '((0 . "*LINE")))
Len1 (SS-enlst ss)
Len2 (cdr Len1)
)
(setq sc (cond (sc)
(2)
)
)
(setq oldsc sc)
(setq sc (getreal (strcat "\nEnter a Scale Factor <"
(rtos oldsc 2 1)
"> : "
)
)
)
(if (null sc)
(setq sc oldsc)
)
(foreach en1 Len1
(foreach en2 Len2
(if (setq po (acet-geom-intersectwith en1 en2 0))
(setq Lpo (cons (car po) Lpo))
)
)
(setq Len2 (cdr Len2))
)
(foreach pin Lpo
(Setq ss (ssget "_C" pin pin '((0 . "*LINE")))
Len3 (SS-enlst ss)
n 0
)
(repeat (sslength ss)
(vla-ScaleEntity
(vlax-ename->vla-object (ssname ss n))
(vlax-3d-point pin)
sc
)
(setq n (1+ n))
)
)
(acet-sysvar-restore)
(vla-put-Comments
(vla-get-SummaryInfo
(vla-get-ActiveDocument
(vlax-get-acad-object)
)
)
(setq ok "Thank you for use scL.lsp! THIEP 0918841230")
)
(princ ok)
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề Viết lisp theo yêu cầu [phần 2]. Xem đúng bài viết #82931 để đọc hướng dẫn và trao đổi thêm.