Jump to content

Lisp lệnh SCD trong chủ đề “Nhờ Viết Lisp Đánh Số Cột Đèn Có Phân Pha!”

Đây bạn:

;;;lisp danh so cot den
(defun c:SCD( / st str i p chu str1)
(setq    #tu (NGT #tu "1" getstring "Tu chieu sang so")
        #lo (NGT #lo "1" getstring "Lo so")
        #st (NGT #st 1 getint "STT cot dau tien")
        st (1- #st)
        str (strcat "TCS" #tu "/L" #lo "/")
        )
(initget "A B C")
(setq #pha (NGT #pha "A" getkword "Pha dau tien [A/B/C]"))
(cond ((= (strcase #pha) "A")
        (setq i -1)
    (while
        (setq p (getpoint "\nPick: "))
        (setq i (1+ i))
        (setq chu (nth (rem i 3) '("A" "B" "C"))
            st (1+ st)
            str1 (strcat str (itoa st) chu)
            )
        (MakeText p str1 2.5 0 "L" nil nil 2 nil)
    )
    )
    ((= (strcase #pha) "B")
        (setq i 0)
    (while
        (setq p (getpoint "\nPick: "))
        (setq i (1+ i))
        (setq chu (nth (rem i 3) '("A" "B" "C"))
            st (1+ st)
            str1 (strcat str (itoa st) chu)
            )
        (MakeText p str1 2.5 0 "L" nil nil 2 nil)
    )
    )
    ((= (strcase #pha) "C")
        (setq i 1)
    (while
        (setq p (getpoint "\nPick: "))
        (setq i (1+ i))
        (setq chu (nth (rem i 3) '("A" "B" "C"))
            st (1+ st)
            str1 (strcat str (itoa st) chu)
            )
        (MakeText p str1 2.5 0 "L" nil nil 2 nil)
    )
    )
)
)
;;;==================================================
(defun NGT(a mac_dinh ham str_nhac / modul)
;;Nhan gia tri
(or a (setq a mac_dinh))
(setq a (cond
    ((= "" (setq modul (ham (strcat "\n" str_nhac " <" (vl-princ-to-string a) ">: ")))) a)
    (modul)
    (a)
    )
    )
)
;;;=================================================
(defun MakeText (point string Height Ang justify Style Layer Color xdata / Lst)
; Ang: Radial    
(setq Lst (list '(0 . "TEXT")
                (cons 8 (if Layer Layer (getvar "Clayer")))                                    
                (cons 62 (if Color Color 256))                                    
                (cons 10 point)                                    
                (cons 40 Height)                                    
                (cons 1 string)                                    
                (if Ang (cons 50 Ang))                                    
                (cons 7 (if Style Style (getvar "Textstyle")))                                    
                (cons -3 (if xdata (list xdata) nil)))                
                justify (strcase justify))    
                (cond ((= justify "C") (setq Lst (append Lst (list (cons 72 1) (cons 11 point)))))                
                      ((= justify "R") (setq Lst (append Lst (list (cons 72 2) (cons 11 point)))))                
                      ((= justify "M") (setq Lst (append Lst (list (cons 72 4) (cons 11 point)))))                
                      ((= justify "TL") (setq Lst (append Lst (list (cons 72 0) (cons 11 point) (cons 73 3)))))                
                      ((= justify "TC") (setq Lst (append Lst (list (cons 72 1) (cons 11 point) (cons 73 3)))))                
                      ((= justify "TR") (setq Lst (append Lst (list (cons 72 2) (cons 11 point) (cons 73 3)))))                    
                      ((= justify "ML") (setq Lst (append Lst (list (cons 72 0) (cons 11 point) (cons 73 2)))))                
                      ((= justify "MC") (setq Lst (append Lst (list (cons 72 1) (cons 11 point) (cons 73 2)))))                
                      ((= justify "MR") (setq Lst (append Lst (list (cons 72 2) (cons 11 point) (cons 73 2)))))                
                      ((= justify "BL") (setq Lst (append Lst (list (cons 72 0) (cons 11 point) (cons 73 1)))))                
                      ((= justify "BC") (setq Lst (append Lst (list (cons 72 1) (cons 11 point) (cons 73 1)))))                
                      ((= justify "BR") (setq Lst (append Lst (list (cons 72 2) (cons 11 point) (cons 73 1)))))
                      )    
                      (entmakex Lst)
);end
;=================================

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 388294_scd.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 SCD để chạy lisp.

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

;;;lisp danh so cot den
(defun c:SCD( / st str i p chu str1)
(setq    #tu (NGT #tu "1" getstring "Tu chieu sang so")
        #lo (NGT #lo "1" getstring "Lo so")
        #st (NGT #st 1 getint "STT cot dau tien")
        st (1- #st)
        str (strcat "TCS" #tu "/L" #lo "/")
        )
(initget "A B C")
(setq #pha (NGT #pha "A" getkword "Pha dau tien [A/B/C]"))
(cond ((= (strcase #pha) "A")
        (setq i -1)
    (while
        (setq p (getpoint "\nPick: "))
        (setq i (1+ i))
        (setq chu (nth (rem i 3) '("A" "B" "C"))
            st (1+ st)
            str1 (strcat str (itoa st) chu)
            )
        (MakeText p str1 2.5 0 "L" nil nil 2 nil)
    )
    )
    ((= (strcase #pha) "B")
        (setq i 0)
    (while
        (setq p (getpoint "\nPick: "))
        (setq i (1+ i))
        (setq chu (nth (rem i 3) '("A" "B" "C"))
            st (1+ st)
            str1 (strcat str (itoa st) chu)
            )
        (MakeText p str1 2.5 0 "L" nil nil 2 nil)
    )
    )
    ((= (strcase #pha) "C")
        (setq i 1)
    (while
        (setq p (getpoint "\nPick: "))
        (setq i (1+ i))
        (setq chu (nth (rem i 3) '("A" "B" "C"))
            st (1+ st)
            str1 (strcat str (itoa st) chu)
            )
        (MakeText p str1 2.5 0 "L" nil nil 2 nil)
    )
    )
)
)
;;;==================================================
(defun NGT(a mac_dinh ham str_nhac / modul)
;;Nhan gia tri
(or a (setq a mac_dinh))
(setq a (cond
    ((= "" (setq modul (ham (strcat "\n" str_nhac " <" (vl-princ-to-string a) ">: ")))) a)
    (modul)
    (a)
    )
    )
)
;;;=================================================
(defun MakeText (point string Height Ang justify Style Layer Color xdata / Lst)
; Ang: Radial    
(setq Lst (list '(0 . "TEXT")
                (cons 8 (if Layer Layer (getvar "Clayer")))                                    
                (cons 62 (if Color Color 256))                                    
                (cons 10 point)                                    
                (cons 40 Height)                                    
                (cons 1 string)                                    
                (if Ang (cons 50 Ang))                                    
                (cons 7 (if Style Style (getvar "Textstyle")))                                    
                (cons -3 (if xdata (list xdata) nil)))                
                justify (strcase justify))    
                (cond ((= justify "C") (setq Lst (append Lst (list (cons 72 1) (cons 11 point)))))                
                      ((= justify "R") (setq Lst (append Lst (list (cons 72 2) (cons 11 point)))))                
                      ((= justify "M") (setq Lst (append Lst (list (cons 72 4) (cons 11 point)))))                
                      ((= justify "TL") (setq Lst (append Lst (list (cons 72 0) (cons 11 point) (cons 73 3)))))                
                      ((= justify "TC") (setq Lst (append Lst (list (cons 72 1) (cons 11 point) (cons 73 3)))))                
                      ((= justify "TR") (setq Lst (append Lst (list (cons 72 2) (cons 11 point) (cons 73 3)))))                    
                      ((= justify "ML") (setq Lst (append Lst (list (cons 72 0) (cons 11 point) (cons 73 2)))))                
                      ((= justify "MC") (setq Lst (append Lst (list (cons 72 1) (cons 11 point) (cons 73 2)))))                
                      ((= justify "MR") (setq Lst (append Lst (list (cons 72 2) (cons 11 point) (cons 73 2)))))                
                      ((= justify "BL") (setq Lst (append Lst (list (cons 72 0) (cons 11 point) (cons 73 1)))))                
                      ((= justify "BC") (setq Lst (append Lst (list (cons 72 1) (cons 11 point) (cons 73 1)))))                
                      ((= justify "BR") (setq Lst (append Lst (list (cons 72 2) (cons 11 point) (cons 73 1)))))
                      )    
                      (entmakex Lst)
);end
;=================================

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Nhờ Viết Lisp Đánh Số Cột Đèn Có Phân Pha!. Xem đúng bài viết #388294 để đọc hướng dẫn và trao đổi thêm.

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