Jump to content

Lisp lệnh DSC trong chủ đề “nhập các text đi theo các block để làm ký hiệu”


Hãy sử dụng tính năng của block, cộng thêm một chút sáng tạo trong cách dùng. Phương án giải quyết như sau:
Cách 1: dùng Tcount
- Gọi tên block bóng đèn là A, bạn hãy tạo một block với tên B chứa block A + text đánh số cột
- Thay vì chèn block A như thường lệ, hãy chèn block B
- Sau khi chèn xong, hãy chọn tất cả các block B và explode. Chỉnh sửa tất cả các text tên cột cho đúng ý (nên dùng filter hoặc ssx để chỉnh cho đồng bộ).
- Bạn đã có các text như ý để sử dụng với Tcount

Cách 2: dùng lisp với thuật toán:
- Chọn text đầu tiên
- Chọn điểm gốc copy
- Chọn điểm chèn cột tiếp theo (+ options (đánh số tự động hay thay đổi)
Đây là lisp đánh số cột điện tôi sưu tầm và sửa lại, bạn có thể tham khảo:

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 34477_dsc.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 DSC để chạy lisp.

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

**Danh so cot den:
;;;=====Increasing copy=====
(defun c:dsc (/ ang x y ent tg tg1tg2 num_r num_c num_inc dis_r dis_c num top idnum
              dx dy bottom inc tgnum attr attr_ent t_base b_base locat value 
              deci stnum loca1 loca2 tt count inctg inctg1 bpoint mx my nx ny bx by)
 (setq idnum 0)
 (while (/= idnum 1)
   (setq ent (entsel "\nHay lua chon so ma ban muon copy : "))
   (if ent
     (progn
       (setq e (car ent))
       (setq tg (entget e))
       (if (= (cdr (assoc 0 tg)) "TEXT") (setq idnum 1))
     )
     (princ)
   )
 )

 (setq num_inc (getreal "\nHay nhap he so tang giam <1> : "))
 (if (= num_inc nil) (setq num_inc 1))

 (setq bpoint (getpoint "\nChon diem goc de copy : "))
 (setq x (car bpoint))
 (setq y (car(cdr bpoint)))

 (if (and (= (cdr (assoc 72 tg)) 0) (= (cdr (assoc 73 tg)) 0))
   (progn
     (setq bx (car (cdr (assoc 10 tg))))
     (setq by (car (cdr (cdr (assoc 10 tg)))))
   )
   (progn
     (setq bx (car (cdr (assoc 11 tg))))
     (setq by (car (cdr (cdr (assoc 11 tg)))))
   )
 )

 (setq attr (cdr tg))	;attr chua cac thuoc tinh cua Entity nguon
 (setq tg (cdr (assoc 1 tg)))
 (setq inc 0)
 (setq tg1 "")
 (setq t_base "")
 (setq b_base "")
 (setq idnum 0)
 (setq top 0)
 (setq bottom 0)
 (setq stnum "") 
 (setq deci 0) 
 (repeat  (strlen tg)    
   (if  (or (and (> (ascii (setq tgnum (substr tg (- (strlen tg) inc) 1))) 47) 
                   (< (ascii (setq tgnum (substr tg (- (strlen tg) inc) 1))) 58))
                   (= (ascii (setq tgnum (substr tg (- (strlen tg) inc) 1))) 32)
                   (= (ascii (setq tgnum (substr tg (- (strlen tg) inc) 1))) 46))
     (progn  
         (if  (= (ascii (setq tgnum (substr tg (- (strlen tg) inc) 1))) 46) (setq deci inc))      
         (if (= inc 0)
            (progn
              (setq idnum 1)
              (if  (= (ascii (setq tgnum (substr tg (- (strlen tg) inc) 1))) 46) 
                 (setq b_base (strcat "." b_base)))               
            )
         )
         (if (= bottom 1) (progn (setq bottom 0) (setq idnum 1) (setq top 1)))
         (if (and (= idnum 0) (= top 1)) (setq t_base (strcat tgnum t_base)))
         (if (= idnum 1) 
           (progn    
             (if (and (= tgnum "0") (> inc 0)) (setq stnum (strcat stnum "0")) (setq stnum ""))
             (setq tg1 (strcat tgnum tg1))
           )
         )
     )
     (if (= inc 0) 
       (progn
         (setq b_base (strcat tgnum b_base))
         (setq bottom 1)
       )
       (if (= bottom 1)
         (setq b_base (strcat tgnum b_base))
         (progn
           (setq top 1)
           (setq t_base (strcat tgnum t_base))
           (if (= idnum 1) (setq idnum 0))
         )
       )
     )
   )
   (setq inc (+ inc 1))
 )

 (if (= tg1 "") (exit))
 (setq num (atof tg1))
 (setq count 1)

 (while (setq bpoint (getpoint "\nChon diem copy tiep theo : "))
    (setq num (+ num num_inc))
   (if (>= (strlen b_base) 3)
     (cond
   ( (or (= "A" (strcase (substr b_base 2 1))
     )
     (= "B" (strcase (substr b_base 2 1))
	)
  )
    (setq b_base (strcat (substr b_base 1 1) (chr (1+ (ascii (substr b_base 2 1))) ) (substr b_base 3)
		  )
   )
    )
   ((= "C" (strcase (substr b_base 2 1)))
(setq b_base (strcat (substr b_base 1 1) "A") )
)
   )
     (cond
   ( (or (= "A" (strcase (substr b_base 2 1))
     )
     (= "B" (strcase (substr b_base 2 1))
	)
  )
    (setq b_base (strcat (substr b_base 1 1) (chr (1+ (ascii (substr b_base 2 1))) ) (substr b_base 3)
		  )
   )
    )
   ((= "C" (strcase (substr b_base 2 1)))
(setq b_base (strcat (substr b_base 1 1) "A") )
)
   )
     )
    (setq value (strcat t_base (strcat stnum (rtos num 2 deci)) b_base))
    (setq nx (car bpoint))
    (setq ny (car(cdr bpoint)))
    (setq dx (- nx x))
    (setq dy (- ny y))
    (setq mx (car (getvar "ucsxdir")))
    (setq my (car (cdr (getvar "ucsxdir"))))
    (setq loca1 (+ bx (* mx dx)))
    (setq loca2 (+ by (* my dx)))
    (setq mx (car (getvar "ucsydir")))
    (setq my (car (cdr (getvar "ucsydir"))))
    (setq loca1 (+ loca1 (* mx dy)))
    (setq loca2 (+ loca2 (* my dy)))
    (setq attr_ent (subst (cons 1 value) (assoc 1 attr) attr))
    (if (and (= (cdr (assoc 72 attr_ent)) 0) (= (cdr (assoc 73 attr_ent)) 0))
      (setq attr_ent (subst (list 10 loca1 loca2 0) (assoc 10 attr_ent) attr_ent))
      (setq attr_ent (subst (list 11 loca1 loca2 0) (assoc 11 attr_ent) attr_ent))
    )
    (entmake attr_ent)
    (setq count (+ count 1))
 )	 ;end while
 (princ)
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề nhập các text đi theo các block để làm ký hiệu. Xem đúng bài viết #34477 để đọc hướng dẫn và trao đổi thêm.

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