Jump to content

Lisp lệnh GCD trong chủ đề “hỏi vấn đề tạo liên kết LSP và dialog DCL”

Xin lỗi bác Hạ, em mải mê làm việc nên lúc viết quên béng mất điều viết. Em sửa lại rồi bác ạ.

Trong câu 2 là em muốn lựa chọn bảng màu sắc cho chữ đó bác. Nếu viết trong DCL thì viết như nào ạ? và cách gọi nó ra thì ntn ạ?

Trong 3 thì em chưa biết cách gán layer lựa chọn hay style  lựa chọn cho Text.

Em vừa sửa lại thấy tự dưng có layer mới xuất hiện mà em ko tạo ra. Cái này em cảm thấy hơi lạ

 

GHICHU
: dialog
{
label = "Ch\U+01B0\U+01A1ng tr\U+00ECnh ghi ch\U+00FA";
	: boxed_column
	{
		: edit_box
		{
			label = "Nh\U+1EADp t\U+00EAn c\U+1EA7n vi\U+1EBFt ghi ch\U+00FA";
			key = "Text_ghichu";
			edit_width = 30;
			alignment = left;
			edit_limit = 50;
			value = "Vi\U+1EBFt ghi ch\U+00FA v\U+00E0o \U+0111\U+00E2y";

		}
		: edit_box
		{
			label = "Nh\U+1EADp chi\U+1EC1u cao ch\U+1EEF:";
			key = "Height_Text";
			edit_width = 3.0;
			alignment = left;
			edit_limit = 5;
			value = 1;
		}


	}
	: boxed_column
	{
        	: row
		{
		 : column
		 {
		      : popup_list
		      {
		          label       = "L\U+1EF1a ch\U+1ECDn Layer" ;
		          key         = "LTSLAY" ;
		          edit_width  = 50 ;  
		          list        = "" ;
		          alignment = left;
		      }
		      : popup_list
		      {
		          label       = "L\U+1EF1a ch\U+1ECDn TextStyle" ;
		          key         = "LTSTEXTSTYLE" ;
		          edit_width  = 50 ;  
		          list        = "" ;
		          alignment = left;
		      }
		 }
		}
	}	
	: boxed_column
	{
		: button
		{
			label = "Pick >>>";
			key = "Accept";
			is_default = true;
			fixed_width = centered;
		}
		: button
		{
			label = "H\U+1EE7y";
			key = "Cancel";
			is_default = false;
			fixed_width = centered;
		}

	}

}

 

