Jump to content

Lisp lệnh DST trong chủ đề “Lisp đánh số thửa cho thửa đất”



Độ rộng thì bác tìm đoạn

Cách dùng

  1. Tải tệp 44181_dst.lsp về máy.
  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 DST để chạy lisp.

Mã nguồn 44181_dst.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/8207-lisp-%C4%91%C3%A1nh-s%E1%BB%91-th%E1%BB%ADa-cho-th%E1%BB%ADa-%C4%91%E1%BA%A5t/
;;;*****************************************************************;;;

;;; Tks to Ssg & all Cadviet members who make lisp impressed me much;;;
;;;*****************************************************************;;;

;;;*****************************************************
;;;  Danh so thua tu dong cho thua dat (Closed_Polyline)
(defun c:dst ( / ent tongsothua)
(command "Undo" "Begin")
(command "osnap" "none")
(setq ent (ssget "X" (list (cons 8 "centroid")(cons 0 "POINT"))))  
(if(= ent nil)(progn (alert "Ch­a ®¸nh dÊu t©m thöa, h·y t¹o t©m thöa d¹ng POINT trªn layer CentroID ! "))
  (progn
     (setq ent (ssget "X" (list (cons 8  "centroid" )(cons 0 "POINT"))))
     (if (/= nil ent) (setq tongsothua(sslength ent) ))     
     (danhsothua tongsothua) 
     (alert (strcat "Cã tæng sè  " (itoa tongsothua) "  thöa ®Êt ®· ®­îc ®¸nh sè !" ))
  );prog
);if
(command "Undo" "End")    
)
;;;*****************************************************
(defun danhsothua (tongsothua / ent tbl List_cen List_sort List_ok e es i j x y e1 e2)
 (vl-load-com)  
 (setq ent (ssget "X" (list (cons 8 "centroid")(cons 0 "POINT"))))      
 (setq tbl (TBLSEARCH  "LAYER"  "sothua" ))
 (if (= tbl nil)(command "layer" "n" "sothua" "c" "Yellow" "sothua" ""))
 (command "layer" "s" "sothua" "")
 (setq tbl (TBLSEARCH  "style"  "sothua" ))
 (if (= tbl nil)(command "style" "sothua" "romans.shx" "1.2" "0.8" "" "" "" "")) 

 (setq j 0) 
 (while (< j tongsothua)
     (setq e (ssname ent j))
     (setq es(entget e))
     (setq x (car (cdr (assoc 10 es))) )
     (setq y (car (cdr (cdr (assoc 10 es)))))
     (setq List_cen(append List_cen(list (list x y))))
     (setq j (1+ j))
 ) ;while

 ; Buoc 1 - sort kieu descending cho point CentroID.Y (X trac dia)
 (setq list_sort (vl-sort list_cen (function (lambda (e1 e2)(> (cadr e1)(cadr e2))))) )

 ; Buoc 2 - sort kieu ascending point CentroID tu trai sang phai truc X (Y trac dia)
 (sort_trai_phai tongsothua list_sort)
 ;;

 ; Ve so thua ra ban ve;
 (setq i 0)  
 (while (< i tongsothua)     
    (wtxt2 (itoa (1+ i)) (nth i List_ok) "sothua" "sothua" 1 "C" "B" )     
    (setq i (1+ i)) 
 )  
)
;;;*****************************************************
(defun sort_trai_phai (tongsothua list_sort / list_tmp step sp ep m k p last_point le dn)
 (setq     
    step 20 ; Do rong cua giai danh so thua la 20m, sua them chut de cho user nhap gia tri nay tu ban phim moi lan chay
    m (- tongsothua 1)
    sp (+ (cadr(nth 0 list_sort)) (* step 0.5))   ; sp.Y + step*0.5     
    ep (cadr (nth m list_sort))                   ; ep.Y     
    ;num_down (+ (fix(/(- sp ep)step)) 1)
    last_point (list (car(nth m list_sort)) (cadr(nth m list_sort)) )
    chan 0  ; neu chan danh tu Trai sang phai, neu le danh tu Phai sang trai
    dn 0
 )  
 (while (> sp ep)
    (setq k 0)
    (setq list_tmp nil)
    (while (< k m)        
       (if (and (<=(cadr(nth k list_sort)) sp) (>(cadr(nth k list_sort)) (- sp step))  )
   (progn	      
      (setq p (list (car(nth k list_sort)) (cadr(nth k list_sort))))	      
      (setq List_tmp (append List_tmp (list p) ) )	      
   )  
)        
       (setq k (1+ k))        
    );while k
    (setq dn (1+ dn))
    (setq chan(rem dn 2))     
    (if (= chan 0)
       (setq list_tmp (vl-sort list_tmp (function (lambda (e1 e2)(> (car e1)(car e2))))) ) ; chan
       (setq list_tmp (vl-sort list_tmp (function (lambda (e1 e2)(< (car e1)(car e2))))) ) ; le
    );if chan
    (setq List_ok (append List_ok list_tmp))
    (setq sp (- sp step))     
 );while sp;
 (setq List_ok (append List_ok (list last_point) ) )
)
;;;*****************************************************
(defun wtxt2 (txt p lay sty k hj vj / d h) ;;;Write txt on graphic screen (from Ssg - Cadviet forum) 
;;;Specify txt, point, layer, style, scale factor, hor justify, ver justify
(setq
   d (tblsearch "style" sty)
   h (cdr (assoc 40 d))
   LH (list "L" "C" "R")    ;;;Left, Center, Right
   LV (list "" "B" "M" "T") ;;;Bottom, Middle, Top
   hcode (vl-position hj LH)
   vcode (vl-position vj LV)
)
(if (= h 0) (setq h (cdr (assoc 42 d))))
(entmake
   (list (cons 0 "TEXT") (cons 8 lay) (cons 7 sty) (cons 1 txt) (cons 10 p) (cons 11 p)
   (cons 40 (* k h)) (assoc 41 d) (cons 72 hcode) (cons 73 vcode))
)
)
;;;*****************************************************

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Lisp đánh số thửa cho thửa đất. Xem đúng bài viết #44181 để đọc hướng dẫn và trao đổi thêm.

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