Lisp lệnh CAD2GEO trong chủ đề “Cần lisp chuyển dwg/dxf sang Plaxis”
Lisp dưới đây sẽ giúp bạn chuyển dữ liệu từ AutoCAD sang file . Tên lệnh là cad2geo
The lisp routine below will help you to transfer data from AutoCAD to file format. Command's name is cad2geo
(defun dxf(ent code) (cdr (assoc code (entget ent))) ) (defun p2s(p) (apply 'strcat (mapcar '(lambda (x) (fullstr (rtos x 2 Accuracydigit) 14)) p)) ) (defun line2param(ent) (list (p2s (dxf ent 10)) (p2s (dxf ent 11))) ) (defun lwpolyline2param(ent / tt z) (setq z (dxf ent 38) tt (vl-remove-if '(lambda (x) (/= (car x) 10) ) (entget ent)) tt (mapcar '(lambda (x) (p2s (append (cdr x) (list z)))) tt) ) tt ) (defun polyline2param(ent / kq) (setq ent (entnext ent) kq nil) (while (and ent (= (dxf ent 0) "VERTEX")) (setq kq (append kq (list (p2s (dxf ent 10)))) ent (entnext ent) ) ) kq ) (defun getpointindex(pp / tmp) (if (setq tmp (member pp points)) (1+ (- (length points) (length tmp))) (length (setq points (append points (list pp)))) ) ) (defun fullstr(str num / sl) (setq sl (- num (strlen str))) (repeat sl (setq str (strcat " " str)) ) ) (defun converttogeometry() (setq index 0 sl (if ss (sslength ss) 0) ) (repeat sl (setq ent (ssname ss index) ) (cond ((= (dxf ent 0) "LINE") (setq tmp (line2param ent))) ((= (dxf ent 0) "LWPOLYLINE") (setq tmp (lwpolyline2param ent))) (T (setq tmp (polyline2param ent))) ) (setq pline (strcat (fullstr (itoa (length tmp)) 5) " - points on layerboundary" (fullstr (itoa index) 6) "\n ") currentnumberinrow 0) (foreach point tmp (setq pline (strcat pline (fullstr (itoa (getpointindex point)) 5)) currentnumberinrow (1+ currentnumberinrow)) (if (>= currentnumberinrow 10) (progn (setq currentnumberinrow 0 pline (strcat pline "\n ")) ) ) ) (setq plines (append plines (list pline)) index (1+ index)) ) (princ) ) (defun getinput() (princ "\nPlease select LINE, POLYLINE: ") (setq ss (ssget '((0 . "*LINE"))) Accuracydigit (getint "\nEnter a integer value to choose Accuracy level (1=0.1, 2=0.01, 3=0.001,...)<2>: ") Accuracydigit (if Accuracydigit Accuracydigit 2) fname (getfiled "Please specify file" (getvar "dwgprefix") "geo" 1) ) ) (defun expten(count / kq) (setq kq 1.0) (repeat count (setq kq (* 10.0 kq)) ) ) (defun writeoutput() (setq fhnd (open fname "w")) (if (not fhnd) (alert (strcat "error when write to " fname)) (progn (write-line (strcat "GEOMETRY FILE FOR THE M-SERIES\n" "==============================================================================\n" "========================== BEGINNING OF DATA ==========================\n" "POINTS Accuracy = " (fullstr (rtos (/ 1.0 (expten Accuracydigit)) 2 4) 12) "\n" (fullstr (itoa (length points)) 5) " - Number of geometry-points -" ) fhnd ) (setq index 1) (foreach point points (write-line (strcat (fullstr (itoa index) 8) point) fhnd) (setq index (1+ index)) ) (write-line "LAYERS" fhnd) (write-line (strcat (fullstr (itoa (1- (length plines))) 5) " - Number of layers -") fhnd) (setq index 0) (foreach pline plines (write-line pline fhnd) (setq index (1+ index)) ) (write-line "" fhnd) (write-line "END OF DATA FILE" fhnd) (close fhnd) ) ) ) (defun c:cad2geo( / ss) (setq points nil) (setq plines nil) (getinput) (converttogeometry) (writeoutput) (alert "Export to file successfully!") (princ) )
Bác cho em hỏi là lisp này của Bác sao chỉ có thể export Line nhưng Circle thì không được. Em đang cần lisp này nhưng không biết phải edit đoạn code nào để có thể export thêm được Circle. Mong Bác chỉ giáo. Thanks Bác Nguyen Hoanh
- Tải lisp
- 146460_cad2geo.lsp
Cách dùng
- Tải tệp 146460_cad2geo.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 CAD2GEO để chạy lisp.
Mã nguồn 146460_cad2geo.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/33919-c%E1%BA%A7n-lisp-chuy%E1%BB%83n-dwgdxf-sang-plaxis/
(defun dxf(ent code)
(cdr (assoc code (entget ent)))
)
(defun p2s(p)
(apply 'strcat (mapcar '(lambda (x) (fullstr (rtos x 2 Accuracydigit) 14)) p))
)
(defun line2param(ent)
(list (p2s (dxf ent 10)) (p2s (dxf ent 11)))
)
(defun lwpolyline2param(ent / tt z)
(setq
z (dxf ent 38)
tt (vl-remove-if '(lambda (x) (/= (car x) 10) ) (entget ent))
tt (mapcar '(lambda (x) (p2s (append (cdr x) (list z)))) tt)
)
tt
)
(defun polyline2param(ent / kq)
(setq ent (entnext ent)
kq nil)
(while (and ent (= (dxf ent 0) "VERTEX"))
(setq kq (append kq (list (p2s (dxf ent 10))))
ent (entnext ent)
)
)
kq
)
(defun getpointindex(pp / tmp)
(if (setq tmp (member pp points))
(1+ (- (length points) (length tmp)))
(length (setq points (append points (list pp))))
)
)
(defun fullstr(str num / sl)
(setq sl (- num (strlen str)))
(repeat sl
(setq str (strcat " " str))
)
)
(defun converttogeometry()
(setq
index 0
sl (if ss (sslength ss) 0)
)
(repeat sl
(setq ent (ssname ss index)
)
(cond
((= (dxf ent 0) "LINE") (setq tmp (line2param ent)))
((= (dxf ent 0) "LWPOLYLINE") (setq tmp (lwpolyline2param ent)))
(T (setq tmp (polyline2param ent)))
)
(setq pline (strcat (fullstr (itoa (length tmp)) 5) " - points on layerboundary" (fullstr (itoa index) 6) "\n ")
currentnumberinrow 0)
(foreach point tmp
(setq pline (strcat pline (fullstr (itoa (getpointindex point)) 5))
currentnumberinrow (1+ currentnumberinrow))
(if (>= currentnumberinrow 10)
(progn
(setq currentnumberinrow 0
pline (strcat pline "\n "))
)
)
)
(setq plines (append plines (list pline))
index (1+ index))
)
(princ)
)
(defun getinput()
(princ "\nPlease select LINE, POLYLINE: ")
(setq ss (ssget '((0 . "*LINE")))
Accuracydigit (getint "\nEnter a integer value to choose Accuracy level (1=0.1, 2=0.01, 3=0.001,...)<2>: ")
Accuracydigit (if Accuracydigit Accuracydigit 2)
fname (getfiled "Please specify [.geo] file" (getvar "dwgprefix") "geo" 1)
)
)
(defun expten(count / kq)
(setq kq 1.0)
(repeat count
(setq kq (* 10.0 kq))
)
)
(defun writeoutput()
(setq fhnd (open fname "w"))
(if (not fhnd)
(alert (strcat "error when write to " fname))
(progn
(write-line (strcat
"GEOMETRY FILE FOR THE M-SERIES\n"
"==============================================================================\n"
"========================== BEGINNING OF DATA ==========================\n"
"POINTS Accuracy = " (fullstr (rtos (/ 1.0 (expten Accuracydigit)) 2 4) 12) "\n"
(fullstr (itoa (length points)) 5) " - Number of geometry-points -"
)
fhnd
)
(setq index 1)
(foreach point points
(write-line (strcat (fullstr (itoa index) 8) point) fhnd)
(setq index (1+ index))
)
(write-line "LAYERS" fhnd)
(write-line (strcat (fullstr (itoa (1- (length plines))) 5) " - Number of layers -") fhnd)
(setq index 0)
(foreach pline plines
(write-line pline fhnd)
(setq index (1+ index))
)
(write-line "" fhnd)
(write-line "END OF DATA FILE" fhnd)
(close fhnd)
)
)
)
(defun c:cad2geo( / ss)
(setq points nil)
(setq plines nil)
(getinput)
(converttogeometry)
(writeoutput)
(alert "Export to [.geo] file successfully!")
(princ)
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề Cần lisp chuyển dwg/dxf sang Plaxis. Xem đúng bài viết #146460 để đọc hướng dẫn và trao đổi thêm.