Jump to content

Lisp lệnh DML trong chủ đề “Xin Lisp Thống Kê Chiều Dài Mline”

-Lisp tính tổng chiều dài mline theo style, scale, layer. Tên lệnh DML

-Về lý thuyết thì thống kê các đường Mline có đủ các thuộc tính là làm được nhưng đề ko rỏ nên không giải.

(defun c:dml ( / txt)

 (initget "ST LA SA")
 (setq txt (getkword "\nLoc MLINE theo  <ST>: "))
 (cond
   ((not txt)
   (setq kieu " thuoc STYLE: <") (setq mdxf 2))
   ((= "ST" txt)
   (setq kieu " thuoc STYLE: <") (setq mdxf 2))
   ((= "LA" txt)
   (setq kieu " thuoc LAYER: <") (setq mdxf 8))
   ((= "SA" txt)
   (setq kieu " co SCALE: <") (setq mdxf 40))
 )

(setq ketqua (cdr (assoc mdxf (entget (car (chonmotmline))))))
(setq ss (ssget (list (cons 0 "MLINE") (cons mdxf ketqua))))
  (setq tot_len 0.0)
  (setq sml (sslength ss))

  (while (> (sslength ss) 0)
    (setq e_name (ssname ss 0))
    (setq e_record (entget e_name))
    (setq e_type (cdr (assoc '0 e_record)))
    (cond ((wcmatch e_type "LINE,ARC,CIRCLE,POLYLINE,LWPOLYLINE,ELLIPSE,SPLINE")
	   (command "lengthen" e_name "")
	   (setq tot_len (+ tot_len (getvar "PERIMETER")))
	   (ssdel e_name ss)
	  )
	  ((wcmatch e_type "MLINE") (add_mline))
	  (e_type (ssdel e_name ss))
    )
  )

  (cond ((= "SA" txt) (setq ketqua (rtos ketqua 2 2)) ))
  (prompt (strcat "\nTim thay: " (itoa sml) " doi tuong MLINE" kieu ketqua "> tong chieu dai=" (rtos tot_len 2 2)))


(princ))
;;;;;;;;;;;;;;
(defun chonmotmline ( / dchon)
(setq dchon (entsel "\nChon Mline chuan:"))
(while
(or
(null (car dchon))
(and (/= "MLINE" (cdr (assoc 0 (entget (car dchon)))))
)
)
(princ "\nDoi tuong khong phai MLINE. Chon lai !")
(setq dchon (entsel))
)
dchon)
;;;;;;;;;;;;;;
(defun add_mline ()
  (foreach e_record_sub	e_record
    (cond ((= 10 (car e_record_sub))
	   (setq pt1	   (cdr e_record_sub)
		 mline_len 0.0
	   )
	  )
	  ((= 11 (car e_record_sub))
	   (setq pt2	   (cdr e_record_sub)
		 mline_len (+ mline_len (distance pt2 pt1))
		 pt1	   pt2
	   )
	  )
    )
  )
  (setq tot_len (+ tot_len mline_len))
  (ssdel e_name ss)
)

(lisp có sử dụng phần tính tổng mline của kexu)

Cách dùng

  1. Tải tệp 428518_dml.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 DML để chạy lisp.

Mã nguồn 428518_dml.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/168542-xin-lisp-th%E1%BB%91ng-k%C3%AA-chi%E1%BB%81u-d%C3%A0i-mline/
(defun c:dml ( / txt)

 (initget "ST LA SA")
 (setq txt (getkword "\nLoc MLINE theo [STyle/LAyer/SAcle] <ST>: "))
 (cond
   ((not txt)
   (setq kieu " thuoc STYLE: <") (setq mdxf 2))
   ((= "ST" txt)
   (setq kieu " thuoc STYLE: <") (setq mdxf 2))
   ((= "LA" txt)
   (setq kieu " thuoc LAYER: <") (setq mdxf 8))
   ((= "SA" txt)
   (setq kieu " co SCALE: <") (setq mdxf 40))
 )

(setq ketqua (cdr (assoc mdxf (entget (car (chonmotmline))))))
(setq ss (ssget (list (cons 0 "MLINE") (cons mdxf ketqua))))
  (setq tot_len 0.0)
  (setq sml (sslength ss))

  (while (> (sslength ss) 0)
    (setq e_name (ssname ss 0))
    (setq e_record (entget e_name))
    (setq e_type (cdr (assoc '0 e_record)))
    (cond ((wcmatch e_type "LINE,ARC,CIRCLE,POLYLINE,LWPOLYLINE,ELLIPSE,SPLINE")
	   (command "lengthen" e_name "")
	   (setq tot_len (+ tot_len (getvar "PERIMETER")))
	   (ssdel e_name ss)
	  )
	  ((wcmatch e_type "MLINE") (add_mline))
	  (e_type (ssdel e_name ss))
    )
  )

  (cond ((= "SA" txt) (setq ketqua (rtos ketqua 2 2)) ))
  (prompt (strcat "\nTim thay: " (itoa sml) " doi tuong MLINE" kieu ketqua "> tong chieu dai=" (rtos tot_len 2 2)))


(princ))
;;;;;;;;;;;;;;
(defun chonmotmline ( / dchon)
(setq dchon (entsel "\nChon Mline chuan:"))
(while
(or
(null (car dchon))
(and (/= "MLINE" (cdr (assoc 0 (entget (car dchon)))))
)
)
(princ "\nDoi tuong khong phai MLINE. Chon lai !")
(setq dchon (entsel))
)
dchon)
;;;;;;;;;;;;;;
(defun add_mline ()
  (foreach e_record_sub	e_record
    (cond ((= 10 (car e_record_sub))
	   (setq pt1	   (cdr e_record_sub)
		 mline_len 0.0
	   )
	  )
	  ((= 11 (car e_record_sub))
	   (setq pt2	   (cdr e_record_sub)
		 mline_len (+ mline_len (distance pt2 pt1))
		 pt1	   pt2
	   )
	  )
    )
  )
  (setq tot_len (+ tot_len mline_len))
  (ssdel e_name ss)
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Xin Lisp Thống Kê Chiều Dài Mline. Xem đúng bài viết #428518 để đọc hướng dẫn và trao đổi thêm.

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