Jump to content

Lisp lệnh CDL COL CTL CBLL CHL trong chủ đề “Muốn chập 2 hay nhiều layer làm 1 thì làm thế nào”


Xin lỗi, hai hàm đó đay anh gia bách ạ.

Tiện thể, xin hỏi anh giabach có hàm nào mà khi pick vào dimension thì trả về được một giá trị chính là giá trị số text ghi trên dimension đó hay không?
Cám ơn anh.
Chúc anh thật nhiều sức khỏe.

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 41415_cdl_col_ctl_cbll_chl.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 CDL COL CTL CBLL CHL để chạy lisp.

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

;;; Tao Layer khong co mau:
(defun M_Lay(layr_name / tbl t1 t2 key)
  (setq tbl(tblnext "LAYER" 1))
  (while tbl
  (setq t1(strcase layr_name) t2 (cdr(car(cdr tbl))) )
  (if (equal t1 t2) (setq key 1))  
  (setq tbl(tblnext "LAYER"))
  )  
  (if(/= key 1)
  (progn (setq tbl NIL ) 
	 (command "_.LAYER" "N" layr_name "" ) 
	 (princ (strcat "\nLayer "layr_name".... was created."))
  )
  )
  (setq layr_name NIL)
  (princ)
)
;;; Tao Layer co mau:
(defun M_Lay_c(layr_name color / tbl t1 t2 key)
(setvar "Cmdecho" 0)
  (setq tbl(tblnext "LAYER" 1))
  (while tbl
  (setq t1(strcase layr_name) t2 (cdr(car(cdr tbl))) )
  (if (equal t1 t2) (setq key 1))  
  (setq tbl(tblnext "LAYER"))
  )  
  (if(/= key 1)
  (progn (setq tbl NIL ) 
	 (command "_.LAYER" "N" layr_name "C" color layr_name "" ) 
	 (princ (strcat "\nLayer "layr_name".... was created."))
  )
  )
  (setq layr_name NIL)
  (princ)
)
;;; Command Active:
;;; Chuyen toan bo Dim sang Layer "_Dim":
(defun C:CDL (/ dim_app)
(setvar "Cmdecho" 0)
(setq dim_app(ssget "X" '((0 . "DIMENSION")) ))
(if dim_app
 (progn
   (M_lay "_Dim");Tao Layer Dim neu chua co
   (command "_.Chprop" dim_app "" "LA" "_Dim" "")
 )
 (prompt "\nHien tai, khong co Dim.")
)
(princ)
)
;;; Chuyen toan bo cac doi tuong ve Layer tuong ung voi mau:
(defun C:COL (/ op_ccl sl_op op_find cl_find en_find)
(setvar "Cmdecho" 0)
(setq op_ccl(ssget "X"))
(if op_ccl
 (progn
  (setq sl_op (sslength op_ccl) next_op 0)
  (while (		  (setq op_find(ssname op_ccl next_op)
			en_find(entget op_find)
			cl_find(cdr(assoc 62 en_find)) )
	  (if (and (numberp cl_find) (			  (progn (M_lay_c (itoa cl_find) cl_find)
				 (command "_.Chprop" op_find "" "LA" (itoa cl_find) 
												 "C" "Bylayer" "")
		  )
	  )
	  (setq next_op(+ next_op 1) cl_find NIL en_find NIL)
  )
  (setq next_op NIL cl_find NIL)
 )
)
(princ)
)
;;; Chuyen toan bo Text -> Text Layer:
(defun C:CTL (/ Text_app)
(setvar "Cmdecho" 0)
(setq Text_app(ssget "X" '((0 . "*Text")) ))
(if Text_app
 (progn
   (M_lay_c "_Text" "4");Tao Layer _Text neu chua co
   (command "_.Chprop" Text_app "" "LA" "_Text" "C" "Bylayer" "")
 )
 (prompt "\nHien tai, khong co Texts.")
)
(princ)
)
;;; Chuyen toan bo Blocks ve Layer _Blocks
(defun C:CBLL (/ blk_app)
(setvar "Cmdecho" 0)
(setq blk_app(ssget "X" '((0 . "INSERT")) ))
(if blk_app
 (progn
   (M_lay "_Blocks");Tao Layer _Blocks neu chua co
   (command "_.Chprop" blk_app "" "LA" "_Blocks" "")
 )
 (prompt "\nKhong co Blocks nao duoc Insert.")
)
(princ)
)
;;; Chuyen toan bo Hatch ve Layer _Hatch
(defun C:CHL (/ hat_app)
(setvar "Cmdecho" 0)
(setq hat_app(ssget "X" '((0 . "Hatch")) ))
(if hat_app
 (progn
   (M_lay "_Hatch");Tao Layer _Hatch neu chua co
   (command "_.Chprop" hat_app "" "LA" "_Hatch" "")
 )
 (prompt "\nKhong co vat lieu Hatch.")
)
(princ)
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Muốn chập 2 hay nhiều layer làm 1 thì làm thế nào. Xem đúng bài viết #41415 để đọc hướng dẫn và trao đổi thêm.

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