Jump to content

Lisp in nhiều bản vẽ trong model mà chỉ cần 1 layout


Tôi không có máy in, chưa test thử. Gặp sự cố thì báo lại giùm.

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 193782_ikn.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 IKN để chạy lisp.

Mã nguồn 193782_ikn.lsp (trích từ bài viết gốc)

(defun c:ikn (/ olmode pre D1 D2 ent1 ent2 pre dau h sty lay col po d1 d2 n i dsdinh) ;;;In khung nghieng
(vl-load-com) (load "aspace") (command "undo" "be") (setq olmode (getvar "OSMODE")) (setvar "OSMODE" 1)
(setq pre (getstring T "\nNhap tien to: "))
(setq dau (getint "\nDanh so bat dau (n): "))
(setq ent1 (car (entsel "\nChon Text mau de lay Style va Justify: ")))		;De lay Style/height/layer/color
(setq h (cdr (assoc 40 (entget ent1))))
(setq sty (cdr (assoc 7 (entget ent1))))
(setq lay (cdr (assoc 8 (entget ent1))))
(setq col (cdr (assoc 62 (entget ent1))))
(command "PSPACE")
(setq po (getpoint "\nChon vi tri dat so hieu ban ve:  ")
      	D1 (getpoint "\nChon diem thu nhat: ")
      	D2 (getpoint "\nChon diem thu hai: "))
(command "MSPACE")
(setq ent2 (entsel "\nChon pline: "))
(setq i 0)
(setq dsdinh (acet-geom-vertex-list (car ent2)))
(setq n (/ (length dsdinh) 2))
(if ent2
 (progn
  (repeat n
(alignspace (nth i dsdinh) (nth (1+ i) dsdinh) D1 D2)
(command "PSPACE")
;Chon 1 trong 2 dong duoi day. Dong khong muon dung thi them dau ; dang truoc.
(setq txt (strcat pre (if (< dau 10) (strcat "0" (itoa dau)) (itoa dau)) "/" (if (< n 10) (strcat "0" (rtos n 2 0)) (rtos n 2 0))))	;VD in ra la <KC, CN KT>: 03/15
;	(setq txt (strcat pre (if (< dau 10) (strcat "0" (itoa dau)) (itoa dau))))					;VD in ra la <KC, CN KT>: 03
(MakeText po txt h 0 "MC" sty lay col)
(setq Elast (entlast))
(command "_plot" "" "" "" "" "" "" "")
(command "erase" Elast "")
(command "MSPACE")
(setq dau (+ dau 1))
(setq i (+ i 2)))))
(command "plan" "w")
(command "PSPACE")
(setvar "OSMODE" olmode) (command "undo" "end") (princ))
;----- by Thaistressz. Thanks!
(defun MakeText (point string Height Ang justify Style Layer Color / Lst)
(setq Lst (list '(0 . "TEXT")
  (cons 8 (if Layer Layer (getvar "Clayer")))
  (cons 62 (if Color Color 256))
  (cons 10 point)
  (cons 40 Height)
  (cons 1 string)
  (if Ang (cons 50 Ang))
  (cons 7 (if Style Style (getvar "Textstyle"))))
 justify (strcase justify))
(cond ((= justify "C") (setq Lst (append Lst (list (cons 72 1) (cons 11 point)))))
       	((= justify "R") (setq Lst (append Lst (list (cons 72 2) (cons 11 point)))))
       	((= justify "M") (setq Lst (append Lst (list (cons 72 4) (cons 11 point)))))
       	((= justify "TL") (setq Lst (append Lst (list (cons 72 0) (cons 11 point) (cons 73 3)))))
       	((= justify "TC") (setq Lst (append Lst (list (cons 72 1) (cons 11 point) (cons 73 3)))))
       	((= justify "TR") (setq Lst (append Lst (list (cons 72 2) (cons 11 point) (cons 73 3)))))   
       	((= justify "ML") (setq Lst (append Lst (list (cons 72 0) (cons 11 point) (cons 73 2)))))
       	((= justify "MC") (setq Lst (append Lst (list (cons 72 1) (cons 11 point) (cons 73 2)))))
       	((= justify "MR") (setq Lst (append Lst (list (cons 72 2) (cons 11 point) (cons 73 2)))))
       	((= justify "BL") (setq Lst (append Lst (list (cons 72 0) (cons 11 point) (cons 73 1)))))
       	((= justify "BC") (setq Lst (append Lst (list (cons 72 1) (cons 11 point) (cons 73 1)))))
       	((= justify "BR") (setq Lst (append Lst (list (cons 72 2) (cons 11 point) (cons 73 1))))))
(entmake Lst))

Thảo luận gốc

Lisp được chia sẻ trong chủ đề [Đã xong] In nhiều bản vẽ trong model mà chỉ cần 1 layout. Xem đúng bài viết #193782 để đọc hướng dẫn và trao đổi thêm.

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