Lisp lệnh DSC trong chủ đề “Viết Lisp theo yêu cầu”
Bạn cần đánh số cột đèn đúng ko
Cái này tôi đã làm giúp một đồng chí ở cty, nhưng có cái khác là bạn phải ký hiệu dạng T3-L1/4/A hoặc T3-L1/4:A . Tôi ko fải dân chuyên ngành điện nên ko hiểu được cách ký hiệu nào đúng. Tôi đưa lên lisp phục vụ cả 2 cách để bạn lựa chọn
Cách dùng: tạo một text đầu tiên, đánh lệnh "DSC", chọn text gốc, chọn giá trị bước nhảy, chọn điểm gốc copy -- chọn điểm copy tới ... đến khi muốn dừng thì thô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
- Chép mã nguồn, lưu thành tệp 37237_dsc.lsp.
- 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 37237_dsc.lsp (trích từ bài viết gốc)
;;;===================================================================
;;; Danh so cot den:
(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))
(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
) ;(chr 32)
(< (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) 1)
(cond
((or (= "A"
(strcase (substr b_base (strlen b_base) 1))
)
(= "B"
(strcase (substr b_base (strlen b_base) 1))
)
)
(setq b_base
(strcat
(substr b_base 1 (1- (strlen b_base)))
(chr (1+ (ascii (substr b_base (strlen b_base) 1))))
)
)
)
((= "C" (strcase (substr b_base (strlen b_base) 1)))
(setq
b_base (strcat (substr b_base 1 (1- (strlen b_base))) "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ủ đề Viết Lisp theo yêu cầu. Xem đúng bài viết #37237 để đọc hướng dẫn và trao đổi thêm.