Jump to content

Lisp lệnh SHOW trong chủ đề “Giao diện hộp thoại trong AutoLisp”

Các bác có thể cho em 1 lisp ví dụ về dialog được không ah . Khi đánh lệnh ABC.. gì đó thì sẽ hiện lên bảng dialog . 1 bên là có 3 dòng với nội dung "hình tròn" "hình vuông" "tam giác" , bên kia là slide của 3 hình đó . Khi mình click vào hình slide hay dòng chữ thì sẽ thực thi ngay lệnh chứ không cần phải nhấp ok . Tất nhiên sau khi click sẽ có giai đoạn nhập R đường tròn , cạnh hình vuông hoặc kích thước tam giác .

Lisp này để em học hỏi , chứ nhiều lisp trên máy quá phức tạp và rất dài , em còn học nhiều nên chưa hiểu hết .

Em cảm ơn rất nhiều .

Bạn thu đoạn code này xem,

Tự tạo lay file *.Sld nhé

"htron.sld"

"hvuong.sld"

" htamgiac.sld"

đặt đường dẫn ở đoạn này

" im (strcat "c:\\" image)" trong funtion (fill-im) mình đang để là ổ c:\

Hy vọng giúp được bạn. Mình buông súng lâu rồi nên bây giờ viết chắc củ chuối lắm <_<

Nếu bạn không muốn lặp lại main dialog thì bỏ phần "(while ( >= redia 2 )" ở C:show đi

thuty.dcl

thuty: dialog{
label= "thu image button";
 :boxed_column {
:row{	
:icon_ima{
	key ="tron";
	}
:icon_ima{
	key ="vuong";

	}
:icon_ima{
	key ="tamgiac";

	}
 } //row  
: retirement_button {
		label		   = " Exit  ";
		key			 = "accept";
		is_default	  = true;
  }


 }//boxed_colum
}

// lap mot cai rieng >>> lap lai nhieu lan
icon_ima: image_button {
	color					= 0;
	allow_accept			= true;
	fixed_height			= true;
	fixed_width			 = true;
width 			=25;
height 			=9;

}


hinhtron: dialog{
label="hinh tron";
:edit_box{
	label	= "nhap ban kinh R";
	key	= "bankinh";
	value	= "0.0";

}

ok_cancel;
}

hinhvuong: dialog{
label="hinh vuong";
:edit_box{
	label	= "chieu dai canh";
	key	= "canh";
	value	= "0.0";

}

ok_cancel;

}

hinhtamgiac: dialog{
label="Hinh tam giac";
:edit_box{
	label	= "canh gi cung duoc";
	key	= "canhtamgiac";
	value	= "100.0";

}
:edit_box{
	label	= "goc gi cung duoc";
	key	= "goctamgiac";
	value	= 0.0;

}

ok_cancel;

}

 

Thuty.lsp

;;; load dialog
(defun loadcl (dia_name)
 (if (= -1 (setq dcl_id (load_dialog (strcat dia_name ".dcl"))))
(progn
  (alert (strcat dia_name ".dcl" "not found")
  (setq dialogloaded nil)
 )		 
) 
(setq dialogloaded 1)
) 
)
;;;=========================
;;; thu tuc dua anh nen 
(defun fill-im (image key / width height im)
(setq 	width (dimx_tile  key)
		  height (dimy_tile key)
;********************* CHU Y *****************************
; dat duong dan den file chua anh - image la anh can dua nen
;************************************************************
	im (strcat "c:\\" image)
	)
(start_image key)
(slide_image 0 0  width height im)  
(end_image)
)
;;; htron , hvuong , htamgiac la anh can dua nen
;;; thu tuc nay chi lam gon chuong trinh 
(defun appear-images ()
 (fill-im "htron" "tron")
 (fill-im "hvuong" "vuong")
 (fill-im "htamgiac" "tamgiac")

)
;;; Load subdialog tranh lap lai nhieu lan 
(defun td (dialogname)
  (if (not (new_dialog dialogname dcl_id)) (exit))
  (start_dialog)
  (done_dialog)
; dat mot so cac function kiem tra va lam viec voi subdialog

);end defun
;;;
;;; Chu y  chi la vi du ve cach hien thi dialog thoi
(defun td1 ()
  (if (not (new_dialog "hinhtron" dcl_id)) (exit))
  (start_dialog)
;CHU Y DAY CHI LA VI DU VE CANH HIEN THI DIALOG THOI
; 2 cach hien thi dialog thi dieu khien sub dialog khac nhau
; do thoi gian co han chi lay vi du thoi.

);end defun
;;;

