Jump to content

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

Bác Tot trả lời nhanh quá!

Mần cho Thanhduan rồi đây:

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/27610-hoi-van-de-tao-lien-ket-lsp-va-dialog-dcl/page-3
(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)
 
(start_list "LTSLAY")
(mapcar 'add_list (setq LstLayer (Getlayer)))
(end_list)
  
(if #CurLay
(set_tile "LTSLAY" #CurLay)
(set_tile "LTSLAY"  "0")
)
(action_tile "LTSLAY" "(setq #CurLay $value)")
 
(if (null #Color) (setq #Color 2))
(fill-rec "color" #color )
(action_tile "color" "(if (setq #color (acad_colordlg #color)) (fill-rec \"color\" #color ))")
 
 
(start_list "LTSTEXTSTYLE")
(mapcar 'add_list (setq LstTextStyle (GetTextStyle)))
(end_list)
  
 
(if #CurStyle
(set_tile "LTSTEXTSTYLE" #CurStyle)
(set_tile "LTSTEXTSTYLE" "Standard")
)
(action_tile "LTSTEXTSTYLE" "(setq #CurStyle $value)")
 
(if (not TextGhiChu) (setq TextGhiChu (get_tile "Text_ghichu")))
(if (not #CurLay) (setq #CurLay (get_tile "LTSLAY")))
(if (not #CurStyle) (setq #CurStyle (get_tile "LTSTEXTSTYLE")))
  
(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 #CurLay #CurStyle #color)
)
)
(if (= UseButton 2)
(alert (strcat "\nTho\U+00E1t"))
)
(Princ)
)
(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
)
(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
)
(defun GCT(TextGhiChu h LayerText TextStyle col / i Olmode Gocxoay);;;;GHI CHU TEXT
  (command "Style" "Times New Roman"  "Times New Roman"  0 1 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) ))  
  )
)
;;;-------------------------------------------------------------
(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)

DCL:

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";

 

                        }

                        //:row{

                        : 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;

                              }

                                    :image_button{key = "color"; width=1; height=2; alignment=centered;}

                         }

                        }

            }         

            : 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;

                        }

 

            }

 

}

;; free lisp from cadviet.com
(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)
 
(start_list "LTSLAY")
(mapcar 'add_list (setq LstLayer (Getlayer)))
(end_list)
  
(if #CurLay
(set_tile "LTSLAY" #CurLay)
(set_tile "LTSLAY"  "0")
)
(action_tile "LTSLAY" "(setq #CurLay $value)")
 
(if (null #Color) (setq #Color 2))
(fill-rec "color" #color )
(action_tile "color" "(if (setq #color (acad_colordlg #color)) (fill-rec \"color\" #color ))")
 
 
(start_list "LTSTEXTSTYLE")
(mapcar 'add_list (setq LstTextStyle (GetTextStyle)))
(end_list)
  
 
(if #CurStyle
(set_tile "LTSTEXTSTYLE" #CurStyle)
(set_tile "LTSTEXTSTYLE" "Standard")
)
(action_tile "LTSTEXTSTYLE" "(setq #CurStyle $value)")
 
(if (not TextGhiChu) (setq TextGhiChu (get_tile "Text_ghichu")))
(if (not #CurLay) (setq #CurLay (get_tile "LTSLAY")))
(if (not #CurStyle) (setq #CurStyle (get_tile "LTSTEXTSTYLE")))
  
(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 #CurLay #CurStyle #color)
)
)
(if (= UseButton 2)
(alert (strcat "\nTho\U+00E1t"))
)
(Princ)
)
(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
)
(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
)
(defun GCT(TextGhiChu h LayerText TextStyle col / i Olmode Gocxoay);;;;GHI CHU TEXT
  (command "Style" "Times New Roman"  "Times New Roman"  0 1 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) ))   
  )
)
;;;-------------------------------------------------------------
(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)
)
;; free lisp from cadviet.com
(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)
 
(start_list "LTSLAY")
(mapcar 'add_list (setq LstLayer (Getlayer)))
(end_list)
  
(if #CurLay
(set_tile "LTSLAY" #CurLay)
(set_tile "LTSLAY"  "0")
)
(action_tile "LTSLAY" "(setq #CurLay $value)")
 
(if (null #Color) (setq #Color 2))
(fill-rec "color" #color )
(action_tile "color" "(if (setq #color (acad_colordlg #color)) (fill-rec \"color\" #color ))")
 
 
(start_list "LTSTEXTSTYLE")
(mapcar 'add_list (setq LstTextStyle (GetTextStyle)))
(end_list)
  
 
(if #CurStyle
(set_tile "LTSTEXTSTYLE" #CurStyle)
(set_tile "LTSTEXTSTYLE" "Standard")
)
(action_tile "LTSTEXTSTYLE" "(setq #CurStyle $value)")
 
(if (not TextGhiChu) (setq TextGhiChu (get_tile "Text_ghichu")))
(if (not #CurLay) (setq #CurLay (get_tile "LTSLAY")))
(if (not #CurStyle) (setq #CurStyle (get_tile "LTSTEXTSTYLE")))
  
(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 #CurLay #CurStyle #color)
)
)
(if (= UseButton 2)
(alert (strcat "\nTho\U+00E1t"))
)
(Princ)
)
(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
)
(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
)
(defun GCT(TextGhiChu h LayerText TextStyle col / i Olmode Gocxoay);;;;GHI CHU TEXT
  (command "Style" "Times New Roman"  "Times New Roman"  0 1 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) ))   
  )
)
;;;-------------------------------------------------------------
(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)
)

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 310297_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 310297_gcd.lsp (trích từ bài viết gốc)

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/27610-hoi-van-de-tao-lien-ket-lsp-va-dialog-dcl/page-3
(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)
 
(start_list "LTSLAY")
(mapcar 'add_list (setq LstLayer (Getlayer)))
(end_list)
  
(if #CurLay
(set_tile "LTSLAY" #CurLay)
(set_tile "LTSLAY"  "0")
)
(action_tile "LTSLAY" "(setq #CurLay $value)")
 
(if (null #Color) (setq #Color 2))
(fill-rec "color" #color )
(action_tile "color" "(if (setq #color (acad_colordlg #color)) (fill-rec \"color\" #color ))")
 
 
(start_list "LTSTEXTSTYLE")
(mapcar 'add_list (setq LstTextStyle (GetTextStyle)))
(end_list)
  
 
(if #CurStyle
(set_tile "LTSTEXTSTYLE" #CurStyle)
(set_tile "LTSTEXTSTYLE" "Standard")
)
(action_tile "LTSTEXTSTYLE" "(setq #CurStyle $value)")
 
(if (not TextGhiChu) (setq TextGhiChu (get_tile "Text_ghichu")))
(if (not #CurLay) (setq #CurLay (get_tile "LTSLAY")))
(if (not #CurStyle) (setq #CurStyle (get_tile "LTSTEXTSTYLE")))
  
(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 #CurLay #CurStyle #color)
)
)
(if (= UseButton 2)
(alert (strcat "\nTho\U+00E1t"))
)
(Princ)
)
(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
)
(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
)
(defun GCT(TextGhiChu h LayerText TextStyle col / i Olmode Gocxoay);;;;GHI CHU TEXT
  (command "Style" "Times New Roman"  "Times New Roman"  0 1 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) ))  
  )
)
;;;-------------------------------------------------------------
(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ủ đề hỏi vấn đề tạo liên kết LSP và dialog DCL. Xem đúng bài viết #310297 để đọc hướng dẫn và trao đổi thêm.

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