Lisp vẽ hình oval
Bạn dùng thử cái này xem được không nhé!
;Doan Van Ha - CADViet.com (defun C:OVAL() (BAT_DAU) (acet-sysvar-set (list "osmode" 0 "cmdecho" 0)) (initget 7) (setq bk (getreal "\nBan kinh Oval: ")) (initget 1) (setq p1 (getpoint "\nPick tam Oval thu 1: ")) (command "arc" (polar p1 (/ pi 2) bk) (polar p1 (- pi) bk) (polar p1 (/ pi -2) bk)) (setq ent1 (entlast)) (command "circle" p1 bk) (setq ent2 (entlast)) (initget 1) (setq p2 (getpoint p1 "\nPick tam Oval thu 2: ")) (command "rotate" ent1 "" p1 (/ (* 180 (angle p1 p2)) pi)) (command "line" (vlax-curve-getEndPoint ent1) (polar (vlax-curve-getEndPoint ent1) (angle p1 p2) (distance p1 p2)) "") (command "line" (vlax-curve-getStartPoint ent1) (polar (vlax-curve-getStartPoint ent1) (angle p1 p2) (distance p1 p2)) "") (command "mirror" ent1 "" (acet-geom-midpoint (vlax-curve-getEndPoint ent1) (polar (vlax-curve-getEndPoint ent1) (angle p1 p2) (distance p1 p2))) (acet-geom-midpoint (vlax-curve-getStartPoint ent1) (polar (vlax-curve-getStartPoint ent1) (angle p1 p2) (distance p1 p2))) "N") (command "erase" ent2 "") (acet-sysvar-restore) (KET_THUC) (princ)) (defun BAT_DAU() (setq AcDoc (vla-get-activeDocument (vlax-get-acad-object))) (vla-StartUndoMark AcDoc) (setq err *error* *error* KHI_LOI)) (defun KET_THUC() (acet-sysvar-restore) (vla-EndUndoMark AcDoc) (setq *error* err)) (defun KHI_LOI(msg) (acet-sysvar-restore) (vla-EndUndoMark AcDoc) (redraw) (command "u") (princ (strcat "\n" msg ", Reset System Variables\n")) (setq *error* err))
Bạn dùng thử cái này xem được không nhé!
;Doan Van Ha - CADViet.com (defun C:OVAL() (BAT_DAU) (acet-sysvar-set (list "osmode" 0 "cmdecho" 0)) (initget 7) (setq bk (getreal "\nBan kinh Oval: ")) (initget 1) (setq p1 (getpoint "\nPick tam Oval thu 1: ")) (command "arc" (polar p1 (/ pi 2) bk) (polar p1 (- pi) bk) (polar p1 (/ pi -2) bk)) (setq ent1 (entlast)) (command "circle" p1 bk) (setq ent2 (entlast)) (initget 1) (setq p2 (getpoint p1 "\nPick tam Oval thu 2: ")) (command "rotate" ent1 "" p1 (/ (* 180 (angle p1 p2)) pi)) (command "line" (vlax-curve-getEndPoint ent1) (polar (vlax-curve-getEndPoint ent1) (angle p1 p2) (distance p1 p2)) "") (command "line" (vlax-curve-getStartPoint ent1) (polar (vlax-curve-getStartPoint ent1) (angle p1 p2) (distance p1 p2)) "") (command "mirror" ent1 "" (acet-geom-midpoint (vlax-curve-getEndPoint ent1) (polar (vlax-curve-getEndPoint ent1) (angle p1 p2) (distance p1 p2))) (acet-geom-midpoint (vlax-curve-getStartPoint ent1) (polar (vlax-curve-getStartPoint ent1) (angle p1 p2) (distance p1 p2))) "N") (command "erase" ent2 "") (acet-sysvar-restore) (KET_THUC) (princ)) (defun BAT_DAU() (setq AcDoc (vla-get-activeDocument (vlax-get-acad-object))) (vla-StartUndoMark AcDoc) (setq err *error* *error* KHI_LOI)) (defun KET_THUC() (acet-sysvar-restore) (vla-EndUndoMark AcDoc) (setq *error* err)) (defun KHI_LOI(msg) (acet-sysvar-restore) (vla-EndUndoMark AcDoc) (redraw) (command "u") (princ (strcat "\n" msg ", Reset System Variables\n")) (setq *error* err))
Cảm ơn Bác Doan van Ha nhé!Nhưng bác có thể chỉnh lại giúp e chút xíu được không!Trước khi mình nhập vào bán kính,mình sẽ pick vào 1 điểm bất kì để xác định tâm cho hình oval 1 luôn và khi vẽ xong thì tất cả sẽ nối lại thành 1 polyline!
- Tải lisp
- 182417_oval.lsp
Cách dùng
- Tải tệp 182417_oval.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 OVAL để chạy lisp.
Mã nguồn 182417_oval.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/59305-nh%E1%BB%9D-ch%E1%BB%89nh-s%E1%BB%ADalisp-v%E1%BA%BD-h%C3%ACnh-oval/
;Doan Van Ha - CADViet.com
(defun C:OVAL()
(BAT_DAU)
(acet-sysvar-set (list "osmode" 0 "cmdecho" 0))
(initget 7) (setq bk (getreal "\nBan kinh Oval: "))
(initget 1) (setq p1 (getpoint "\nPick tam Oval thu 1: "))
(command "arc" (polar p1 (/ pi 2) bk) (polar p1 (- pi) bk) (polar p1 (/ pi -2) bk))
(setq ent1 (entlast))
(command "circle" p1 bk)
(setq ent2 (entlast))
(initget 1) (setq p2 (getpoint p1 "\nPick tam Oval thu 2: "))
(command "rotate" ent1 "" p1 (/ (* 180 (angle p1 p2)) pi))
(command "line" (vlax-curve-getEndPoint ent1) (polar (vlax-curve-getEndPoint ent1) (angle p1 p2) (distance p1 p2)) "")
(command "line" (vlax-curve-getStartPoint ent1) (polar (vlax-curve-getStartPoint ent1) (angle p1 p2) (distance p1 p2)) "")
(command "mirror" ent1 "" (acet-geom-midpoint (vlax-curve-getEndPoint ent1) (polar (vlax-curve-getEndPoint ent1) (angle p1 p2) (distance p1 p2)))
(acet-geom-midpoint (vlax-curve-getStartPoint ent1) (polar (vlax-curve-getStartPoint ent1) (angle p1 p2) (distance p1 p2))) "N")
(command "erase" ent2 "")
(acet-sysvar-restore)
(KET_THUC)
(princ))
(defun BAT_DAU()
(setq AcDoc (vla-get-activeDocument (vlax-get-acad-object)))
(vla-StartUndoMark AcDoc)
(setq err *error* *error* KHI_LOI))
(defun KET_THUC()
(acet-sysvar-restore)
(vla-EndUndoMark AcDoc)
(setq *error* err))
(defun KHI_LOI(msg)
(acet-sysvar-restore)
(vla-EndUndoMark AcDoc)
(redraw)
(command "u")
(princ (strcat "\n" msg ", Reset System Variables\n"))
(setq *error* err))
Thảo luận gốc
Lisp được chia sẻ trong chủ đề [Nhờ chỉnh sửa]Lisp vẽ hình oval. Xem đúng bài viết #182417 để đọc hướng dẫn và trao đổi thêm.