Jump to content

Lisp lệnh VET trong chủ đề “LISP VẼ ĐƯỜNG ỐNG 3D trên AutoCAD”

khà khà :D :D :D

 

Bỏ chạy lâu ngày ko ngoảnh mặt lại, khi trở lại nước đã rút nhưng cứ tưởng rằng chẳng ai cần nên ko code :D

 

>>> Hàng đây, ném đá đi :D :D :D

;lisp ve te theo D & d nhap vao
(defun c:VET()
(setq os (getvar 'osmode)
	  lay (getvar "clayer")
	  cmd (getvar 'cmdecho))
(mapcar 'setvar (list 'osmode 'cmdecho) '(0 0))
;================================
;ham bay loi
(setq temperr *error*)
(defun errorTrap (msg)
    (and os (setvar 'osmode os))
	(and lay (setvar "clayer" lay))
	(and cmd (setvar 'cmdecho cmd))
	(cond
		((tblsearch "ucs" "save_ucs_ve_T") 
			(command "ucs" "na" "r" "save_ucs_ve_T")
			(command "ucs" "na" "d" "save_ucs_ve_T")
			)
	)
    (setq *error* temperr)
	(princ "\n*** Da set lai bien, OK ! ***")
    (princ)
)
(setq *error* errorTrap)
;======het ham bay loi = P1 ============================
;===========================================================================================
(command "ucs" "na" "s" "save_ucs_ve_T")
(setq #D_lon (NGT #D_lon 254. getdist "Nhap duong kinh ong lon (D)")
	  #d_nho (NGT #d_nho 204. getdist "Nhap duong kinh ong nho (d)")
	  bl_name (strcat "T_" (rtos #D_lon 2 0) "_" (rtos #d_nho 2 0))
)
(if (tblsearch "layer" bl_name) 
			(setvar "clayer" bl_name) 
			(command "layer" "m" bl_name "c" "t" "45,159,225" "" "")
			)	;if
;=========================================================================================
(if (not (tblsearch "block" bl_name))
	(progn
		(command "ucs" "na" "w")
		(command "CYLINDER" (list 0 0 (- #d_nho)) (/ #D_lon 2.) (* 2 #d_nho))
		(setq part_1 (entlast))
		(command "ucs" "za" "" '(1 0 0))
		(command "CYLINDER" '(0 0 0) (/ #d_nho 2.) (+ (/ #D_lon 2.) (/ #d_nho 4.)))
		(command "_.union" part_1 (entlast) "")
		(command "ucs" "za" "" '(-1 0 0))
		(command "-block" bl_name '(0 0 0) (entlast) "")
		(command "ucs" "na" "r" "save_ucs_ve_T")
	)
)	;Neu chua co _ tao block Te
;==========================================================================================
(if (and
		(setq base_pt (getpoint "\nChon diem giao tim 02 tuyen ong: "))
		(setq pt1 (getpoint "\nChon diem thuoc tim tuyen ong lon: "))
		(setq pt2 (getpoint "\nChon diem thuoc tim tuyen ong nho: "))
		(not (equal base_pt pt1 (setq fuzz (/ #d_nho 100))))
		(not (equal base_pt pt2 fuzz))
		(not (equal pt2 pt1 fuzz))
	)
	(progn
		(command "ucs" "3p" base_pt pt2 pt1)
		(command "insert" bl_name '(0 0 0) "" "" "")
	)
)
(command "ucs" "na" "r" "save_ucs_ve_T")
(command "ucs" "na" "d" "save_ucs_ve_T")
(setq *error* temperr)
(setvar 'osmode os)
(setvar "clayer" lay)
(setvar 'cmdecho cmd)
(princ "\nOK !")
(princ)
)
;===================================================================================================
(defun NGT(a mac_dinh ham str_nhac / modul)
;;Nhan gia tri
(or a (setq a mac_dinh))
(setq a (cond
	((= "" (setq modul (ham (strcat "\n" str_nhac " <" (vl-princ-to-string a) ">: ")))) a)
	(modul)
	(a)
	)
	)
)

Cách dùng

  1. Tải tệp 328272_vet.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 VET để chạy lisp.

Mã nguồn 328272_vet.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/112854-lisp-v%E1%BA%BD-%C4%91%C6%B0%E1%BB%9Dng-%E1%BB%91ng-3d-tr%C3%AAn-autocad/?page=2
;lisp ve te theo D & d nhap vao
(defun c:VET()
(setq os (getvar 'osmode)
	  lay (getvar "clayer")
	  cmd (getvar 'cmdecho))
(mapcar 'setvar (list 'osmode 'cmdecho) '(0 0))
;================================
;ham bay loi
(setq temperr *error*)
(defun errorTrap (msg)
    (and os (setvar 'osmode os))
	(and lay (setvar "clayer" lay))
	(and cmd (setvar 'cmdecho cmd))
	(cond
		((tblsearch "ucs" "save_ucs_ve_T") 
			(command "ucs" "na" "r" "save_ucs_ve_T")
			(command "ucs" "na" "d" "save_ucs_ve_T")
			)
	)
    (setq *error* temperr)
	(princ "\n*** Da set lai bien, OK ! ***")
    (princ)
)
(setq *error* errorTrap)
;======het ham bay loi = P1 ============================
;===========================================================================================
(command "ucs" "na" "s" "save_ucs_ve_T")
(setq #D_lon (NGT #D_lon 254. getdist "Nhap duong kinh ong lon (D)")
	  #d_nho (NGT #d_nho 204. getdist "Nhap duong kinh ong nho (d)")
	  bl_name (strcat "T_" (rtos #D_lon 2 0) "_" (rtos #d_nho 2 0))
)
(if (tblsearch "layer" bl_name) 
			(setvar "clayer" bl_name) 
			(command "layer" "m" bl_name "c" "t" "45,159,225" "" "")
			)	;if
;=========================================================================================
(if (not (tblsearch "block" bl_name))
	(progn
		(command "ucs" "na" "w")
		(command "CYLINDER" (list 0 0 (- #d_nho)) (/ #D_lon 2.) (* 2 #d_nho))
		(setq part_1 (entlast))
		(command "ucs" "za" "" '(1 0 0))
		(command "CYLINDER" '(0 0 0) (/ #d_nho 2.) (+ (/ #D_lon 2.) (/ #d_nho 4.)))
		(command "_.union" part_1 (entlast) "")
		(command "ucs" "za" "" '(-1 0 0))
		(command "-block" bl_name '(0 0 0) (entlast) "")
		(command "ucs" "na" "r" "save_ucs_ve_T")
	)
)	;Neu chua co _ tao block Te
;==========================================================================================
(if (and
		(setq base_pt (getpoint "\nChon diem giao tim 02 tuyen ong: "))
		(setq pt1 (getpoint "\nChon diem thuoc tim tuyen ong lon: "))
		(setq pt2 (getpoint "\nChon diem thuoc tim tuyen ong nho: "))
		(not (equal base_pt pt1 (setq fuzz (/ #d_nho 100))))
		(not (equal base_pt pt2 fuzz))
		(not (equal pt2 pt1 fuzz))
	)
	(progn
		(command "ucs" "3p" base_pt pt2 pt1)
		(command "insert" bl_name '(0 0 0) "" "" "")
	)
)
(command "ucs" "na" "r" "save_ucs_ve_T")
(command "ucs" "na" "d" "save_ucs_ve_T")
(setq *error* temperr)
(setvar 'osmode os)
(setvar "clayer" lay)
(setvar 'cmdecho cmd)
(princ "\nOK !")
(princ)
)
;===================================================================================================
(defun NGT(a mac_dinh ham str_nhac / modul)
;;Nhan gia tri
(or a (setq a mac_dinh))
(setq a (cond
	((= "" (setq modul (ham (strcat "\n" str_nhac " <" (vl-princ-to-string a) ">: ")))) a)
	(modul)
	(a)
	)
	)
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề LISP VẼ ĐƯỜNG ỐNG 3D trên AutoCAD. Xem đúng bài viết #328272 để đọc hướng dẫn và trao đổi thêm.

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