Lisp lệnh NB trong chủ đề “(NHỜ VIẾT LISP)”
Bạn dùng thử lisp NB
Command: NB
Pick hinh chu nhat (pick vao canh) : -> Pick vào cạnh chữ nhật (chính là cạnh nan cần chia)
Pick doan thang :
Kieu chia: :+1
Nhap so nan :10
(defun c:nb() (setq e1 (entsel "\nPick hinh chu nhat (pick vao canh) :")) (setq e2 (car (entsel "\nPick doan thang :"))) (initget "+1 -1") (setq kieuchia (getkword "Kieu chia: :")) (setq nan (getint "\n Nhap so nan :")) (setq p1 (vlax-curve-getStartPoint e2)) (setq p2 (vlax-curve-getEndPoint e2)) (setq d2 (distance p1 p2)) (setq ptg (cadr e1)) (setq e (car e1)) (setq p11 (vlax-curve-getPointAtParam e (fix (vlax-curve-getParamAtPoint e (vlax-curve-getClosestPointto e ptg))))) (setq p12 (vlax-curve-getPointAtParam e (1+ (fix (vlax-curve-getParamAtPoint e (vlax-curve-getClosestPointto e ptg)))))) (setq d1 (distance p11 p12)) (if (< (cadr p11) (cadr p12)) (setq pb p11) (setq pb p12)) (if (= kieuchia "+1") (setq khe (/ (- d2 (* nan d1)) (1- nan))) (setq khe (/ (- d2 (* nan d1)) (1+ nan)))) (if (= kieuchia "-1") (setq p1 (polar p1 (angle p1 p2) khe))) (Repeat nan (command "._copy" e "" "_non" pb "_non" p1) (setq p1 (polar p1 (angle p1 p2) (+ d1 khe))) ) )
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 440648_nb.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 NB để chạy lisp.
Mã nguồn 440648_nb.lsp (trích từ bài viết gốc)
(defun c:nb()
(setq e1 (entsel "\nPick hinh chu nhat (pick vao canh) :"))
(setq e2 (car (entsel "\nPick doan thang :")))
(initget "+1 -1")
(setq kieuchia (getkword "Kieu chia: [+1 -1] :"))
(setq nan (getint "\n Nhap so nan :"))
(setq p1 (vlax-curve-getStartPoint e2)) (setq p2 (vlax-curve-getEndPoint e2))
(setq d2 (distance p1 p2))
(setq ptg (cadr e1)) (setq e (car e1))
(setq p11 (vlax-curve-getPointAtParam e (fix (vlax-curve-getParamAtPoint e (vlax-curve-getClosestPointto e ptg)))))
(setq p12 (vlax-curve-getPointAtParam e (1+ (fix (vlax-curve-getParamAtPoint e (vlax-curve-getClosestPointto e ptg))))))
(setq d1 (distance p11 p12)) (if (< (cadr p11) (cadr p12)) (setq pb p11) (setq pb p12))
(if (= kieuchia "+1") (setq khe (/ (- d2 (* nan d1)) (1- nan))) (setq khe (/ (- d2 (* nan d1)) (1+ nan))))
(if (= kieuchia "-1") (setq p1 (polar p1 (angle p1 p2) khe)))
(Repeat nan
(command "._copy" e "" "_non" pb "_non" p1)
(setq p1 (polar p1 (angle p1 p2) (+ d1 khe)))
)
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề (NHỜ VIẾT LISP). Xem đúng bài viết #440648 để đọc hướng dẫn và trao đổi thêm.