Jump to content

Lisp lệnh FAO trong chủ đề “Em xin trợ giúp chuyển lip cad từ tính m2 thành hecta ạ”

của Bạn đây

(defun c:fao (/ bn ld as lt 2v 3d e p p1 p2 _att a en)
  (vl-load-com)
  (setq	bn "SDDMOI"
	ld "KHIEU"
	as "DTICH"
	lt "TENBLOCK"
  )					;Change by user
  (or *st* (setq *st* 1))
  (setq	2v vlax-ename->vla-object
	3d vlax-3D-point
  ) ;_ end of setq
  (while (not (setq s (ssget "_+.:E:S" (list (cons 2 bn)))))
    (princ "\nMiss!")
  ) ;_ end of while
  (setq	e    (2v (ssname s 0))
	*st* (cond ((getint (strcat "Start Number <" (itoa *st*) ">:")))
		   (*st*)
	     ) ;_ end of cond
	p    (getpoint "\nBase point :")
	p1   (3d p)
	_att (lambda (b tag v / r)
	       (foreach	at (vlax-invoke b 'GetAttributes)
		 (if (eq tag (vla-get-TagString at))
		   (setq r
			  (if v
			    (vla-put-textstring at v)
			    (vla-get-textstring at)
			  ) ;_ end of if
		   ) ;_ end of setq
		 ) ;_ end of if
	       ) ;_ end of foreach
	       r
	     ) ;_ end of lambda
  ) ;_ end of setq
  (while (setq p2 (acet-ss-drag-move s p "\nTo :"))
    (cond ((setq en (bpoly p2))
	   (setq a (vla-get-area (2v en)))
	   (entdel en)
	   (vla-move (setq n (vla-copy e)) p1 (3d p2))
	   (_att n
		 ld
		 (strcat
		   (_att n lt nil)
		   (if (< *st* 10)
		     "-0"
		     "-"
		   ) ;_ end of if
		   (itoa *st*)
		 ) ;_ end of strcat
	   ) ;_ end of _att
	   (_att n as (vl-string-translate "." "," (rtos (* a 0.0001) 2 4))); thay doi dong nay
	   (setq *st* (1+ *st*))
	  )
    ) ;_ end of cond
  ) ;_ end of while
) ;_ end of defun

 

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 434258_fao.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 FAO để chạy lisp.

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

(defun c:fao (/ bn ld as lt 2v 3d e p p1 p2 _att a en)
  (vl-load-com)
  (setq	bn "SDDMOI"
	ld "KHIEU"
	as "DTICH"
	lt "TENBLOCK"
  )					;Change by user
  (or *st* (setq *st* 1))
  (setq	2v vlax-ename->vla-object
	3d vlax-3D-point
  ) ;_ end of setq
  (while (not (setq s (ssget "_+.:E:S" (list (cons 2 bn)))))
    (princ "\nMiss!")
  ) ;_ end of while
  (setq	e    (2v (ssname s 0))
	*st* (cond ((getint (strcat "Start Number <" (itoa *st*) ">:")))
		   (*st*)
	     ) ;_ end of cond
	p    (getpoint "\nBase point :")
	p1   (3d p)
	_att (lambda (b tag v / r)
	       (foreach	at (vlax-invoke b 'GetAttributes)
		 (if (eq tag (vla-get-TagString at))
		   (setq r
			  (if v
			    (vla-put-textstring at v)
			    (vla-get-textstring at)
			  ) ;_ end of if
		   ) ;_ end of setq
		 ) ;_ end of if
	       ) ;_ end of foreach
	       r
	     ) ;_ end of lambda
  ) ;_ end of setq
  (while (setq p2 (acet-ss-drag-move s p "\nTo :"))
    (cond ((setq en (bpoly p2))
	   (setq a (vla-get-area (2v en)))
	   (entdel en)
	   (vla-move (setq n (vla-copy e)) p1 (3d p2))
	   (_att n
		 ld
		 (strcat
		   (_att n lt nil)
		   (if (< *st* 10)
		     "-0"
		     "-"
		   ) ;_ end of if
		   (itoa *st*)
		 ) ;_ end of strcat
	   ) ;_ end of _att
	   (_att n as (vl-string-translate "." "," (rtos (* a 0.0001) 2 4))); thay doi dong nay
	   (setq *st* (1+ *st*))
	  )
    ) ;_ end of cond
  ) ;_ end of while
) ;_ end of defun

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Em xin trợ giúp chuyển lip cad từ tính m2 thành hecta ạ. Xem đúng bài viết #434258 để đọc hướng dẫn và trao đổi thêm.

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