Lisp lệnh DSC trong chủ đề “[Yêu Cầu] Nhờ Viết Lisp Copy Tăng Số Cải Tiến”
Trường hợp 1: Bạn có thể sử dụng lsp này (không biết bản quyền của bà con cô dì chú bác nào cả)
;;;=====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) )
- Tải lisp
- 393662_dsc.lsp
Cách dùng
- Tải tệp 393662_dsc.lsp về máy.
- 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ẽ.
- Gõ lệnh DSC để chạy lisp.
Mã nguồn 393662_dsc.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/159030-y%C3%AAu-c%E1%BA%A7u-nh%E1%BB%9D-vi%E1%BA%BFt-lisp-copy-t%C4%83ng-s%E1%BB%91-c%E1%BA%A3i-ti%E1%BA%BFn/
;;;=====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ủ đề [Yêu Cầu] Nhờ Viết Lisp Copy Tăng Số Cải Tiến. Xem đúng bài viết #393662 để đọc hướng dẫn và trao đổi thêm.