Lisp vẽ một SPL trên một PL cho trước
Nếu muốn làm mịn đi thì loại bỏ các điểm ở giữa, bạn sử dụng thằng này. Độ làm mịn càng lớn thì số đỉnh của Pline bị loại bỏ càng lớn. Ở máy của mình lấy ví dụ tầm 30 là đẹp :) Lần sau chịu khó trình bày kỹ hơn chút nữa hén, do mình hơi dốt nên dễ hiểu nhầm
(defun c:p2s(/ ss lstPro MakeSPline ST:Geom-Vertext-List lstPro) (command "undo" "be") (setq a (getint "\nDo lam min :")) (prompt "\nChon Pline(s) :") (cond ( (ssget (list (cons 0 "*POLYLINE"))) (vl-load-com) (setq lstPro '(Linetype LinetypeScale Layer Color)) (defun lstRe (lst n / rt sublst);(1 2 3 4) (defun sublst(lst it)(repeat (1- it) (setq lst (cdr lst)))) (while lst (setq rt (cons (car lst) rt) lst (sublst lst n)) ) (reverse (vl-remove nil rt)) ) (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 (lstRe (ST:Geom-Vertext-List x) a)) (mapcar '(lambda(a)(vlax-get x a)) lstPro) ) ) (vla-erase x) ) ) ) (command "undo" "en") )
Thanhs!
Bạn khiêm tốn quá ! mình muốn dốt như bạn mà còn chẳng được nữa là.
Về diễn giải hay trình bày một cái gì đó thì mình kém lắm. (văn học mình học cực dốt mà)
Mọi người thông cảm.
- Tải lisp
- 200484_p2s.lsp
Cách dùng
- Tải tệp 200484_p2s.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 P2S để chạy lisp.
Mã nguồn 200484_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 lstPro)
(command "undo" "be")
(setq a (getint "\nDo lam min :"))
(prompt "\nChon Pline(s) :")
(cond ( (ssget (list (cons 0 "*POLYLINE")))
(vl-load-com)
(setq lstPro '(Linetype LinetypeScale Layer Color))
(defun lstRe (lst n / rt sublst);(1 2 3 4)
(defun sublst(lst it)(repeat (1- it) (setq lst (cdr lst))))
(while lst
(setq rt (cons (car lst) rt) lst (sublst lst n))
) (reverse (vl-remove nil rt))
)
(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 (lstRe (ST:Geom-Vertext-List x) a))
(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 #200484 để đọc hướng dẫn và trao đổi thêm.