Jump to content

Lisp lệnh IB RESETIB trong chủ đề “TẠO MỘT MENU THƯ VIỆN”

Đây là mã nguồn:

file CVIB.lsp

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 14082_ib_resetib.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 IB RESETIB để chạy lisp.

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

;;;  This is opensource sofware from www.cadviet.com
;;;   You can modify or make anything you want with this lisp source

(defun C:IB (/	       SYM_DCL_ID	   TEXT	     FILE
     SYMLIST   SLIST	 DESCR	   BLKNAME   SLDNAME
     VALUE
    )
 (defun INIT_BLOCK ()
   (setq symlist (vl-directory-files
	    (strcat activepath curgroup "\\")
	    "*.dwg"
	  )
  slist	  (mapcar 'vl-filename-base symlist)
  symlist slist
   )
   (start_list "list_sym")
   (mapcar 'add_list symLIST)
   (end_list)
   (set_tile "list_sym" "0")
 )
 (defun INIT_GROUP ()
   (setq grplist  (vl-directory-files activepath "*.*" -1)
  grplist  (vl-remove "." grplist)
  grplist  (vl-remove ".." grplist)
  curGroup (car grplist)
   )
   (start_list "list_grp")
   (mapcar 'add_list grpLIST)
   (end_list)
   (set_tile "list_grp" "0")
 )
 (defun disable ()
   (cond
     ((= 0 osn)
      (mode_tile "scobj" 0)
      (mode_tile "rot" 0)
     )
     ((and (= 1 osn))
      (mode_tile "scobj" 1)
      (mode_tile "rot" 1)
     )
   )
 )
 (defun IMAGE_ACT (VALUE)
   (setq ITEM (nth (atoi VALUE) SYMLIST))
   (setq
     BLKNAME ITEM
     SLDNAME (strcat ActivePath curGroup "\\" ITEM ".sld")
     DESCR   ITEM
     WIDTH   (dimx_tile "tile_1")
     HEIGHT  (dimy_tile "tile_1")
   )
   (start_image "tile_1")
   (fill_image 0 0 WIDTH HEIGHT 0)
   (slide_image
     0	0 WIDTH	HEIGHT SLDNAME)
   (end_image)
   (set_tile "desc_blk" DESCR)
 )
 (defun GROUP_ACT (VALUE)
   (setq ITEM	    (nth (atoi VALUE) GRPLIST)
  curGroup  ITEM
  blockpath (strcat activepath curGroup "\\")
   )
   (INIT_BLOCK)
   (IMAGE_ACT "0")
 )

 ;;---------------------------------------------------
 (princ "\nIB program - © 2007, CADViet.com")
 (princ "\n")
 (princ "\n")
 ;;(setq activepath "D:\\Hoanh\\@CadTool\\InsBlk\\")
 (setq activepath (getcfg "AppData/CADViet/IB_Path"))
 (while (or
   (not activepath)
   (not (vl-file-directory-p activepath))	   
 )
   (setq cvname (getfiled "Hay chi dinh duong dan toi file CVIB.vlx de bat dau su dung lisp"
		   "CVIB.vlx"
                          "VLX"
		   16
		   )
   )
   (if (= (vl-filename-base cvname) "CVIB")
     (setq activepath (strcat (vl-filename-directory  cvname) "\\"))
   )
 )
 (setcfg "AppData/CADViet/IB_Path" activepath)  
 (setq SYM_DCL_ID (load_dialog "CVIB.dcl"))
 (if (< SYM_DCL_ID 0)
   (exit)
 )
 (new_dialog "symbol" SYM_DCL_ID)
 (INIT_GROUP)
 (INIT_BLOCK)

 (setq sc 1)
 (set_tile "scobj" (rtos sc))
 (setq rt 0)
 (set_tile "rot" (angtos rt))
 (action_tile "list_grp" "(group_act $value)")
 (action_tile "list_sym" "(image_act $value)")
 (action_tile "osn" "(setq osn (atoi $value ))(disable)")
 (action_tile "scobj" "(setq sc (atoi $value))(disable)")
 (action_tile "rot" "(setq rt (atoi $value))(disable)")
 (action_tile
   "cancel"
   "(setq blkname nil)"
 )
 (start_dialog)
 (unload_dialog SYM_DCL_ID)
 (if BLKNAME
   (command "insert"
     (cond
       ((tblsearch "block" BLKNAME) BLKNAME)
       (t (strcat blockpath BLKNAME ".dwg"))
     )
     "s"
     sc
     "r"
     rt
     pause
   )
 )
 (princ)
)

(defun c:resetib()
 (setcfg "AppData/CADViet/IB_Path" "")
 (princ "\nDa reset thanh cong!")
 (princ "\n")
 (princ)
)

(princ "\nIB da load thanh cong")
(princ "\nHay dung lenh IB de bat dau su dung")
(princ "\nHay dung lenh resetIB khi ban muon thiet lap lai duong dan")
(princ "\n")
(princ)

symbol:dialog {
 aspect_ratio = 0;
	 label = "Chi dinh Block muon chen";
: row {
: boxed_column {
 label = "Ten nhom";
 : list_box {
   key = "list_grp";
   allow_accept = true;
 }
}
: boxed_column {
 label = "Ten Block";
 : list_box {
   key = "list_sym";
   allow_accept = true;
 }
}
 : boxed_column {
   : toggle {
	  label = "Chi dinh tren man hinh";
  key = "osn";
  mnemonic = "O";
  fixed_width = true;
   }
 label = "Goc xoay va ty le:";
 : edit_box {
	label = "Scale 1 : ";
key = "scobj";
mnemonic = "S";
edit_width = 10;
label = "Ty le";
 }
 : edit_box {
label = "Goc: ";
key = "rot";
mnemonic = "A";
edit_width = 10;		 
 }
  }


}
 : row {
   label = "Hinh anh Block";
   : icon_image {
   key = "tile_1";
   aspect_ratio = 0.9;
   fixed_height = true;
   fixed_width = true;
   width = 49;
   height = 12; 
   alignment = centered;
 }
}
 : text {
   key = "desc_blk";
   width = 30;
   alignment = centered;
 }
 ok_cancel;
}

Thảo luận gốc

Lisp được chia sẻ trong chủ đề TẠO MỘT MENU THƯ VIỆN. Xem đúng bài viết #14082 để đọc hướng dẫn và trao đổi thêm.

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