Jump to content

Lisp phun điểm mia

Nhờ các anh chi em sưa giúp lisp phun diem mia. Mình muốn bỏ phần cao độ Z đi

;CHUONG TRINH PHUN DIEM MIA X,Y,Z
;CAC DIEM TRAM MAY CO CODE=1 SE DUOC NOI LAI VOI NHAU
;-------------DINH DANG MAU----------------------
;TENDIEM   X      Y    Z    CODE
;KV1         0      0    0    1
;KV2       10      0    0    1
;1       5      10    0
;2       10      6    0
;KV3       10      10    0    1
(defun c:pdm (/ ms PR FN thunhat tentram caodotram xtram ytram
        htram tentrammay tendh
        )
  (bdau)
  (setq tam ())
  (setq i 0)
 ;  (setq ms 1000)
  (setq
    FN (getfiled "NhËp file nguån : "
         ""
         ""
         4
       )
  )
 (SETQ MS (GETREAL "Nhap vao mau so ty le ban do : "))
(setq ms (* ms 2))
  (progn
    (command "-osnap" "")
    (setvar "cmdecho" 0)
    (setvar "luprec" 8)
    (setvar "pdmode" 0)          
    (command "-layer" "m" "diem" "c" "red" "" "")
    (command "-layer" "m" "caodo" "c" "cyan" "" "")
    (command "-layer" "m" "sothutu" "c" "magenta" "" "")
    (command "-layer" "m" "khongche" "c" "red" "" "")
    (setq st (/ ms 1000))
    (setq st1 st)
    (command "-style" "diemmia" "txt.shx" st1 "1" "0" "n" "n" "n")
    (setq FN (open FN "r"))
    (while (and (setq PR (read-line FN)) (/= PR ""))
      (progn
        (setq PR (strcat "(" PR ")"))
        (setq PR (read PR))
        (thuchien)
    (if (= (nth 4 PR) 1);neu code= 1 thi ve
    (ve)
        )
      )                    ;end progn
    )                    ;end while
  );end progn
  (close FN)
  (command "zoom" "e")
  (kthuc)
  (princ)
)
(defun thuchien (/ TEN )
  (setq ten (convtostr (nth 0 PR)));chuyen tu symbol sang string
  (setq td (list (nth 2 PR) (nth 1 PR) (nth 3 PR)))
  (setq tam (append tam td));dua toa do diem thu n vao trong list tam
  (command "-layer" "s" "diem" "")
  (command "point" td)
  (command "-style" "diemmia" "txt.shx" st1  "1" "0" "n" "n" "n")
  (command "-layer" "s" "sothutu" "")
  (command "text" td "" ten)
  (command "-style" "diemmia" "txt.shx" st1 "1" "0" "n" "n" "n")
  (command "-layer" "s" "caodo" "")
  (command "text" "tl" td "" (rtos (nth 3 PR) 2 1))
)
(defun ve ()
  (setq diemcuoi td)
  (if (/= i 0)
    (progn
      (command "line" diemdau diemcuoi "")
    )
  )
  (setq diemdau diemcuoi)
  (setq i (+ i 1))
)
;CHUONG TRINH CHUYEN HAI COT X VA Y CHO NHAU
;---------DINH DANG MAU----------
;TEN       X      Y     Z    CODE
;KV1    100.00    50.00    1.5    1
;KV2    200.00    31.00    2.1
(defun c:chuyencot(/ FN FD i ch PR TEN X Y Z CODE TD XUAT)
  (setq
    FN (getfiled "NhËp file nguån : "
         ""
         ""
         4
       )
  )
  (setq i (strlen FN))
  (setq ch "")
     (while (/= ch "\\")
       (setq ch (substr FN i 1))
       (setq i (- i 1))
     )
     (setq xuat (substr FN 1  (+ i 1)))
  (setq FD (getstring "Nhap ten file ket qua : "))
  (setq FD (strcat xuat FD))
  (setq FD (open FD "w"))
  (setq FN (open FN "r"))
  (while (and (setq PR (read-line FN)) (/= PR ""))
      (progn
        (setq PR (strcat "(" PR ")"))
        (setq PR (read PR))
    (setq ten (dd (convtostr (nth 0 PR))))
        (setq x (dd (convtostr (nth 1 PR))))
    (setq y (dd (convtostr (nth 2 PR))))
    (setq z (dd (convtostr (nth 3 PR))))
    (setq code (nth 4 PR))
    (if (/= code nil)
      (setq td (strcat ten y x z (convtostr code)))
      (setq td (strcat ten y x z))
    )
    (write-line td FD)
      )                    ;end progn
    )                    ;end while
  (close FD)
  (close FN)
)

