Chuyển đến nội dung
Diễn đàn CADViet
abidime

Cần lisp chuyển dwg/dxf sang Plaxis

Các bài được khuyến nghị

Tôi cần lisp hỗ trợ import file autocad (dxf hoặc dwg) sang file plaxis (geometry only). Cảm ơn nhiều.

Lisp dưới đây sẽ giúp bạn chuyển dữ liệu từ AutoCAD sang file [.geo]. Tên lệnh là cad2geo

The lisp routine below will help you to transfer data from AutoCAD to [.geo] 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 [.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)
)

  • Vote tăng 3

Chia sẻ bài đăng này


Liên kết tới bài đăng
Chia sẻ trên các trang web khác

Lisp dưới đây sẽ giúp bạn chuyển dữ liệu từ AutoCAD sang file [.geo]. Tên lệnh là cad2geo

The lisp routine below will help you to transfer data from AutoCAD to [.geo] 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 [.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)
)

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

Chia sẻ bài đăng này


Liên kết tới bài đăng
Chia sẻ trên các trang web khác

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

Bó tay thôi,

 

Mình không rành về Plaxis, chỉ đọc định dạng thông qua các cấu trúc mà chương trình khai báo. Làm được với Line là 'may mắn' lắm rồi.

Chia sẻ bài đăng này


Liên kết tới bài đăng
Chia sẻ trên các trang web khác

Tạo một tài khoản hoặc đăng nhập để nhận xét

Bạn cần phải là một thành viên để lại một bình luận

Tạo tài khoản

Đăng ký một tài khoản mới trong cộng đồng của chúng tôi. Điều đó dễ mà.

Đăng ký tài khoản mới

Đăng nhập

Bạn có sẵn sàng để tạo một tài khoản ? Đăng nhập tại đây.

Đăng nhập ngay

×