xin lisp ghi cao độ
Trên diễn đàn hẳn có rất nhiều LISP na ná như bạn mong muốn
Ví dụ như LISP đánh cốt tự động của bác Nguyen Hoanh http://www.cadviet.c...p?showtopic=152
Hoặc bạn có thể dùng thử đồ chơi của mình
;;; Free lisp code from CADViet.com
(defun CheckObj(e MyType) (equal (cdr (assoc 0 (entget e))) MyType))
;;;-----------------------------------------
(defun FilObj(ss1 MyType / ss2 i e)
(setq ss2 (ssadd) i 0)
(repeat (sslength ss1)
(setq e (ssname ss1 i) i (1+ i))
(if (CheckObj e MyType) (ssadd e ss2) )
)
(eval ss2)
)
;;;-----------------------------------------
(defun SelData( / OK)
(setq OK nil)
(while (not OK)
(prompt "\tChon text: ")
(setq ss (FilObj (ssget) "TEXT"))
(if (> (sslength ss) 0) (setq OK T) (princ "\nDoi tuong chon khong phai text"))
)
)
;;;-----------------------------------------
(defun WriteRes1(kq / OK e chen data txt)
(setq OK nil)
(while (not OK)
(if (null cheno) (setq cheno ""))
(setq chen (getstring (strcat "\nText chen them vao phia truoc: an 1 de nhan text( " cheno " ) hoac nhap text: "))) ;; Dung viet them ghi chu cho text cao do (co the bo qua)
(if (= chen "1") (setq chen cheno) (setq cheno chen))
(setq e (car (entsel "\nChon text ghi ket qua cao do: ")))
(if (CheckObj e "TEXT") (setq OK T) (princ "\nDoi tuong chon khong phai text"))
)
(setq txt (strcat chen (rtos kq 2 tp)))
(entmod (subst (cons 1 txt) (assoc 1 (setq data (entget e))) data))
(princ)
)
;;;-----------------------------------------
(defun C:kb( / new1 )
(if (null newo) (setq newo 1000.0))
(setq new1 (getreal (strcat "\nNhap ty le ban ve 1/ <" (rtos newo) ">:ok or: ")))
(if (null new1) (setq new1 newo) (setq newo new1))
(setq tyle newo)
(setq dgoc (getpoint "\nChon diem goc cao do: "))
(setq cdg (getreal "\nNhap vao cao do goc: "))
(setq tp (getint "\nNhap vao so chu so thap phan: "))
)
;;;;;;;;;;---------------------------------
(defun C:ccd( / )
(setq i 1 n 100)
(while (< i n)
(setq dchon (getpoint "\nChon diem can tinh cao do: "))
(setq cddc (- cdg (* (/ 1 tyle) (- (cadr dgoc) (cadr dchon) ))) )
;(WriteRes1 cddc) ;; De dien vao text cac text co san
(command "TEXT" dchon "" "" (rtos cddc 2 tp)) ;; De viet them text moi Ban dung 1 trong 2 truong hop nhe
(setq i (+ i 1))
)
(princ)
)
Bạn dùng lệnh KB để chọn điểm gốc và các thông số
Và lệnh CCD để chèn cao độ vào các vị trí mong muốn
Trong LISP có 2 options ghi vào text có sẵn hoặc chèn text bạn nhé
Dùng trường hợp nào thì bạn cho dấu ";" vào đầu dòng còn lại nhé và bỏ dấu ";" của dòng kia đi
Lưu ý: Nếu chèn text, bạn hãy tạo text style có sẵn chiều cao chữ như bạn muốn thì nó mới chạy ngon được bạn nhé
Thân,
- Tải lisp
- 201510_kb_ccd.lsp
Cách dùng
- Tải tệp 201510_kb_ccd.lsp về máy.
- 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 KB CCD để chạy lisp.
Mã nguồn 201510_kb_ccd.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/64401-y%C3%AAu-c%E1%BA%A7u-xin-lisp-ghi-cao-%C4%91%E1%BB%99/
;;; Free lisp code from CADViet.com
(defun CheckObj(e MyType) (equal (cdr (assoc 0 (entget e))) MyType))
;;;-----------------------------------------
(defun FilObj(ss1 MyType / ss2 i e)
(setq ss2 (ssadd) i 0)
(repeat (sslength ss1)
(setq e (ssname ss1 i) i (1+ i))
(if (CheckObj e MyType) (ssadd e ss2) )
)
(eval ss2)
)
;;;-----------------------------------------
(defun SelData( / OK)
(setq OK nil)
(while (not OK)
(prompt "\tChon text: ")
(setq ss (FilObj (ssget) "TEXT"))
(if (> (sslength ss) 0) (setq OK T) (princ "\nDoi tuong chon khong phai text"))
)
)
;;;-----------------------------------------
(defun WriteRes1(kq / OK e chen data txt)
(setq OK nil)
(while (not OK)
(if (null cheno) (setq cheno ""))
(setq chen (getstring (strcat "\nText chen them vao phia truoc: an 1[+ enter] de nhan text( " cheno " ) hoac nhap text: "))) ;; Dung viet them ghi chu cho text cao do (co the bo qua)
(if (= chen "1") (setq chen cheno) (setq cheno chen))
(setq e (car (entsel "\nChon text ghi ket qua cao do: ")))
(if (CheckObj e "TEXT") (setq OK T) (princ "\nDoi tuong chon khong phai text"))
)
(setq txt (strcat chen (rtos kq 2 tp)))
(entmod (subst (cons 1 txt) (assoc 1 (setq data (entget e))) data))
(princ)
)
;;;-----------------------------------------
(defun C:kb( / new1 )
(if (null newo) (setq newo 1000.0))
(setq new1 (getreal (strcat "\nNhap ty le ban ve 1/ <" (rtos newo) ">:ok [enter] or: ")))
(if (null new1) (setq new1 newo) (setq newo new1))
(setq tyle newo)
(setq dgoc (getpoint "\nChon diem goc cao do: "))
(setq cdg (getreal "\nNhap vao cao do goc: "))
(setq tp (getint "\nNhap vao so chu so thap phan: "))
)
;;;;;;;;;;---------------------------------
(defun C:ccd( / )
(setq i 1 n 100)
(while (< i n)
(setq dchon (getpoint "\nChon diem can tinh cao do: "))
(setq cddc (- cdg (* (/ 1 tyle) (- (cadr dgoc) (cadr dchon) ))) )
;(WriteRes1 cddc) ;; De dien vao text cac text co san
(command "TEXT" dchon "" "" (rtos cddc 2 tp)) ;; De viet them text moi Ban dung 1 trong 2 truong hop nhe
(setq i (+ i 1))
)
(princ)
)
Thảo luận gốc
Lisp được chia sẻ trong chủ đề [yêu cầu] xin lisp ghi cao độ. Xem đúng bài viết #201510 để đọc hướng dẫn và trao đổi thêm.