Jump to content

Lisp lệnh TT trong chủ đề “Nhờ viết LISP tạo hình chữ nhật từ LINE”

Mình cũng tham gia tý:

(defun c:tt  (/ a d e p s _lwpoly)
  (defun _lwpoly  (l)
    (entmake (append (list (cons 0 "LWPOLYLINE")
                           (cons 100 "AcDbEntity")
                           (cons 100 "AcDbPolyline")
                           (cons 90 (length l))
                           (cons 70 1))
                     (mapcar '(lambda (p) (cons 10 (trans p 1 0))) l))))
  (setq d (cond (#othedglin2rec#)
                (100)))
  (initget 2)
  (setq d (cond ((getdist (strcat "\nChieu dai canh khac <" (rtos d 2 2) ">: ")))
                (d)))
  (setq #othedglin2rec# d)
  (while (setq s (ssget '((0 . "LINE"))))
    (while (and (setq e (ssname s 0)) (ssdel e s))
      (setq p (mapcar '(lambda (x) (cdr (assoc x (entget e)))) '(10 11))
            a (apply 'angle p))
      (entdel e)
      (_lwpoly (mapcar '(lambda (x y) (polar x (+ a (* y pi)) (* 0.5 d)))
                       (append p (reverse p))
                       (list 0.5 0.5 1.5 1.5)))))
  (princ))

 

Cách dùng

  1. Tải tệp 455100_tt.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 TT để chạy lisp.

Mã nguồn 455100_tt.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/185936-nh%E1%BB%9D-vi%E1%BA%BFt-lisp-t%E1%BA%A1o-h%C3%ACnh-ch%E1%BB%AF-nh%E1%BA%ADt-t%E1%BB%AB-line/
(defun c:tt  (/ a d e p s _lwpoly)
  (defun _lwpoly  (l)
    (entmake (append (list (cons 0 "LWPOLYLINE")
                           (cons 100 "AcDbEntity")
                           (cons 100 "AcDbPolyline")
                           (cons 90 (length l))
                           (cons 70 1))
                     (mapcar '(lambda (p) (cons 10 (trans p 1 0))) l))))
  (setq d (cond (#othedglin2rec#)
                (100)))
  (initget 2)
  (setq d (cond ((getdist (strcat "\nChieu dai canh khac <" (rtos d 2 2) ">: ")))
                (d)))
  (setq #othedglin2rec# d)
  (while (setq s (ssget '((0 . "LINE"))))
    (while (and (setq e (ssname s 0)) (ssdel e s))
      (setq p (mapcar '(lambda (x) (cdr (assoc x (entget e)))) '(10 11))
            a (apply 'angle p))
      (entdel e)
      (_lwpoly (mapcar '(lambda (x y) (polar x (+ a (* y pi)) (* 0.5 d)))
                       (append p (reverse p))
                       (list 0.5 0.5 1.5 1.5)))))
  (princ))

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Nhờ viết LISP tạo hình chữ nhật từ LINE. Xem đúng bài viết #455100 để đọc hướng dẫn và trao đổi thêm.

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