Jump to content

Lisp lệnh VDC trong chủ đề “Xin lisp vẽ đường chéo”

Sưu tầm.... chỉ vẽ được từng hình... dùng tạm nhé.

(defun c:vdc (/ pnt1 pnt2 pnt3 pnt4  lst e len n e1)

	(setq e (entget (car (entsel))))
	;get the entity list

	(setq len (length e))
	;get the length of the list

	(setq n 0)
	;set counter to zero
	(setq lst nil)
	(repeat len
	;repeat for the length of the entity list

	  (setq e1 (car (nth n e)))
	  ;get each item in the entity list
	  ;and strip the entity code number

	  (if (= e1 10)
	  ;check for code 10 (vertex)

	    (progn
	    ;if it's group 10 do the following

		(terpri)
		  ;new line
		(setq lst (if lst (append lst (list(cdr (nth n e))))(list(cdr (nth n e)))))	  
	    );progn

	  );if
	  (setq n (1+ n))
	  ;increment the counter

	);repeat
  (mapcar 'set '(pnt1 pnt2 pnt3 pnt4) lst)
  
	        (setq pnt1 (strcat(rtos(car pnt1))"," (rtos(cadr pnt1)) ",0"))
	      
		(setq pnt2 (strcat(rtos(car pnt2)) ","(rtos(cadr pnt2))",0"))

		(setq pnt3 (strcat(rtos(car pnt3)) ","(rtos(cadr pnt3))",0"))

		(setq pnt4 (strcat(rtos(car pnt4)) ","(rtos(cadr pnt4))",0"))

(command "line" pnt1 pnt3 "")
(command "line" pnt2 pnt4 "")
  (princ)
);defun
(princ)

Cách dùng

  1. Tải tệp 417296_vdc.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 VDC để chạy lisp.

Mã nguồn 417296_vdc.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/18387-xin-lisp-v%E1%BA%BD-%C4%91%C6%B0%E1%BB%9Dng-ch%C3%A9o/
(defun c:vdc (/ pnt1 pnt2 pnt3 pnt4  lst e len n e1)

	(setq e (entget (car (entsel))))
	;get the entity list

	(setq len (length e))
	;get the length of the list

	(setq n 0)
	;set counter to zero
	(setq lst nil)
	(repeat len
	;repeat for the length of the entity list

	  (setq e1 (car (nth n e)))
	  ;get each item in the entity list
	  ;and strip the entity code number

	  (if (= e1 10)
	  ;check for code 10 (vertex)

	    (progn
	    ;if it's group 10 do the following

		(terpri)
		  ;new line
		(setq lst (if lst (append lst (list(cdr (nth n e))))(list(cdr (nth n e)))))	  
	    );progn

	  );if
	  (setq n (1+ n))
	  ;increment the counter

	);repeat
  (mapcar 'set '(pnt1 pnt2 pnt3 pnt4) lst)
  
	        (setq pnt1 (strcat(rtos(car pnt1))"," (rtos(cadr pnt1)) ",0"))
	      
		(setq pnt2 (strcat(rtos(car pnt2)) ","(rtos(cadr pnt2))",0"))

		(setq pnt3 (strcat(rtos(car pnt3)) ","(rtos(cadr pnt3))",0"))

		(setq pnt4 (strcat(rtos(car pnt4)) ","(rtos(cadr pnt4))",0"))

(command "line" pnt1 pnt3 "")
(command "line" pnt2 pnt4 "")
  (princ)
);defun
(princ)

Thảo luận gốc

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

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