Jump to content

Nhờ viết lisp vẽ thống kê hư hỏng cục bộ mặt đường

mọi người bớt chút thời gian giúp em với ạ  :mellow: . Cảm ơn

Hề hề hề,

Thiệt tình là mình chả muốn làm cái ni do chả hiểu hết ý bạn. Song thấy bạn cần nên đành đoán mò theo hình vẽ mà làm vậy. 

Đây chỉ là bản nháp nên có thể chưa đúng ý bạn, bạn có thể tự chỉnh lại về kiểu hatch cũng như màu sắc mà bạn muốn.

Bạn hãy dùng thử coi đã ưng cái bụng chưa nhé. Nếu chưa ưng thì post lên nói rõ vì sao chưa ưng. Cố gắng trình bày cho rõ ràng để may ra mình có thể hiểu mà sửa theo ý bạn.

 

(defun c:vhhmd (/ oldos p h e e1 olcol fn f dlst ln lst)
(vl-load-com)
(setq oldos (getvar "osmode"))
(setvar "osmode" 0)
(command "undo" "be")
(setq p (getpoint "\n Chon diem bat dau ve")
          h (getreal "\n Nhap chieu rong mat duong: ") )
(if (not h) (setq h 7))
(command "line" p (polar p 0 100) "")
(setq e (entlast))
(command "copy" e "" p (polar p (/ pi 2) h))
(if (not (tblsearch "ltype" "center2"))
    (command "linetype" "l" "center2" "")
)
(command "linetype" "s" "center2" "")
(setq olcol (getvar "cecolor"))
(setvar "cecolor" "6")
(command "line" (polar p (/ pi 2) (/ h 2.0)) (list (+ (car p) 100) (+ (cadr p) (/ h 2.0))) "")
(setvar "cecolor" olcol)
(command "linetype" "s" "bylayer" "")
(setq  fn (getfiled "Select Data File" "" "txt" 0)
            f (open fn "r")
            dlst (list)
)
(while (setq ln (read-line f))
      (setq dlst (append dlst (list ln)))
)
(foreach d dlst
    (setq lst (separate d "\t"))
    (command "rectangle" (list (+ (car p) (atof (nth 0 lst))) (+ (cadr p) (atof (nth 2 lst))))
                                           (list (+ (car p) (atof (nth 1 lst))) (+ (cadr p) (atof (nth 2 lst)) (atof (nth 3 lst))))  )
    (setq e1 (entlast))
    (if (= (nth 4 lst) "1")
         (command "hatch" "ansi31" 10 0 e1 "")
         (command "hatch" "ansi31" 10 90 e1 "")
    )
   (command "text" "j" "mc" (list (+ (car p) (/ (abs (- (atof (nth 0 lst)) (atof (nth 1 lst)))) 2) (atof (nth 0 lst))) 
                                                      (+ (cadr p) (atof (nth 2 lst)) (/ (atof (nth 3 lst)) 2))) 1 0
                                                      (strcat (nth 3 lst) " x " (rtos (abs (- (atof (nth 0 lst)) (atof (nth 1 lst)))) 2 0)))
    (if (<= (atof (nth 2 lst)) (/ h 2))
        (progn
              (command "text" "j" "mc" (list (+ (car p) (atof (nth 0 lst))) (- (cadr p) 2)) 1 270 (nth 0 lst))
              (command "text" "j" "mc" (list (+ (car p) (atof (nth 1 lst))) (- (cadr p) 2)) 1 270 (nth 1 lst))
        )
        (progn
              (command "text" "j" "mc" (list (+ (car p) (atof (nth 0 lst))) (+ (cadr p) h 2)) 1 270 (nth 0 lst))
              (command "text" "j" "mc" (list (+ (car p) (atof (nth 1 lst))) (+ (cadr p) h 2)) 1 270 (nth 1 lst))
        )
    )
)
(command "undo" "e")
(setvar "osmode" oldos)
(princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun Separate (S sym / i L ch)
(setq i 0 L nil)
(while (< i (strlen S))
 (setq i (1+ i) ch (substr S i 1))
 (if (= ch sym) (progn
(setq
     L (append L (list (substr S 1 (- i 1))))
     S (substr S (1+ i) (- (strlen S) i))
     i 0
)
      )) 
)
(append L (list S))
)

Cách dùng

  1. Tải tệp 271191_vhhmd.lsp về máy.
  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 VHHMD để chạy lisp.

Mã nguồn 271191_vhhmd.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/89792-y%C3%AAu-c%E1%BA%A7u-nh%E1%BB%9D-vi%E1%BA%BFt-lisp-v%E1%BA%BD-th%E1%BB%91ng-k%C3%AA-h%C6%B0-h%E1%BB%8Fng-c%E1%BB%A5c-b%E1%BB%99-m%E1%BA%B7t-%C4%91%C6%B0%E1%BB%9Dng/
(defun c:vhhmd (/ oldos p h e e1 olcol fn f dlst ln lst)
(vl-load-com)
(setq oldos (getvar "osmode"))
(setvar "osmode" 0)
(command "undo" "be")
(setq p (getpoint "\n Chon diem bat dau ve")
          h (getreal "\n Nhap chieu rong mat duong: ") )
(if (not h) (setq h 7))
(command "line" p (polar p 0 100) "")
(setq e (entlast))
(command "copy" e "" p (polar p (/ pi 2) h))
(if (not (tblsearch "ltype" "center2"))
    (command "linetype" "l" "center2" "")
)
(command "linetype" "s" "center2" "")
(setq olcol (getvar "cecolor"))
(setvar "cecolor" "6")
(command "line" (polar p (/ pi 2) (/ h 2.0)) (list (+ (car p) 100) (+ (cadr p) (/ h 2.0))) "")
(setvar "cecolor" olcol)
(command "linetype" "s" "bylayer" "")
(setq  fn (getfiled "Select Data File" "" "txt" 0)
            f (open fn "r")
            dlst (list)
)
(while (setq ln (read-line f))
      (setq dlst (append dlst (list ln)))
)
(foreach d dlst
    (setq lst (separate d "\t"))
    (command "rectangle" (list (+ (car p) (atof (nth 0 lst))) (+ (cadr p) (atof (nth 2 lst))))
                                           (list (+ (car p) (atof (nth 1 lst))) (+ (cadr p) (atof (nth 2 lst)) (atof (nth 3 lst))))  )
    (setq e1 (entlast))
    (if (= (nth 4 lst) "1")
         (command "hatch" "ansi31" 10 0 e1 "")
         (command "hatch" "ansi31" 10 90 e1 "")
    )
   (command "text" "j" "mc" (list (+ (car p) (/ (abs (- (atof (nth 0 lst)) (atof (nth 1 lst)))) 2) (atof (nth 0 lst))) 
                                                      (+ (cadr p) (atof (nth 2 lst)) (/ (atof (nth 3 lst)) 2))) 1 0
                                                      (strcat (nth 3 lst) " x " (rtos (abs (- (atof (nth 0 lst)) (atof (nth 1 lst)))) 2 0)))
    (if (<= (atof (nth 2 lst)) (/ h 2))
        (progn
              (command "text" "j" "mc" (list (+ (car p) (atof (nth 0 lst))) (- (cadr p) 2)) 1 270 (nth 0 lst))
              (command "text" "j" "mc" (list (+ (car p) (atof (nth 1 lst))) (- (cadr p) 2)) 1 270 (nth 1 lst))
        )
        (progn
              (command "text" "j" "mc" (list (+ (car p) (atof (nth 0 lst))) (+ (cadr p) h 2)) 1 270 (nth 0 lst))
              (command "text" "j" "mc" (list (+ (car p) (atof (nth 1 lst))) (+ (cadr p) h 2)) 1 270 (nth 1 lst))
        )
    )
)
(command "undo" "e")
(setvar "osmode" oldos)
(princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun Separate (S sym / i L ch)
(setq i 0 L nil)
(while (< i (strlen S))
 (setq i (1+ i) ch (substr S i 1))
 (if (= ch sym) (progn
(setq
     L (append L (list (substr S 1 (- i 1))))
     S (substr S (1+ i) (- (strlen S) i))
     i 0
)
      )) 
)
(append L (list S))
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề [yêu cầu] Nhờ viết lisp vẽ thống kê hư hỏng cục bộ mặt đường. Xem đúng bài viết #271191 để đọc hướng dẫn và trao đổi thêm.

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