Jump to content

cần hướng dẫn giúp gộp file.dcl vào trong file.lsp

Không biết mọi người có tham khảo được gì ở LISP này không? 

;;;TAO TEXTSTYLE
(command "-Style" "Times New Roman"  "Times New Roman" 0 1 0 "" "" "" )
(vl-load-com)
;;;KHI LOAD LISP SE HIEN LEN THONG BAO TEN LENH
(Prompt (strcat "\nL\U+1EC7nh ghi ch\U+00FA Text l\U+00E0: GCT2"))

(defun C:GCT2(  / file tmp dch return );;;;;;;GHI CHU TEXT CACH 2
    (cond
      (
        (not
          (and (setq file (open (setq tmp (vl-filename-mktemp nil nil ".dcl")) "w"))
            (write-line
              (strcat
	"	GHICHU"
	"	: dialog"
	"	{"
	"	label = \"Ch\U+01B0\U+01A1ng tr\U+00ECnh vi\U+1EBFt ghi ch\U+00FA Text\";"
	"	            : 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 = 25; alignment = left; value = \"Nh\U+1EADp n\U+1ED9i dung 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; value = 1;"
	"	                        }"
	"	            }"
	"	            : boxed_column"
	"	            {"
	"	            : row"
	"	                        {"
	"	                         : column"
	"	                         {"
	"	                              : popup_list"
	"	                              {"
	"	                                  label = \"L\U+1EF1a ch\U+1ECDn Layer\" ; key = \"LTSLAY\" ; edit_width  = 25 ; list = \"\" ; alignment = left;"
	"	                              }"
	"	                              : popup_list"
	"	                              {"
	"	                                  label = \"L\U+1EF1a ch\U+1ECDn TextStyle\" ; key = \"LTSTEXTSTYLE\" ; edit_width  = 25 ; list = \"\" ; alignment = left;"
	"	                              }"
	"				      spacer;spacer;"
	"				      :row"
	"				      { "
	"					: text"
	"					{"
	"						label = \"Ch\U+1ECDn Color\"; alignment =left;"
	"					}"
	"					: image_button"
	"					{"
	"						key = \"color\"; alignment = centered; height = 1.5; width = 1.0;	fixed_width = false;   fixed_height = true;"
	"					}"
	"				       }"
	"		                         }"
	"	                        }"
	"	            }"
	"	spacer;"
	"	            ok_cancel;"
	"	spacer;spacer;"
	"	:text"
	"	{"
	"		label= \"Ng\U+01B0\U+1EDDi vi\U+1EBFt: Nguy\U+1EC5n Th\U+00E0nh Du\U+00E2n - \U+0110\U+1ECBa Ch\U+00EDnh K48 - 0972.0168.25\";"
	"		alignment= left;"
	"	}"
	"	}"
              )
              file
            )
            (not (close file)) (< 0 (setq dch (load_dialog tmp))) (new_dialog "GHICHU" dch)
          )
        )
      )
      (t
		(action_tile "Text_ghichu"  "(setq TextGhiChu $value)")
		;;;;;;CHO PHEP NHAP NOI DUNG VAO
		(mode_tile "Text_ghichu" 2)
		;;;GAN BIEN CHO TEXTBOX CAO CHU
		(action_tile "Height_Text"  "(setq #Height $value)")
		;;;;;;CHO PHEP NHAP NOI DUNG VAO
		(mode_tile "Height_Text" 2)
		;;;TAO 1 DANH SACH CHUA CAC LAYER CO TRONG BAN VE
		(start_list "LTSLAY")
		(mapcar 'add_list (setq LstLayer (Getlayer)))
		(end_list)


		(if TextGhiChu
			(set_tile "Text_ghichu" TextGhiChu)
			(set_tile "Text_ghichu" "Nh\U+1EADp n\U+1ED9i dung ghi ch\U+00FA v\U+00E0o \U+0111\U+00E2y")
		)

		;;;;GAN LAYER 
		(if #CurLay
			(set_tile "LTSLAY" #CurLay)
			(set_tile "LTSLAY"  "0")
		)
       		(if #Height
			(set_tile "Height_Text" #Height)
			(set_tile "Height_Text"  "1.0")
		)
		(action_tile "LTSLAY" "(setq #CurLay $value)")
		;;;GAN MAU SAC
		(if (null #Color) (setq #Color 2))
		(fill-rec "color" #Color )
		(action_tile "color" "(if (setq #color (acad_colordlg #color)) (fill-rec \"color\" #color ))")
		 
		 ;;;;TAO 1 DANH SACH CHUA CAC TEXTSTYLE
		(start_list "LTSTEXTSTYLE")
		(mapcar 'add_list (setq LstTextStyle (GetTextStyle)))
		(end_list)
		  
		 ;;;;GAN TEXTSTYLE
		(if #CurStyle
			(set_tile "LTSTEXTSTYLE" #CurStyle)
			(set_tile "LTSTEXTSTYLE" "Standard")
		)

		  
		(action_tile "LTSTEXTSTYLE" "(setq #CurStyle $value)")
		;;;;GAN CAC BIEN CHO NOI DUNG GHI CHU, LAYER, TEXTSTYLE
		(if (not TextGhiChu) (setq TextGhiChu (get_tile "Text_ghichu")))
       		(if (not #Height) (setq #Height (get_tile "Height_Text")))
		(if (not #CurLay) (setq #CurLay (get_tile "LTSLAY")))
		(if (not #CurStyle) (setq #CurStyle (get_tile "LTSTEXTSTYLE")))
		;;;;GAN HANH DONG CHO BUTTON OK
		(action_tile "accept" "(setq userclick T)(done_dialog)")
		;;GAN HANH DONG CHO BUTTON CANCEL
		(action_tile "cancel" "(setq userclick nil)(done_dialog)(exit)")

        
      )
    )
    (start_dialog)
    (unload_dialog dch)
    (if (setq tmp (findfile tmp)) (vl-file-delete tmp))
	(if userclick
		(progn
			(GCT1 TextGhiChu #Height #CurLay #CurStyle #Color)
		 )
	)
  )


(defun Getlayer ( / lyr l)
(setq l nil)
(vlax-for lyr
	(vla-get-layers
		(vla-get-activedocument
			(vlax-get-acad-object)
		)
	)
	(setq l (cons (vla-get-name lyr) l))
)
  l
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;HAM CON - LAY RA CAC TEXTSTYLE CO TRONG BAN VE;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun GetTextStyle ( / styl_ l)
(setq l nil)
(vlax-for styl_
	(vla-get-textstyles
		(vla-get-activedocument
			(vlax-get-acad-object)
		)
	)
	(setq l (cons (vla-get-name styl_) l))
)
  l
)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;HAM CON GHI CHU TEXT;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun GCT1 (TextGhiChu h LayerText TextStyle col / i Olmode Gocxoay);;;;GHI CHU TEXT
(setq Olmode (getvar "OSMODE"))
(setvar "OSMODE" 0)
(while  (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)
	              )
	)
	(entmake (list  (cons 0 "TEXT") (cons 10 P1) (cons 8 (nth (atoi LayerText) LstLayer))
			(cons 40 (atof h)) (cons 50 Gocxoay)
			(cons 7 (nth (atoi TextStyle) LstTextStyle)) (cons 1 TextGhiChu) (cons 62 col) ))
)
(setvar "OSMODE" Olmode)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;TAO MOT PICTURE BOX GAN MAU SAC;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun fill-rec (MyTile col / x y)
(start_image MyTile)
(setq x (dimx_tile MyTile) y (dimy_tile MyTile))
(fill_image 0 0 x y col)
(end_image)
)

Cách dùng

  1. Tải tệp 325047_gct2.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 GCT2 để chạy lisp.

Mã nguồn 325047_gct2.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/65883-y%C3%AAu-c%C3%A2u-c%E1%BA%A7n-h%C6%B0%E1%BB%9Bng-d%E1%BA%ABn-gi%C3%BAp-g%E1%BB%99p-filedcl-v%C3%A0o-trong-filelsp/
;;;TAO TEXTSTYLE
(command "-Style" "Times New Roman"  "Times New Roman" 0 1 0 "" "" "" )
(vl-load-com)
;;;KHI LOAD LISP SE HIEN LEN THONG BAO TEN LENH
(Prompt (strcat "\nL\U+1EC7nh ghi ch\U+00FA Text l\U+00E0: GCT2"))

(defun C:GCT2(  / file tmp dch return );;;;;;;GHI CHU TEXT CACH 2
    (cond
      (
        (not
          (and (setq file (open (setq tmp (vl-filename-mktemp nil nil ".dcl")) "w"))
            (write-line
              (strcat
	"	GHICHU"
	"	: dialog"
	"	{"
	"	label = \"Ch\U+01B0\U+01A1ng tr\U+00ECnh vi\U+1EBFt ghi ch\U+00FA Text\";"
	"	            : 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 = 25; alignment = left; value = \"Nh\U+1EADp n\U+1ED9i dung 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; value = 1;"
	"	                        }"
	"	            }"
	"	            : boxed_column"
	"	            {"
	"	            : row"
	"	                        {"
	"	                         : column"
	"	                         {"
	"	                              : popup_list"
	"	                              {"
	"	                                  label = \"L\U+1EF1a ch\U+1ECDn Layer\" ; key = \"LTSLAY\" ; edit_width  = 25 ; list = \"\" ; alignment = left;"
	"	                              }"
	"	                              : popup_list"
	"	                              {"
	"	                                  label = \"L\U+1EF1a ch\U+1ECDn TextStyle\" ; key = \"LTSTEXTSTYLE\" ; edit_width  = 25 ; list = \"\" ; alignment = left;"
	"	                              }"
	"				      spacer;spacer;"
	"				      :row"
	"				      { "
	"					: text"
	"					{"
	"						label = \"Ch\U+1ECDn Color\"; alignment =left;"
	"					}"
	"					: image_button"
	"					{"
	"						key = \"color\"; alignment = centered; height = 1.5; width = 1.0;	fixed_width = false;   fixed_height = true;"
	"					}"
	"				       }"
	"		                         }"
	"	                        }"
	"	            }"
	"	spacer;"
	"	            ok_cancel;"
	"	spacer;spacer;"
	"	:text"
	"	{"
	"		label= \"Ng\U+01B0\U+1EDDi vi\U+1EBFt: Nguy\U+1EC5n Th\U+00E0nh Du\U+00E2n - \U+0110\U+1ECBa Ch\U+00EDnh K48 - 0972.0168.25\";"
	"		alignment= left;"
	"	}"
	"	}"
              )
              file
            )
            (not (close file)) (< 0 (setq dch (load_dialog tmp))) (new_dialog "GHICHU" dch)
          )
        )
      )
      (t
		(action_tile "Text_ghichu"  "(setq TextGhiChu $value)")
		;;;;;;CHO PHEP NHAP NOI DUNG VAO
		(mode_tile "Text_ghichu" 2)
		;;;GAN BIEN CHO TEXTBOX CAO CHU
		(action_tile "Height_Text"  "(setq #Height $value)")
		;;;;;;CHO PHEP NHAP NOI DUNG VAO
		(mode_tile "Height_Text" 2)
		;;;TAO 1 DANH SACH CHUA CAC LAYER CO TRONG BAN VE
		(start_list "LTSLAY")
		(mapcar 'add_list (setq LstLayer (Getlayer)))
		(end_list)


		(if TextGhiChu
			(set_tile "Text_ghichu" TextGhiChu)
			(set_tile "Text_ghichu" "Nh\U+1EADp n\U+1ED9i dung ghi ch\U+00FA v\U+00E0o \U+0111\U+00E2y")
		)

		;;;;GAN LAYER 
		(if #CurLay
			(set_tile "LTSLAY" #CurLay)
			(set_tile "LTSLAY"  "0")
		)
       		(if #Height
			(set_tile "Height_Text" #Height)
			(set_tile "Height_Text"  "1.0")
		)
		(action_tile "LTSLAY" "(setq #CurLay $value)")
		;;;GAN MAU SAC
		(if (null #Color) (setq #Color 2))
		(fill-rec "color" #Color )
		(action_tile "color" "(if (setq #color (acad_colordlg #color)) (fill-rec \"color\" #color ))")
		 
		 ;;;;TAO 1 DANH SACH CHUA CAC TEXTSTYLE
		(start_list "LTSTEXTSTYLE")
		(mapcar 'add_list (setq LstTextStyle (GetTextStyle)))
		(end_list)
		  
		 ;;;;GAN TEXTSTYLE
		(if #CurStyle
			(set_tile "LTSTEXTSTYLE" #CurStyle)
			(set_tile "LTSTEXTSTYLE" "Standard")
		)

		  
		(action_tile "LTSTEXTSTYLE" "(setq #CurStyle $value)")
		;;;;GAN CAC BIEN CHO NOI DUNG GHI CHU, LAYER, TEXTSTYLE
		(if (not TextGhiChu) (setq TextGhiChu (get_tile "Text_ghichu")))
       		(if (not #Height) (setq #Height (get_tile "Height_Text")))
		(if (not #CurLay) (setq #CurLay (get_tile "LTSLAY")))
		(if (not #CurStyle) (setq #CurStyle (get_tile "LTSTEXTSTYLE")))
		;;;;GAN HANH DONG CHO BUTTON OK
		(action_tile "accept" "(setq userclick T)(done_dialog)")
		;;GAN HANH DONG CHO BUTTON CANCEL
		(action_tile "cancel" "(setq userclick nil)(done_dialog)(exit)")

        
      )
    )
    (start_dialog)
    (unload_dialog dch)
    (if (setq tmp (findfile tmp)) (vl-file-delete tmp))
	(if userclick
		(progn
			(GCT1 TextGhiChu #Height #CurLay #CurStyle #Color)
		 )
	)
  )


(defun Getlayer ( / lyr l)
(setq l nil)
(vlax-for lyr
	(vla-get-layers
		(vla-get-activedocument
			(vlax-get-acad-object)
		)
	)
	(setq l (cons (vla-get-name lyr) l))
)
  l
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;HAM CON - LAY RA CAC TEXTSTYLE CO TRONG BAN VE;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun GetTextStyle ( / styl_ l)
(setq l nil)
(vlax-for styl_
	(vla-get-textstyles
		(vla-get-activedocument
			(vlax-get-acad-object)
		)
	)
	(setq l (cons (vla-get-name styl_) l))
)
  l
)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;HAM CON GHI CHU TEXT;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun GCT1 (TextGhiChu h LayerText TextStyle col / i Olmode Gocxoay);;;;GHI CHU TEXT
(setq Olmode (getvar "OSMODE"))
(setvar "OSMODE" 0)
(while  (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)
	              )
	)
	(entmake (list  (cons 0 "TEXT") (cons 10 P1) (cons 8 (nth (atoi LayerText) LstLayer))
			(cons 40 (atof h)) (cons 50 Gocxoay)
			(cons 7 (nth (atoi TextStyle) LstTextStyle)) (cons 1 TextGhiChu) (cons 62 col) ))
)
(setvar "OSMODE" Olmode)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;TAO MOT PICTURE BOX GAN MAU SAC;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun fill-rec (MyTile col / x y)
(start_image MyTile)
(setq x (dimx_tile MyTile) y (dimy_tile MyTile))
(fill_image 0 0 x y col)
(end_image)
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề [Yêu câu] cần hướng dẫn giúp gộp file.dcl vào trong file.lsp. Xem đúng bài viết #325047 để đọc hướng dẫn và trao đổi thêm.

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