(defun C:GCD ( / dcl_id  LtsLayer LtsStyle h Text_ghichu )
(setq dcl_id (load_dialog "GHICHU.DCL"))
(if (not (new_dialog "GHICHU" dcl_id))
 (exit)
)

  
(action_tile "Text_ghichu"  "(setq TextGhiChu $value)")
(mode_tile "Text_ghichu" 2)
(action_tile "Height_Text"  "(setq h $value)")
(mode_tile "Height_Text" 2)
(action_tile "Text_ghichu"  "(setq TextGhiChu $value)")

(setq LtsLayer_ (Getlayer))
(start_list "LTSLAY")
(mapcar 'add_list  LtsLayer_)
(end_list)
(set_tile "LTSLAY" "0")
(action_tile "LTSLAY" "(setq LayerText_ $value)")


(setq LtsStyle_ (GetTextStyle))
(start_list "LTSTEXTSTYLE")
(mapcar 'add_list  LtsStyle_)
(end_list)

;;;(action_tile "LTSTEXTSTYLE" "(setq TextStyle_ $value)")
  

(action_tile "Accept" "(setq UseButton 1)(done_dialog)")
(action_tile "Cancel" "(setq UseButton 2)(done_dialog)")

(start_dialog)
(unload_dialog dcl_id)
(if (= UseButton 1)
	(progn
		(GCT TextGhiChu h LayerText_ )
	)
)
(if (= UseButton 2)
	(alert (strcat "\nTho\U+00E1t"))
)


(Princ)
)




(defun Getlayer ( / lyr LstLayer)
(vlax-for lyr
	(vla-get-layers
		(vla-get-activedocument
			(vlax-get-acad-object)
	        )
        )		
(setq LstLayer (cons (vla-get-name lyr) LstLayer))
)
LstLayer
)




(defun GetTextStyle ( / styl_  LstTextStyle)
(vlax-for styl_
	(vla-get-textstyles
		(vla-get-activedocument
			(vlax-get-acad-object)
	        )
        )		
(setq LstTextStyle (cons (vla-get-name styl_) LstTextStyle))
)
LstTextStyle
)


(defun GCT(TextGhiChu h LayerText  / i Olmode Gocxoay);;;;GHI CHU TEXT
(setq i 0)
(while
  	(setvar "OSMODE" 0)
	(setq P1 (Getpoint "\nCh\U+1ECDn \U+0111i\U+1EC3m ch\U+00E8n TEXT ghi ch\U+00FA: :  "))
	(setq P2 (Getpoint  P1 "\nChon huong ghi chu TEXT:  "))
  	(setq Gocxoay (Angle (trans P1 1 0)
                             (trans P2 1 0)
		      )
	)
	(command "Style" "Times New Roman"  "Times New Roman"  0 1 0 "" "" "" )
;;;	(entmake (list  (cons 0 "TEXT") (cons 10 P1) (cons 8 LayerText) (cons 40 (atof h)) (cons 50 Gocxoay) (cons 7 TextStyle) (cons 1 TextGhiChu)))
  	(entmake (list  (cons 0 "TEXT") (cons 10 P1) (cons 8 LayerText) (cons 40 (atof h)) (cons 50 Gocxoay)(cons 7 "Times New Roman")   (cons 1 TextGhiChu)))
  	(setq i (1+ i))
)
)

;;;-------------------------------------------------------------


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 310284_gcd.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 GCD để chạy lisp.

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

GHICHU
: dialog
{
label = "Ch\U+01B0\U+01A1ng tr\U+00ECnh ghi ch\U+00FA";
	: boxed_column
	{
		: edit_box
		{
			label = "Nh\U+1EADp t\U+00EAn c\U+1EA7n vi\U+1EBFt ghi ch\U+00FA";
			key = "Text_ghichu";
			edit_width = 30;
			alignment = left;
			edit_limit = 50;
			value = "Vi\U+1EBFt ghi ch\U+00FA v\U+00E0o \U+0111\U+00E2y";

		}
		: edit_box
		{
			label = "Nh\U+1EADp chi\U+1EC1u cao ch\U+1EEF:";
			key = "Height_Text";
			edit_width = 3.0;
			alignment = left;
			edit_limit = 5;
			value = 1;
		}


	}
	: boxed_column
	{
        	: row
		{
		 : column
		 {
		      : popup_list
		      {
		          label       = "L\U+1EF1a ch\U+1ECDn Layer" ;
		          key         = "LTSLAY" ;
		          edit_width  = 50 ;  
		          list        = "" ;
		          alignment = left;
		      }
		      : popup_list
		      {
		          label       = "L\U+1EF1a ch\U+1ECDn TextStyle" ;
		          key         = "LTSTEXTSTYLE" ;
		          edit_width  = 50 ;  
		          list        = "" ;
		          alignment = left;
		      }
		 }
		}
	}	
	: boxed_column
	{
		: button
		{
			label = "Pick >>>";
			key = "Accept";
			is_default = true;
			fixed_width = centered;
		}
		: button
		{
			label = "H\U+1EE7y";
			key = "Cancel";
			is_default = false;
			fixed_width = centered;
		}

	}

}

(defun C:GCD ( / dcl_id  LtsLayer LtsStyle h Text_ghichu )
(setq dcl_id (load_dialog "GHICHU.DCL"))
(if (not (new_dialog "GHICHU" dcl_id))
 (exit)
)

  
(action_tile "Text_ghichu"  "(setq TextGhiChu $value)")
(mode_tile "Text_ghichu" 2)
(action_tile "Height_Text"  "(setq h $value)")
(mode_tile "Height_Text" 2)
(action_tile "Text_ghichu"  "(setq TextGhiChu $value)")

(setq LtsLayer_ (Getlayer))
(start_list "LTSLAY")
(mapcar 'add_list  LtsLayer_)
(end_list)
(set_tile "LTSLAY" "0")
(action_tile "LTSLAY" "(setq LayerText_ $value)")


(setq LtsStyle_ (GetTextStyle))
(start_list "LTSTEXTSTYLE")
(mapcar 'add_list  LtsStyle_)
(end_list)

;;;(action_tile "LTSTEXTSTYLE" "(setq TextStyle_ $value)")
  

(action_tile "Accept" "(setq UseButton 1)(done_dialog)")
(action_tile "Cancel" "(setq UseButton 2)(done_dialog)")

(start_dialog)
(unload_dialog dcl_id)
(if (= UseButton 1)
	(progn
		(GCT TextGhiChu h LayerText_ )
	)
)
(if (= UseButton 2)
	(alert (strcat "\nTho\U+00E1t"))
)


(Princ)
)




(defun Getlayer ( / lyr LstLayer)
(vlax-for lyr
	(vla-get-layers
		(vla-get-activedocument
			(vlax-get-acad-object)
	        )
        )		
(setq LstLayer (cons (vla-get-name lyr) LstLayer))
)
LstLayer
)




(defun GetTextStyle ( / styl_  LstTextStyle)
(vlax-for styl_
	(vla-get-textstyles
		(vla-get-activedocument
			(vlax-get-acad-object)
	        )
        )		
(setq LstTextStyle (cons (vla-get-name styl_) LstTextStyle))
)
LstTextStyle
)


(defun GCT(TextGhiChu h LayerText  / i Olmode Gocxoay);;;;GHI CHU TEXT
(setq i 0)
(while
  	(setvar "OSMODE" 0)
	(setq P1 (Getpoint "\nCh\U+1ECDn \U+0111i\U+1EC3m ch\U+00E8n TEXT ghi ch\U+00FA: :  "))
	(setq P2 (Getpoint  P1 "\nChon huong ghi chu TEXT:  "))
  	(setq Gocxoay (Angle (trans P1 1 0)
                             (trans P2 1 0)
		      )
	)
	(command "Style" "Times New Roman"  "Times New Roman"  0 1 0 "" "" "" )
;;;	(entmake (list  (cons 0 "TEXT") (cons 10 P1) (cons 8 LayerText) (cons 40 (atof h)) (cons 50 Gocxoay) (cons 7 TextStyle) (cons 1 TextGhiChu)))
  	(entmake (list  (cons 0 "TEXT") (cons 10 P1) (cons 8 LayerText) (cons 40 (atof h)) (cons 50 Gocxoay)(cons 7 "Times New Roman")   (cons 1 TextGhiChu)))
  	(setq i (1+ i))
)
)

;;;-------------------------------------------------------------

Thảo luận gốc

Lisp được chia sẻ trong chủ đề hỏi vấn đề tạo liên kết LSP và dialog DCL. Xem đúng bài viết #310284 để đọc hướng dẫn và trao đổi thêm.

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