Jump to content

Lisp vẽ một SPL trên một PL cho trước

Rất cần thì phải quick and dirty code thôi ^^
Của bạn đây, chọn hàng loạt Pline để chuyển thành SPline, giữ nguyên các thuộc tính Layer, Color,Linetype, LinetypeScale. Lisp có dùng hàm MakeSpline của bác Thái, 2 hàm của bộ Express


(defun c:p2s(/ ss lstPro MakeSPline)
(command "undo" "be")
(prompt "\nChon Pline(s) :")
(cond ((setq ss (ssget (list (cons 0 "*POLYLINE"))))
(vl-load-com)
(setq ss (acet-ss-to-list ss)
lstPro '(Linetype LinetypeScale Layer Color))
(defun MakeSPline (listpoint Linetype LTScale Layer Color / Lst)
(setq lst (list '(0 . "SPLINE")'(100 . "AcDbEntity")
(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))
'(100 . "AcDbSpline")
(cons 71 3)
(cons 74 (length listpoint))))
(foreach PP listpoint (setq Lst (append Lst (list (cons 11 PP)))))
(entmakex Lst)
);end
(mapcar
'(lambda(x)
(apply
'MakeSPline
(append
(list (acet-geom-vertex-list x))
(mapcar '(lambda(a)(vlax-get (vlax-ename->vla-object x) a)) lstPro)
)
)
(entdel x)
)
ss
)
))
(command "undo" "en")
)

Cách dùng

  1. Tải tệp 200446_p2s.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 P2S để chạy lisp.

Mã nguồn 200446_p2s.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/64121-y%C3%AAu-c%E1%BA%A7u-lisp-v%E1%BA%BD-m%E1%BB%99t-spl-tr%C3%AAn-m%E1%BB%99t-pl-cho-tr%C6%B0%E1%BB%9Bc/

(defun c:p2s(/ ss lstPro MakeSPline ST:Geom-Vertext-List)
(command "undo" "be")
(prompt "\nChon Pline(s) :")
(cond ( (ssget (list (cons 0 "*POLYLINE")))
(vl-load-com)
(setq  lstPro '(Linetype LinetypeScale Layer Color))
(defun MakeSPline (listpoint Linetype LTScale Layer Color  / Lst)
(setq lst (list '(0 . "SPLINE")'(100 . "AcDbEntity")
(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))
'(100 . "AcDbSpline")
(cons 71 3)
(cons 74 (length listpoint))))
(foreach PP listpoint (setq Lst (append Lst (list (cons 11 PP))))) 
(entmakex Lst)
);end
(defun ST:Geom-Vertext-List (e / typ poly) ;vlaObject
(setq typ (vlax-get e 'ObjectName))
(cond ((wcmatch typ "AcDbLine")(list (vlax-get e 'StartPoint)(vlax-get e 'EndPoint)))
(T 
(   (lambda ( f /)
(if (setq poly (vl-position typ '("AcDbPolyline" "AcDb2dPolyline" "AcDb3dPolyline"))) 
(f (vlax-get e 'coordinates))
)
)
(lambda ( l )
(cond
((and l (= poly 0)) (cons (list (car l) (cadr l)) (f (cddr l))))
((and l (= poly 1)) (cons (list (car l) (cadr l)) (f (cdddr l))))
((and l (= poly 2)) (cons (list (car l) (cadr l) (caddr l)) (f (cdddr l))))
)
)
)
)
)
)
(vlax-for x (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))) 
(apply 
'MakeSPline 
(append
(list (ST:Geom-Vertext-List x))
(mapcar '(lambda(a)(vlax-get x a)) lstPro) 
)
)
(vla-erase x)
) 
)
)
(command "undo" "en")
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề [Yêu Cầu] Lisp vẽ một SPL trên một PL cho trước. Xem đúng bài viết #200446 để đọc hướng dẫn và trao đổi thêm.

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