Jump to content

Lisp đánh số thứ tự vào phần text của các block attribute

 

Hề hề hề,

Đồng ý với ý kiến của bác, song bác cho mình một ít thời gian để sửa nhé. Rất cám ơn về món quà bác biếu....

Hề hề hề,..

 

Và nó dây ạ:

(defun c:chatt (/ oldos bln ssbl atn n k i a j  ans att atlst atv pre num)(vl-load-com)(command "undo" "be")(setq oldos (getvar "osmode"))(setvar "osmode" 0)(setq bln (cdr (assoc 2 (entget (car (entsel "\n Chon block mau can thay doi gia tri thuoc tinh"))))))(setq ssbl (acet-ss-to-list (ssget (list (cons 0 "insert") (cons 2 bln) (cons 66 1)))))(if ssbl       (progn              (setq atn (cdr (assoc 2 (entget (car (nentsel "\n Chon thuoc tinh can thay doi gia tri ")))))                      n (getint "\n Nhap so ky tu can giu cua gia tri thuoc tinh: ")                                          k (getint "\n Nhap so ky tu bieu dien so: ")                      i (getint "\n Nhap so bat dau danh so: ")                      a (getreal "\n Nhap gia so: ")                      j 0 )              ;;;;(if (> k 4) (setq k 4))                   (if (= atn "") (setq atn bln))              (setq ans (getstring t "\n Ban muon danh so theo chieu thuan <y or n>: "))              (if (= (strcase ans) "Y")                  (setq ssbl (vl-sort ssbl '(lambda (x y) (< (cadr (assoc 10 (entget x))) (cadr (assoc 10 (entget y)))))))                  (setq ssbl (vl-sort ssbl '(lambda (x y) (> (cadr (assoc 10 (entget x))) (cadr (assoc 10 (entget y)))))))              )              (foreach bl ssbl                      (setq att (entnext bl))                      (while (/= (cdr (assoc 0 (entget att))) "SEQEND")                               (setq atlst (entget att))                               (if (= (cdr (assoc 2 atlst)) (strcase atn))                                   (progn                                          (setq atv (cdr (assoc 1 atlst))                                                  pre (substr atv 1 n)                                                  num (rtos (+ i (* j a)) 2 0))                                          ;;;(if (and (= (strlen num) 1) (= k 4)) (setq num (strcat "000" num)))                                          ;;;(if (and (= (strlen num) 2) (= k 4)) (setq num (strcat "00" num)))                                          ;;;(if (and (= (strlen num) 3) (= k 4)) (setq num (strcat "0" num)))                                          ;;;(if (and (= (strlen num) 1) (= k 3)) (setq num (strcat "00" num)))                                          ;;;(if (and (= (strlen num) 2) (= k 3)) (setq num (strcat "0" num)))                                          ;;;(if (and (= (strlen num) 1) (= k 2)) (setq num (strcat "0" num)))                                          (if (< (strlen num) k)                                              (setq num (repeat (- k (strlen num)) (setq num (strcat "0" num))))                                          )                                          (setq atlst (subst (cons 1 (strcat pre num)) (assoc 1 atlst) atlst))                                          (entmod atlst)                                                                                    (setq j (1+ j))                                    )                                 )                                 (setq att (entnext att))                      )              )         ))(command "regenall")(setvar "osmode" oldos)(command "undo" "e")(princ))

sao mình down về mà ko dùng được nhỉ, nó báo lỗi là "Command: nil

Command: UNDO Current settings: Auto = On, Control = All, Combine = Yes, Layer 
= Yes
Enter the number of operations to undo or  

<1>: END"

rồi sau đó gõ lệnh thì nó báo là không có lệnh đó, bạn xem lại cái

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 242138_chatt.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 CHATT để chạy lisp.

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

(defun c:chatt (/ oldos bln ssbl atn n k i a j  ans att atlst atv pre num)(vl-load-com)(command "undo" "be")(setq oldos (getvar "osmode"))(setvar "osmode" 0)(setq bln (cdr (assoc 2 (entget (car (entsel "\n Chon block mau can thay doi gia tri thuoc tinh"))))))(setq ssbl (acet-ss-to-list (ssget (list (cons 0 "insert") (cons 2 bln) (cons 66 1)))))(if ssbl       (progn              (setq atn (cdr (assoc 2 (entget (car (nentsel "\n Chon thuoc tinh can thay doi gia tri ")))))                      n (getint "\n Nhap so ky tu can giu cua gia tri thuoc tinh: ")                                          k (getint "\n Nhap so ky tu bieu dien so: ")                      i (getint "\n Nhap so bat dau danh so: ")                      a (getreal "\n Nhap gia so: ")                      j 0 )              ;;;;(if (> k 4) (setq k 4))                   (if (= atn "") (setq atn bln))              (setq ans (getstring t "\n Ban muon danh so theo chieu thuan <y or n>: "))              (if (= (strcase ans) "Y")                  (setq ssbl (vl-sort ssbl '(lambda (x y) (< (cadr (assoc 10 (entget x))) (cadr (assoc 10 (entget y)))))))                  (setq ssbl (vl-sort ssbl '(lambda (x y) (> (cadr (assoc 10 (entget x))) (cadr (assoc 10 (entget y)))))))              )              (foreach bl ssbl                      (setq att (entnext bl))                      (while (/= (cdr (assoc 0 (entget att))) "SEQEND")                               (setq atlst (entget att))                               (if (= (cdr (assoc 2 atlst)) (strcase atn))                                   (progn                                          (setq atv (cdr (assoc 1 atlst))                                                  pre (substr atv 1 n)                                                  num (rtos (+ i (* j a)) 2 0))                                          ;;;(if (and (= (strlen num) 1) (= k 4)) (setq num (strcat "000" num)))                                          ;;;(if (and (= (strlen num) 2) (= k 4)) (setq num (strcat "00" num)))                                          ;;;(if (and (= (strlen num) 3) (= k 4)) (setq num (strcat "0" num)))                                          ;;;(if (and (= (strlen num) 1) (= k 3)) (setq num (strcat "00" num)))                                          ;;;(if (and (= (strlen num) 2) (= k 3)) (setq num (strcat "0" num)))                                          ;;;(if (and (= (strlen num) 1) (= k 2)) (setq num (strcat "0" num)))                                          (if (< (strlen num) k)                                              (setq num (repeat (- k (strlen num)) (setq num (strcat "0" num))))                                          )                                          (setq atlst (subst (cons 1 (strcat pre num)) (assoc 1 atlst) atlst))                                          (entmod atlst)                                                                                    (setq j (1+ j))                                    )                                 )                                 (setq att (entnext att))                      )              )         ))(command "regenall")(setvar "osmode" oldos)(command "undo" "e")(princ))

Thảo luận gốc

Lisp được chia sẻ trong chủ đề [Yêu cầu] Lisp đánh số thứ tự vào phần text của các block attribute. Xem đúng bài viết #242138 để đọc hướng dẫn và trao đổi thêm.

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