Jump to content

Lisp lệnh TG2A trong chủ đề “Đo kích thước nhiều line”

 

1 lệnh cũng được, nhiều lệnh cũng được, trên diễn đàn có lisp để bạn là việc này rồi mà.Bạn chịu khó search nhé.Trường hợp của bạn có thể dùng lệnh nối các line liền nhau lại thành 1 Pline, khi đó khối lượng công việc giảm đi nhiều

Còn đây là 1 lisp tính tổng chiều dài các đoạn được chọn.

;; free lisp from cadviet.com @Bommak(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));;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;(defun WriteRes(kq / OK e data)(setq OK nil)(while (not OK)(setq e (car (entsel "\tChon text ghi ket qua:")))(if (CheckObj e "TEXT") (setq OK T) (princ "\nDoi tuong chon khong phai text")))(entmod (subst (cons 1 (rtos kq 2 2)) (assoc 1 (setq data (entget e))) data))(princ));;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;(defun C:tg2a (/ tot_len ss e_name e_record e_type)  (setq tot_len 0.0)  (setq ss (ssget))  (if (null ss)    (exit)  )  (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))    )  );De dong nay neu muon cong them gia tri vao kq	;(setq tot_len (+ tot_len (getreal "\nGia tri cong them : ")))  (writeres tot_len))

Mình có dùng cái lipsp này của bạn nhưng cũng đến bước chọn text ghi kết quả là nó cũng bị lỗi. Bạn kia nói không rõ lắm thôi, sau đây là lỗi trên dòng command "ketxu" à:

Command: TG2A

Select objects: 1 found

Select objects: 1 found, 2 total

Select objects:

Current length: 4.91263

Current length: 0.47663   Chon text ghi ket qua:; error: no function

definition: CHECKOBJ

Command:

Nó có tính được chiều dài các đối tượng rồi nhưng đến ghi ra text thì bị lỗi

Bạn xem lại xem có gì sai sót ko vì khi mình dùng lisp TL để tính chiều dài thì ngon lành nhưng nó chỉ tính được có 1 đối tượng mà thôi

Mình search nên giờ mới thấy topic này

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 244745_tg2a.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 TG2A để chạy lisp.

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

;; free lisp from cadviet.com @Bommak(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));;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;(defun WriteRes(kq / OK e data)(setq OK nil)(while (not OK)(setq e (car (entsel "\tChon text ghi ket qua:")))(if (CheckObj e "TEXT") (setq OK T) (princ "\nDoi tuong chon khong phai text")))(entmod (subst (cons 1 (rtos kq 2 2)) (assoc 1 (setq data (entget e))) data))(princ));;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;(defun C:tg2a (/ tot_len ss e_name e_record e_type)  (setq tot_len 0.0)  (setq ss (ssget))  (if (null ss)    (exit)  )  (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))    )  );De dong nay neu muon cong them gia tri vao kq	;(setq tot_len (+ tot_len (getreal "\nGia tri cong them : ")))  (writeres tot_len))

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Đo kích thước nhiều line. Xem đúng bài viết #244745 để đọc hướng dẫn và trao đổi thêm.

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