(defun c:show (/ dcl_id dialogloaded redia r)
 (setq redia 2)
 (loadcl "thuty")
 (if (/= nil dialogloaded)
(progn
   (while ( >= redia 2 )
	  (progn
	  (if (not (new_dialog "thuty" dcl_id)) (exit)); break when error
	  (appear-images)
		  (action_tile  "tron" "(td1)(done_dialog 3)")
		  (action_tile  "vuong" "(setq r $key)(done_dialog 4)")
		  (action_tile  "tamgiac" "(setq r $key)(done_dialog 5)")
	  (action_tile  "accept" "(done_dialog 1)")
			(setq redia (start_dialog))
;;; Co mot so cach de goi Funtion khi tac dong Image
;;; Minh chi gioi thieu 2 cach thoi, khong co thoi gian
;;; Cach 1	  
		  (cond
	((eq r "vuong") (td "hinhvuong"))
	((eq r "tamgiac") (td "hinhtamgiac"))	
	  )
	  (setq r nil)
;;; cach 2
;;;			  (cond
;;;		((= redia 4) (td "hinhvuong"))
;;;		((= redia 5) (td "hinhtamgiac"))	
;;;		  ) 

	  );p
 );w
  (unload_dialog dcl_id)
  );p-f
(print "Error")
 );if  
);defun

Have fun,

Roberto Nguyen

Cách dùng

  1. Tải tệp 14375_show.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 SHOW để chạy lisp.

Mã nguồn 14375_show.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/1793-giao-di%E1%BB%87n-h%E1%BB%99p-tho%E1%BA%A1i-trong-autolisp/
;;; load dialog
(defun loadcl (dia_name)
 (if (= -1 (setq dcl_id (load_dialog (strcat dia_name ".dcl"))))
(progn
  (alert (strcat dia_name ".dcl" "not found")
  (setq dialogloaded nil)
 )		 
) 
(setq dialogloaded 1)
) 
)
;;;=========================
;;; thu tuc dua anh nen 
(defun fill-im (image key / width height im)
(setq 	width (dimx_tile  key)
		  height (dimy_tile key)
;********************* CHU Y *****************************
; dat duong dan den file chua anh - image la anh can dua nen
;************************************************************
	im (strcat "c:\\" image)
	)
(start_image key)
(slide_image 0 0  width height im)  
(end_image)
)
;;; htron , hvuong , htamgiac la anh can dua nen
;;; thu tuc nay chi lam gon chuong trinh 
(defun appear-images ()
 (fill-im "htron" "tron")
 (fill-im "hvuong" "vuong")
 (fill-im "htamgiac" "tamgiac")

)
;;; Load subdialog tranh lap lai nhieu lan 
(defun td (dialogname)
  (if (not (new_dialog dialogname dcl_id)) (exit))
  (start_dialog)
  (done_dialog)
; dat mot so cac function kiem tra va lam viec voi subdialog

);end defun
;;;
;;; Chu y  chi la vi du ve cach hien thi dialog thoi
(defun td1 ()
  (if (not (new_dialog "hinhtron" dcl_id)) (exit))
  (start_dialog)
;CHU Y DAY CHI LA VI DU VE CANH HIEN THI DIALOG THOI
; 2 cach hien thi dialog thi dieu khien sub dialog khac nhau
; do thoi gian co han chi lay vi du thoi.

);end defun
;;;

(defun c:show (/ dcl_id dialogloaded redia r)
 (setq redia 2)
 (loadcl "thuty")
 (if (/= nil dialogloaded)
(progn
   (while ( >= redia 2 )
	  (progn
	  (if (not (new_dialog "thuty" dcl_id)) (exit)); break when error
	  (appear-images)
		  (action_tile  "tron" "(td1)(done_dialog 3)")
		  (action_tile  "vuong" "(setq r $key)(done_dialog 4)")
		  (action_tile  "tamgiac" "(setq r $key)(done_dialog 5)")
	  (action_tile  "accept" "(done_dialog 1)")
			(setq redia (start_dialog))
;;; Co mot so cach de goi Funtion khi tac dong Image
;;; Minh chi gioi thieu 2 cach thoi, khong co thoi gian
;;; Cach 1	  
		  (cond
	((eq r "vuong") (td "hinhvuong"))
	((eq r "tamgiac") (td "hinhtamgiac"))	
	  )
	  (setq r nil)
;;; cach 2
;;;			  (cond
;;;		((= redia 4) (td "hinhvuong"))
;;;		((= redia 5) (td "hinhtamgiac"))	
;;;		  ) 

	  );p
 );w
  (unload_dialog dcl_id)
  );p-f
(print "Error")
 );if  
);defun

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Giao diện hộp thoại trong AutoLisp. Xem đúng bài viết #14375 để đọc hướng dẫn và trao đổi thêm.

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