Jump to content

Lisp lệnh GETSTYLE trong chủ đề “List Tất Cả Layer, Teststyle, Dimstyle Trong Bản Vẽ Hiện Hành”

;20160204-GETSTYLE
;--------------------------------------------DIALOG-------------------------------------------------------
;getstyle : dialog { //dialog name
;	label = "Select Layer, Textstyle, Dimstyle" ; //give it a label
;		: column { 
;			: popup_list { //define list box
;						key = "sel_lyr"; //give it a name
;						label = "Select layer";
;						value = "0"; //initial value
;			} //end list
;			: popup_list { //define list box
;						key = "sel_tst"; //give it a name
;						label = "Select textstyle";
;						value = "0"; //initial value
;			} //end list
;			: popup_list { //define list box
;						key = "sel_dst"; //give it a name
;						label = "Select dimstyle";
;						value = "0"; //initial value
;			} //end list
;		} //end column
;	ok_cancel ; //predifined OK/Cancel 
;} //end dialog
;--------------------------------------------lISP-------------------------------------------------------
(defun C:GETSTYLE( / table_lyr table_tst table_dst lyrs tsts dsts);define funcion
	(setvar "cmdecho" 0);switch off command echo
	;Get list of all Layer
	(vlax-for lyr
		(vla-get-layers
			(vla-get-activedocument
				(vlax-get-acad-object)
			)
		)
		(setq table_lyr (cons (vla-get-name lyr) table_lyr))
	)
	;Get list of all Textstyles
	(vlax-for tst
		(vla-get-textstyles
			(vla-get-activedocument
				(vlax-get-acad-object)
			)
		)
		(setq table_tst (cons (vla-get-name tst) table_tst))
	)
	;Get list of all Dimstyles
	(vlax-for dst
		(vla-get-dimstyles
			(vla-get-activedocument
				(vlax-get-acad-object)
			)
		)
		(setq table_dst (cons (vla-get-name dst) table_dst))
	)
	(setq dcl_id (load_dialog "getstyle.dcl"))		;load dialogue
	(if (not (new_dialog "getstyle" dcl_id)			;check for errors
		)											;not
		(exit)										;if problem exit
	)												;if
	;Layer
	(set_tile "sel_lyr" "0")						;initilise list box
	(start_list "sel_lyr")							;start the list
	(mapcar 'add_list table_lyr)					;add the layer table_lyr
	(end_list)										;end the list
	;Textstyles
	(set_tile "sel_tst" "0")						;initilise list box
	(start_list "sel_tst")							;start the list
	(mapcar 'add_list table_tst)					;add the layer table_tst
	(end_list)										;end the list
	;Dimstyles
	(set_tile "sel_dst" "0")						;initilise list box
	(start_list "sel_dst")							;start the list
	(mapcar 'add_list table_dst)					;add the layer table_dst
	(end_list)										;end the list	
	;Action
	(action_tile "accept" "(setq ddiag 2)(Assign_value)(done_dialog)")
	(action_tile "cancel" "(setq ddiag 1)(done_dialog)")
	(start_dialog)									;Display the dialog box
	(unload_dialog dcl_id)							;Unload the dialog box
	(if(= ddiag 1)									;If the user pressed the Cancel button
		(princ "\n Cancelled!")
	)
	(if(= ddiag 2)									; If the user pressed the Okay button
		(progn
		  (alert (strcat "\nYou Selected Layer:" lyrs ",Textstyle: " tsts ",Dimstyle: " dsts))
		)
	);end if
	(princ)
);defun

	(defun Assign_value()
		;Layer
		(setq lyrs (nth (atoi (get_tile sel_lyr)) sel_lyr)) 
		;Textstyles
		(setq tsts (nth (atoi (get_tile sel_tst)) sel_tst)) 
		;Dimstyles
		(setq dsts (nth (atoi (get_tile sel_dst)) sel_dst))
	)

Xin lỗi, vì có thể vấn đề này hơi bi dư thừa cho nhiều người. Nhưng mình đang găp thắc mắc.

1.       Nhờ moi người sửa giúp đoan lisp trên.

2.       Chỉ ra lỗi của nó.

3.       Theo mình biết thì muốn có Dialog (hôp thoai) thì cần có 1 file .dcl để goi khi chay. Nhưng trong đoan lisp mình xem trên Lee Mac thì nó đươc tích hơp trong .lsp luôn. Vây, cách tao nó như thế nào. Có thể áp dung trong bài này luôn đươc không?

Xin cảm ơn!

Cách dùng

  1. Tải tệp 393207_getstyle.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 GETSTYLE để chạy lisp.

Mã nguồn 393207_getstyle.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/158654-list-t%E1%BA%A5t-c%E1%BA%A3-layer-teststyle-dimstyle-trong-b%E1%BA%A3n-v%E1%BA%BD-hi%E1%BB%87n-h%C3%A0nh/
;20160204-GETSTYLE
;--------------------------------------------DIALOG-------------------------------------------------------
;getstyle : dialog { //dialog name
;	label = "Select Layer, Textstyle, Dimstyle" ; //give it a label
;		: column { 
;			: popup_list { //define list box
;						key = "sel_lyr"; //give it a name
;						label = "Select layer";
;						value = "0"; //initial value
;			} //end list
;			: popup_list { //define list box
;						key = "sel_tst"; //give it a name
;						label = "Select textstyle";
;						value = "0"; //initial value
;			} //end list
;			: popup_list { //define list box
;						key = "sel_dst"; //give it a name
;						label = "Select dimstyle";
;						value = "0"; //initial value
;			} //end list
;		} //end column
;	ok_cancel ; //predifined OK/Cancel 
;} //end dialog
;--------------------------------------------lISP-------------------------------------------------------
(defun C:GETSTYLE( / table_lyr table_tst table_dst lyrs tsts dsts);define funcion
	(setvar "cmdecho" 0);switch off command echo
	;Get list of all Layer
	(vlax-for lyr
		(vla-get-layers
			(vla-get-activedocument
				(vlax-get-acad-object)
			)
		)
		(setq table_lyr (cons (vla-get-name lyr) table_lyr))
	)
	;Get list of all Textstyles
	(vlax-for tst
		(vla-get-textstyles
			(vla-get-activedocument
				(vlax-get-acad-object)
			)
		)
		(setq table_tst (cons (vla-get-name tst) table_tst))
	)
	;Get list of all Dimstyles
	(vlax-for dst
		(vla-get-dimstyles
			(vla-get-activedocument
				(vlax-get-acad-object)
			)
		)
		(setq table_dst (cons (vla-get-name dst) table_dst))
	)
	(setq dcl_id (load_dialog "getstyle.dcl"))		;load dialogue
	(if (not (new_dialog "getstyle" dcl_id)			;check for errors
		)											;not
		(exit)										;if problem exit
	)												;if
	;Layer
	(set_tile "sel_lyr" "0")						;initilise list box
	(start_list "sel_lyr")							;start the list
	(mapcar 'add_list table_lyr)					;add the layer table_lyr
	(end_list)										;end the list
	;Textstyles
	(set_tile "sel_tst" "0")						;initilise list box
	(start_list "sel_tst")							;start the list
	(mapcar 'add_list table_tst)					;add the layer table_tst
	(end_list)										;end the list
	;Dimstyles
	(set_tile "sel_dst" "0")						;initilise list box
	(start_list "sel_dst")							;start the list
	(mapcar 'add_list table_dst)					;add the layer table_dst
	(end_list)										;end the list	
	;Action
	(action_tile "accept" "(setq ddiag 2)(Assign_value)(done_dialog)")
	(action_tile "cancel" "(setq ddiag 1)(done_dialog)")
	(start_dialog)									;Display the dialog box
	(unload_dialog dcl_id)							;Unload the dialog box
	(if(= ddiag 1)									;If the user pressed the Cancel button
		(princ "\n Cancelled!")
	)
	(if(= ddiag 2)									; If the user pressed the Okay button
		(progn
		  (alert (strcat "\nYou Selected Layer:" lyrs ",Textstyle: " tsts ",Dimstyle: " dsts))
		)
	);end if
	(princ)
);defun

	(defun Assign_value()
		;Layer
		(setq lyrs (nth (atoi (get_tile sel_lyr)) sel_lyr)) 
		;Textstyles
		(setq tsts (nth (atoi (get_tile sel_tst)) sel_tst)) 
		;Dimstyles
		(setq dsts (nth (atoi (get_tile sel_dst)) sel_dst))
	)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề List Tất Cả Layer, Teststyle, Dimstyle Trong Bản Vẽ Hiện Hành. Xem đúng bài viết #393207 để đọc hướng dẫn và trao đổi thêm.

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