Lisp lệnh HKH trong chủ đề “chuyển tọa độ từ file excel sang cad”
Chào vantran, Lisp này chạy khi trong bản vẽ của bạn đã có block "HOKHOAN" và trong file dữ liệu thêm 1 dòng tiêu đề như trong file Thiep gửi cho bạn sau:https://www.cadviet.com/upfiles/2/dulieudavoi.zip
Còn đây là lisp:
;| Lisp nhap cac blockref LOKHOAN tu file du lieu *.txt copyright by TRAN THIEP V1 03/2010 Yeu cau: ACAD da co cai dat Express Tools =====================================================|; (vl-load-com) (defun c:hkh (/ ActDoc *Model* *layer* f Lh posX posY name Z Se p objblk n taglst ) (setq ActDoc (vla-get-ActiveDocument (vlax-get-acad-object)) *Model* (vla-get-ModelSpace ActDoc) *layer* (vla-get-Layers ActDoc) *sumary* (vla-get-SummaryInfo ActDoc) ) (vla-StartUndoMark ActDoc) (or fn (setq fn (getfiled "chon file du lieu" "d:/" "txt" 0 ) ) ) (or (tblobjname "layer" "LOKHOAN")(vla-add *layer* "LOKHOAN")) (acet-sysvar-set (list "cmdecho" 0 "osmode" 0 "clayer" "LOKHOAN") ) (setq f (open fn "r")) (setq Lh (ACET-STR-TO-LIST "\t" (read-line f)) posX (vl-position "Y" Lh) posY (vl-position "X" Lh) name (vl-position "TEN" Lh) Z (vl-position "H" Lh) ) (setq tyle (cond (tyle) (1) ) ) (setq oldtyle tyle) (setq tyle (getreal (strcat "\nChon ty le chen khoi <" (rtos oldtyle 2 0) "> : " ) ) ) (if (null tyle) (setq tyle oldtyle) ) (while (setq Lh (read-line f)) (setq Se (ACET-STR-TO-LIST "\t" Lh) p (list (distof (nth posX Se) 2) (distof (nth posY Se) 2) (distof (nth Z Se) 2) ) ) (setq objblk (vla-InsertBlock *Model* (vlax-3d-point p) "HOKHOAN" tyle tyle 1 0 ) n 0 ) (setq taglst (vlax-safearray->list (vlax-variant-value (vla-getattributes objblk) ) ) ) (foreach att taglst (cond ((eq (vla-get-tagstring att) "TENHK") (vla-put-textstring att (nth name Se)) ) ((eq (vla-get-tagstring att) "Z") (vla-put-textstring att (nth Z Se)) ) ) ) ) (close f) (acet-sysvar-restore) (vla-EndUndoMark ActDoc) (vla-put-Author *sumary* "TRAN-THIEP 0918841230") (vla-put-Comments *sumary* (strcat "This drawing used to use hokhoan.lsp" " " " Copyright by Tran Thiep" " " " Thank you very much" ) ) (princ "\nThiep chuc ban thanh cong") (princ) )
cảm ơn Thiep. đây đúng là cái lisp mình cần.
- Tải lisp
- 92720_hkh.lsp
Cách dùng
- Tải tệp 92720_hkh.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 HKH để chạy lisp.
Mã nguồn 92720_hkh.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/18561-chuy%E1%BB%83n-t%E1%BB%8Da-%C4%91%E1%BB%99-t%E1%BB%AB-file-excel-sang-cad/
;| Lisp nhap cac blockref LOKHOAN tu file du lieu *.txt
copyright by TRAN THIEP V1 03/2010
Yeu cau: ACAD da co cai dat Express Tools
=====================================================|;
(vl-load-com)
(defun c:hkh (/ ActDoc *Model* *layer* f Lh posX posY
name Z Se p objblk n taglst
)
(setq ActDoc (vla-get-ActiveDocument (vlax-get-acad-object))
*Model* (vla-get-ModelSpace ActDoc)
*layer* (vla-get-Layers ActDoc)
*sumary* (vla-get-SummaryInfo ActDoc)
)
(vla-StartUndoMark ActDoc)
(or fn (setq fn (getfiled "chon file du lieu"
"d:/"
"txt"
0
)
)
)
(or (tblobjname "layer" "LOKHOAN")(vla-add *layer* "LOKHOAN"))
(acet-sysvar-set
(list "cmdecho" 0 "osmode" 0 "clayer" "LOKHOAN")
)
(setq f (open fn "r"))
(setq Lh (ACET-STR-TO-LIST "\t" (read-line f))
posX (vl-position "Y" Lh)
posY (vl-position "X" Lh)
name (vl-position "TEN" Lh)
Z (vl-position "H" Lh)
)
(setq tyle (cond (tyle)
(1)
)
)
(setq oldtyle tyle)
(setq tyle (getreal (strcat "\nChon ty le chen khoi <"
(rtos oldtyle 2 0)
"> : "
)
)
)
(if (null tyle)
(setq tyle oldtyle)
)
(while (setq Lh (read-line f))
(setq Se (ACET-STR-TO-LIST "\t" Lh)
p (list (distof (nth posX Se) 2)
(distof (nth posY Se) 2)
(distof (nth Z Se) 2)
)
)
(setq objblk (vla-InsertBlock
*Model*
(vlax-3d-point p)
"HOKHOAN"
tyle
tyle
1
0
)
n 0
)
(setq taglst (vlax-safearray->list
(vlax-variant-value
(vla-getattributes objblk)
)
)
)
(foreach att taglst
(cond ((eq (vla-get-tagstring att) "TENHK")
(vla-put-textstring att (nth name Se))
)
((eq (vla-get-tagstring att) "Z")
(vla-put-textstring att (nth Z Se))
)
)
)
)
(close f)
(acet-sysvar-restore)
(vla-EndUndoMark ActDoc)
(vla-put-Author *sumary* "TRAN-THIEP 0918841230")
(vla-put-Comments
*sumary*
(strcat
"This drawing used to use hokhoan.lsp"
" "
" Copyright by Tran Thiep"
" "
" Thank you very much"
)
)
(princ "\nThiep chuc ban thanh cong")
(princ)
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề chuyển tọa độ từ file excel sang cad. Xem đúng bài viết #92720 để đọc hướng dẫn và trao đổi thêm.