Jump to content

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

Sửa lại cho bạn.

(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)")
 
(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)
)
)
(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 / 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)))   
  )
)
 
;;;-------------------------------------------------------------
 
 

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

(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)")
 
(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)
)
)
(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 / 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)))   
  )
)
 
;;;-------------------------------------------------------------
 
 

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 #310286 để đọc hướng dẫn và trao đổi thêm.

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