Jump to content

Lisp lệnh NB trong chủ đề “(NHỜ VIẾT LISP)”

@zutum:

Lisp sửa lại đây bạn. Nếu đoạn thẳng và hình chữ nhật xiên cùng 1 góc thì Lisp chấp nhận luôn đó nhé


(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))
  (if (> (cadr p1)(cadr p2)) (setq pptg p2 p2 p1 p1 pptg))
  (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

  1. Chép mã nguồn, lưu thành tệp 440693_nb.lsp.
  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 NB để chạy lisp.

Mã nguồn 440693_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))
  (if (> (cadr p1)(cadr p2)) (setq pptg p2 p2 p1 p1 pptg))
  (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 #440693 để đọc hướng dẫn và trao đổi thêm.

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