Jump to content

vẽ pline theo danh sách.


tui dang dùng lisp viết lệnh vẽ trắc ngang. đọc file số liệu ntd. vì list được tạo ra sau nhiều vòng while và khi gặp điều kiện thỏa mãn thì thực hiện lệnh vẽ pline. tui còn đang làm dở dang nhưng cũng up lên cho bác hiểu ý tưởng của tui.http://www.cadviet.c..._dau_vaontd.txt http://www.cadviet.c...6914_ketqua.dwg

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 199458_vtn.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 VTN để chạy lisp.

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

(defun c:vtn ( / fn fid strht vt x y z)
 (defun pos (sub st / l1 l2 index)
(setq index 1
  l1 (strlen sub)
  l2 (strlen st)
)
(while
 	(and (<= (+ index l1 -1) l2) (/= sub (substr st index l1)))
  	(setq index (1+ index))
)
(if (= sub (substr st index l1))
 	index
 	nil
)
 )
 (princ "\neiPoint © 2007 Cadviet.com")
 (setq fn  (getfiled "Ten tep de nhap toa do x y z"
   	(getvar "dwgprefix")
   	"txt"
   	2
	)
fid (open fn "r")
 )
 (setq i 0)
 (setq point (getpoint "\n chon diem ve tn:"))
 (command "_UCS" "N" point "")
 (setq taphopdiem nil)
 (while (setq strht (read-line fid))
(setq strht (strcat strht "\t\t\t\t"))
(if (/= strht "   ")
 	(progn
(setq
  vt (pos "\t" strht)
  mot (substr strht 1 (1- vt))
  strht (substr strht (1+ vt))

  vt (pos "\t" strht)
  hai (substr strht 1 (1- vt))
  strht (substr strht (1+ vt))

  vt (pos "\t" strht)
  ba (substr strht 1 (1- vt))
  strht (substr strht (1+ vt))
  vt (pos "\t" strht)
  bon (substr strht 1 (1- vt))
  strht (substr strht (1+ vt))
)
;(princ (strcat "\t" mot "\t" hai "\t" ba "\t" bon "\n"))
 	);het progn
); het if
(cond
	((= mot "POLE")
 	(progn
   	(if (/= taphopdiem nil)
     	(progn
 	(command "pline" taphopdiem "")
;(princ taphopdiem)
)
  )
(setq
  tencon hai
  caodo (atof bon)
  taphopdiem "\n"
)
   	(princ (strcat "\n" mot "\t" hai "\t" ba "\t" bon "\n"))
 	); het progn
	)
	((or (= mot "TARGETL") (= mot "TARGETR"))
 	(progn
(setq
  kcl (atof hai)
  ccao (atof ba)
  taphopdiem(strcat (chr 32) hai "," ba taphopdiem)
 ; taphopdiem (cons pointi taphopdiem)
)
  	); het progn
 	)
); Het cond
(setq i (1+ i))

 )
 (command "_UCS" "w" "")
 (close fid)
)
(princ "\neiPoint da duoc nap. su dung 2 lenh: ExpPnt va ImpPnt de xuat va nhap Point")

Thảo luận gốc

Lisp được chia sẻ trong chủ đề [hỏi] vẽ pline theo danh sách.. Xem đúng bài viết #199458 để đọc hướng dẫn và trao đổi thêm.

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