(defun bdau ()
  (command "_.undo" "begin")
  (setq cmd (getvar "cmdecho"))
  (setq plwid (getvar "plinewid"))
  (setq elev (getvar "elevation"))
  (setq thick (getvar "thickness"))
  (setq hh (getvar "osmode"))
  (setq clay (getvar "clayer"))
)
(defun kthuc ()
  (command "plinewid" plwid)
  (command "elevation" elev)
  (command "thickness" thick)
  (command "osmode" hh)
  (command "_.undo" "end")
  (command "clayer" clay)
  (command "cmdecho" cmd)
)
(defun ConvtoStr (Sym)
  (setq ftemp "temp.tmp")
  (setq ftmp (open ftemp "w"))
  (princ Sym ftmp)
  (close ftmp)
  (setq ftmp (open ftemp "r"))
  (setq sym (read-line ftmp))
  (close ftmp)
  (princ sym)
)
(defun *error*(msg)
       (princ "\nerror:")
       (princ msg)
(command "osmode" h "")
(command "_.undo" "end")
(command "clayer" clay)
(command "u" "")
(alert          "  - - - - ha ha ha- - - -
<Chaudaubac 0913.167111> ")
    (setq *error* olderr)
(princ)
)
(defun dd (nhap)
  (setq len (strlen nhap))
  (cond ((= len 1)(setq xuat (strcat nhap "        ")))
        ((= len 2)(setq xuat (strcat nhap "       ")))
        ((= len 3)(setq xuat (strcat nhap "      ")))
        ((= len 4)(setq xuat (strcat nhap "     ")))
        ((= len 5)(setq xuat (strcat nhap "    ")))
        ((= len 6)(setq xuat (strcat nhap "   ")))
        ((= len 7)(setq xuat (strcat nhap "  ")))
        ((= len 8)(setq xuat (strcat nhap " ")))
        ((= len 9)(setq xuat (strcat nhap "")))
  )
)
 
________________________________________________

File So Lieu

1    2339097.81    549068.55    1
2    2339127.18    549077.58    2
3    2339131.33    549078.35    3
4    2339135.72    549077.89    4
5    2339139.53    549076.32    5
6    2339142.77    549073.78    6
7    2339302.5    548908.23    7
8    2339294.43    548887.96    8
9    2339402.91    548767.01    9
10    2339273.21    548697.27    10
11    2339253.31    548705.86    11
12    2339231.99    548709.79    12
13    2339210.33    548708.84    13
14    2339175.48    548820.72    14
15    2339172.28    548830.99    15
16    2339114.96    549015.01    16
17    2339106.61    549041.66    17

https://www.cadviet.com/upfiles/4/139428_

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 333679_pdm_chuyencot.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 PDM CHUYENCOT để chạy lisp.

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

;CHUONG TRINH PHUN DIEM MIA X,Y,Z
;CAC DIEM TRAM MAY CO CODE=1 SE DUOC NOI LAI VOI NHAU
;-------------DINH DANG MAU----------------------
;TENDIEM   X      Y    Z    CODE
;KV1         0      0    0    1
;KV2       10      0    0    1
;1       5      10    0
;2       10      6    0
;KV3       10      10    0    1
(defun c:pdm (/ ms PR FN thunhat tentram caodotram xtram ytram
        htram tentrammay tendh
        )
  (bdau)
  (setq tam ())
  (setq i 0)
 ;  (setq ms 1000)
  (setq
    FN (getfiled "NhËp file nguån : "
         ""
         ""
         4
       )
  )
 (SETQ MS (GETREAL "Nhap vao mau so ty le ban do : "))
(setq ms (* ms 2))
  (progn
    (command "-osnap" "")
    (setvar "cmdecho" 0)
    (setvar "luprec" 8)
    (setvar "pdmode" 0)          
    (command "-layer" "m" "diem" "c" "red" "" "")
    (command "-layer" "m" "caodo" "c" "cyan" "" "")
    (command "-layer" "m" "sothutu" "c" "magenta" "" "")
    (command "-layer" "m" "khongche" "c" "red" "" "")
    (setq st (/ ms 1000))
    (setq st1 st)
    (command "-style" "diemmia" "txt.shx" st1 "1" "0" "n" "n" "n")
    (setq FN (open FN "r"))
    (while (and (setq PR (read-line FN)) (/= PR ""))
      (progn
        (setq PR (strcat "(" PR ")"))
        (setq PR (read PR))
        (thuchien)
    (if (= (nth 4 PR) 1);neu code= 1 thi ve
    (ve)
        )
      )                    ;end progn
    )                    ;end while
  );end progn
  (close FN)
  (command "zoom" "e")
  (kthuc)
  (princ)
)
(defun thuchien (/ TEN )
  (setq ten (convtostr (nth 0 PR)));chuyen tu symbol sang string
  (setq td (list (nth 2 PR) (nth 1 PR) (nth 3 PR)))
  (setq tam (append tam td));dua toa do diem thu n vao trong list tam
  (command "-layer" "s" "diem" "")
  (command "point" td)
  (command "-style" "diemmia" "txt.shx" st1  "1" "0" "n" "n" "n")
  (command "-layer" "s" "sothutu" "")
  (command "text" td "" ten)
  (command "-style" "diemmia" "txt.shx" st1 "1" "0" "n" "n" "n")
  (command "-layer" "s" "caodo" "")
  (command "text" "tl" td "" (rtos (nth 3 PR) 2 1))
)
(defun ve ()
  (setq diemcuoi td)
  (if (/= i 0)
    (progn
      (command "line" diemdau diemcuoi "")
    )
  )
  (setq diemdau diemcuoi)
  (setq i (+ i 1))
)
;CHUONG TRINH CHUYEN HAI COT X VA Y CHO NHAU
;---------DINH DANG MAU----------
;TEN       X      Y     Z    CODE
;KV1    100.00    50.00    1.5    1
;KV2    200.00    31.00    2.1
(defun c:chuyencot(/ FN FD i ch PR TEN X Y Z CODE TD XUAT)
  (setq
    FN (getfiled "NhËp file nguån : "
         ""
         ""
         4
       )
  )
  (setq i (strlen FN))
  (setq ch "")
     (while (/= ch "\\")
       (setq ch (substr FN i 1))
       (setq i (- i 1))
     )
     (setq xuat (substr FN 1  (+ i 1)))
  (setq FD (getstring "Nhap ten file ket qua : "))
  (setq FD (strcat xuat FD))
  (setq FD (open FD "w"))
  (setq FN (open FN "r"))
  (while (and (setq PR (read-line FN)) (/= PR ""))
      (progn
        (setq PR (strcat "(" PR ")"))
        (setq PR (read PR))
    (setq ten (dd (convtostr (nth 0 PR))))
        (setq x (dd (convtostr (nth 1 PR))))
    (setq y (dd (convtostr (nth 2 PR))))
    (setq z (dd (convtostr (nth 3 PR))))
    (setq code (nth 4 PR))
    (if (/= code nil)
      (setq td (strcat ten y x z (convtostr code)))
      (setq td (strcat ten y x z))
    )
    (write-line td FD)
      )                    ;end progn
    )                    ;end while
  (close FD)
  (close FN)
)

(defun bdau ()
  (command "_.undo" "begin")
  (setq cmd (getvar "cmdecho"))
  (setq plwid (getvar "plinewid"))
  (setq elev (getvar "elevation"))
  (setq thick (getvar "thickness"))
  (setq hh (getvar "osmode"))
  (setq clay (getvar "clayer"))
)
(defun kthuc ()
  (command "plinewid" plwid)
  (command "elevation" elev)
  (command "thickness" thick)
  (command "osmode" hh)
  (command "_.undo" "end")
  (command "clayer" clay)
  (command "cmdecho" cmd)
)
(defun ConvtoStr (Sym)
  (setq ftemp "temp.tmp")
  (setq ftmp (open ftemp "w"))
  (princ Sym ftmp)
  (close ftmp)
  (setq ftmp (open ftemp "r"))
  (setq sym (read-line ftmp))
  (close ftmp)
  (princ sym)
)
(defun *error*(msg)
       (princ "\nerror:")
       (princ msg)
(command "osmode" h "")
(command "_.undo" "end")
(command "clayer" clay)
(command "u" "")
(alert          "  - - - - ha ha ha- - - -
<Chaudaubac 0913.167111> ")
    (setq *error* olderr)
(princ)
)
(defun dd (nhap)
  (setq len (strlen nhap))
  (cond ((= len 1)(setq xuat (strcat nhap "        ")))
        ((= len 2)(setq xuat (strcat nhap "       ")))
        ((= len 3)(setq xuat (strcat nhap "      ")))
        ((= len 4)(setq xuat (strcat nhap "     ")))
        ((= len 5)(setq xuat (strcat nhap "    ")))
        ((= len 6)(setq xuat (strcat nhap "   ")))
        ((= len 7)(setq xuat (strcat nhap "  ")))
        ((= len 8)(setq xuat (strcat nhap " ")))
        ((= len 9)(setq xuat (strcat nhap "")))
  )
)
 
________________________________________________

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Nhờ sửa lisp. Xem đúng bài viết #333679 để đọc hướng dẫn và trao đổi thêm.

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