Jump to content

Kết hợp lisp

18 giờ trước, loranypt đã nói:

minh load được lệnh rồi , nhưng nó chỉ dừng tới chỗ rải thép , còn lấy thông tin chiều dài thanh thép thì lại error

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/175622-y%C3%AAu-c%E1%BA%A7u-k%E1%BA%BFt-h%E1%BB%A3p-lisp/
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/163324-lisp-r%C3%A3i-th%C3%A9p-s%C3%A0n/
(defun c:sl (/ a1 c)
  (setq luu (getvar "osmode"))
  (setq lay (getvar "clayer"))
  (setq p1 (getpoint "Chon diem xuat phat\n"))
  (setq p2 (getpoint p1 "Chon diem ket thuc\n"))
  (command "_Pline" p1 p2 "")
  (setq a1 (Distance p1 p2))
  (or (and a (or (= (type a) 'int) (= (type a) 'real)))
      (setq a 200)
  )
  (setq Caochu 300)
  (or (and hbv (or (= (type hbv) 'int) (= (type hbv) 'real)))
      (setq hbv 10)
  )
  (setq    hbv
     (cond
       ((getreal (strcat "\nduong kinh thep <" (rtos hbv 2 2) ">: ")
        )
       )
       (hbv)
     )
  )
  (setq c (1+ (/ a1 a)))
  (setq p (getpoint "\n Chon diem nhap ket qua" ))
  (entmake
             (list
               (cons 0 "TEXT")
               (cons 10 (list (car p) (cadr p)))
               (cons 40 Caochu)
               (cons
                 1
                 (strcat (rtos c 2 0) "D" (rtos hbv 2 0))
               )
             )
               )

  (AC:TT Caochu)
  (Ac:at2t)
  (SETVAR "clayer" lay)
  (setvar "osmode" luu)
  (princ)
)
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/60478-nh%E1%BB%9D-ch%E1%BB%89nh-s%E1%BB%ADa%C4%91o-chi%E1%BB%81u-d%C3%A0i-v%C3%A0-ghi-ra-text/
(defun AC:TT(Caochu / ss L e)
(vl-load-com)
(defun Length1(e) (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e)))
;(or ans (setq ans 2))
(Alert (strcat "Chon PLine thep\n"))
(setq L (strcat "L= "
   (vl-princ-to-string (* (getvar "dimlfac") (apply '+
       (mapcar 'Length1 (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget (list (cons 0 "LINE,ARC,CIRCLE,POLYLINE,LWPOLYLINE,ELLIPSE,SPLINE")))))))
   )))
   ))
 (setq p (getpoint "\n Chon diem nhap ket qua" ))
  (entmake
             (list
               (cons 0 "TEXT")
               (cons 10 (list (car p) (cadr p)))
               (cons 40 Caochu)
               (cons 1 L
               )
             )
               )
(princ)
)
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/13074-lisp-gh%C3%A9p-text-c%E1%BA%A7n-gi%C3%BAp-%C4%91%E1%BB%A1/?page=2
(defun Ac:at2t (/ center color data edata ent i sel ss str);All Text to Text
 (defun centerSS (ss / lst_max lst_min maxpt minpt ll ur)
   (vl-load-com)
   (foreach ent (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
     (vla-GetBoundingBox ent 'minpt 'maxpt)
     (setq lst_min (cons (vlax-safearray->list minpt) lst_min)
    lst_max (cons (vlax-safearray->list maxpt) lst_max)  )   )
   (setq ll (list (car (vl-sort (mapcar 'car lst_min) '<))
       (car (vl-sort (mapcar 'cadr lst_min) '<))  )
  ur (list (last (vl-sort (mapcar 'car lst_max) '<))
       (last (vl-sort (mapcar 'cadr lst_max) '<)) ) )
   (mapcar '/ (mapcar '+ ll ur) '(2.0 2.0 2.0))    )  

 (defun Change_Str (data pt str color)
   (entmake (list (cons 0 "TEXT") (assoc 8 data) (cons 10 pt)
       (cons 11 pt) (assoc 7 data) (assoc 40 data)
       (cons 71 0) (cons 72 1) (cons 73 2)
       (cons 1 str) (cons 62 color)
       (if (assoc 6 data)  (assoc 6 data)  '(6 . "BYLAYER") )
       (if (assoc 39 data) (assoc 39 data) '(39 . 0) )
       (if (assoc 370 data) (assoc 370 data) '(370 . -1) ) ))  )

 (defun dxf (tag obj) (cdr (assoc tag obj)))
;main
 (or *color* (setq *color* 6 ))
 (setq color (getint (strcat "\nNhap so mau cua Text sau khi hoan thanh <" (itoa *color*) "> :")) )
 (if color (setq *color* color) (setq color *color*))
 (setq ss (ssadd))
  (Alert (strcat "Chon Text chieu dai thep truoc\n"))
 (while (setq ent
      (car
        (LM:SelectIf "\nB\U+1EA1n \U+0111\U+00E3 Ch\U+1ECDn Text \U+0111\U+1EC3 N\U+1ED1i: "
          (lambda ( x ) (eq "TEXT" (cdr (assoc 0 (entget (car x)))))) entsel nil
        )
      )
    )   ;(setq sel (entsel "\nChon cac Text can noi voi nhau: "))
   ;(setq ent (car sel))
   (if (= (cdr (assoc 0 (entget ent))) "TEXT")
     (ssadd ent ss)
   )
 )  
 (if (> (sslength ss) 0)
   (progn
     (setq i -1
    str ""
    center (centerSS ss)        
    data (entget (ssname ss 0))        )
     (while (setq ent (ssname ss (setq i (1+ i))))
       (setq edata (entget ent)
         str   (strcat (dxf 1 edata)" " str  )
       )
       (entdel ent)
     )
     (Change_Str data center (substr str 1) color)     )
   (princ "\nKhong chon duoc Text !"))
 (princ))
;===========
(defun LM:SelectIf ( msg pred func keyw / sel ) (setq pred (eval pred))
(while
(progn (setvar 'ERRNO 0) (if keyw (apply 'initget keyw)) (setq sel (func msg))
(cond
( (= 7 (getvar 'ERRNO))
(princ "\nB\U+1EA1n ch\U+1ECDn sai r\U+1ED3i _  B\U+1EA5m ch\U+1ECDn \U+0111\U+1ED1i t\U+01B0\U+1EE3ng, Try again.")
)
( (eq 'STR (type sel))
nil
)
( (vl-consp sel)
(if (and pred (not (pred sel)))
(princ "\n\U+0110\U+1ED1i t\U+01B0\U+1EE3ng  ch\U+1ECDn kh\U+00F4ng h\U+1EE3p l\U+1EC7.")
)
)
)
)
)
sel
)

@loranypt@huunhantvxdts Mạo muội edit lại như này, hi vọng đúng ý bạn. đúng thì cho xin 1 Like +

Cách dùng

  1. Tải tệp 434456_sl.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 SL để chạy lisp.

Mã nguồn 434456_sl.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/175622-y%C3%AAu-c%E1%BA%A7u-k%E1%BA%BFt-h%E1%BB%A3p-lisp/
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/175622-y%C3%AAu-c%E1%BA%A7u-k%E1%BA%BFt-h%E1%BB%A3p-lisp/
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/163324-lisp-r%C3%A3i-th%C3%A9p-s%C3%A0n/
(defun c:sl (/ a1 c)
  (setq luu (getvar "osmode"))
  (setq lay (getvar "clayer"))
  (setq p1 (getpoint "Chon diem xuat phat\n"))
  (setq p2 (getpoint p1 "Chon diem ket thuc\n"))
  (command "_Pline" p1 p2 "")
  (setq a1 (Distance p1 p2))
  (or (and a (or (= (type a) 'int) (= (type a) 'real)))
      (setq a 200)
  )
  (setq Caochu 300)
  (or (and hbv (or (= (type hbv) 'int) (= (type hbv) 'real)))
      (setq hbv 10)
  )
  (setq    hbv
     (cond
       ((getreal (strcat "\nduong kinh thep <" (rtos hbv 2 2) ">: ")
        )
       )
       (hbv)
     )
  )
  (setq c (1+ (/ a1 a)))
  (setq p (getpoint "\n Chon diem nhap ket qua" ))
  (entmake
             (list
               (cons 0 "TEXT")
               (cons 10 (list (car p) (cadr p)))
               (cons 40 Caochu)
               (cons
                 1
                 (strcat (rtos c 2 0) "D" (rtos hbv 2 0))
               )
             )
               )

  (AC:TT Caochu)
  (Ac:at2t)
  (SETVAR "clayer" lay)
  (setvar "osmode" luu)
  (princ)
)
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/60478-nh%E1%BB%9D-ch%E1%BB%89nh-s%E1%BB%ADa%C4%91o-chi%E1%BB%81u-d%C3%A0i-v%C3%A0-ghi-ra-text/
(defun AC:TT(Caochu / ss L e)
(vl-load-com)
(defun Length1(e) (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e)))
;(or ans (setq ans 2))
(Alert (strcat "Chon PLine thep\n"))
(setq L (strcat "L= "
   (vl-princ-to-string (* (getvar "dimlfac") (apply '+
       (mapcar 'Length1 (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget (list (cons 0 "LINE,ARC,CIRCLE,POLYLINE,LWPOLYLINE,ELLIPSE,SPLINE")))))))
   )))
   ))
 (setq p (getpoint "\n Chon diem nhap ket qua" ))
  (entmake
             (list
               (cons 0 "TEXT")
               (cons 10 (list (car p) (cadr p)))
               (cons 40 Caochu)
               (cons 1 L
               )
             )
               )
(princ)
)
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/13074-lisp-gh%C3%A9p-text-c%E1%BA%A7n-gi%C3%BAp-%C4%91%E1%BB%A1/?page=2
(defun Ac:at2t (/ center color data edata ent i sel ss str);All Text to Text
 (defun centerSS (ss / lst_max lst_min maxpt minpt ll ur)
   (vl-load-com)
   (foreach ent (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
     (vla-GetBoundingBox ent 'minpt 'maxpt)
     (setq lst_min (cons (vlax-safearray->list minpt) lst_min)
    lst_max (cons (vlax-safearray->list maxpt) lst_max)  )   )
   (setq ll (list (car (vl-sort (mapcar 'car lst_min) '<))
       (car (vl-sort (mapcar 'cadr lst_min) '<))  )
  ur (list (last (vl-sort (mapcar 'car lst_max) '<))
       (last (vl-sort (mapcar 'cadr lst_max) '<)) ) )
   (mapcar '/ (mapcar '+ ll ur) '(2.0 2.0 2.0))    )  

 (defun Change_Str (data pt str color)
   (entmake (list (cons 0 "TEXT") (assoc 8 data) (cons 10 pt)
       (cons 11 pt) (assoc 7 data) (assoc 40 data)
       (cons 71 0) (cons 72 1) (cons 73 2)
       (cons 1 str) (cons 62 color)
       (if (assoc 6 data)  (assoc 6 data)  '(6 . "BYLAYER") )
       (if (assoc 39 data) (assoc 39 data) '(39 . 0) )
       (if (assoc 370 data) (assoc 370 data) '(370 . -1) ) ))  )

 (defun dxf (tag obj) (cdr (assoc tag obj)))
;main
 (or *color* (setq *color* 6 ))
 (setq color (getint (strcat "\nNhap so mau cua Text sau khi hoan thanh <" (itoa *color*) "> :")) )
 (if color (setq *color* color) (setq color *color*))
 (setq ss (ssadd))
  (Alert (strcat "Chon Text chieu dai thep truoc\n"))
 (while (setq ent
      (car
        (LM:SelectIf "\nB\U+1EA1n \U+0111\U+00E3 Ch\U+1ECDn Text \U+0111\U+1EC3 N\U+1ED1i: "
          (lambda ( x ) (eq "TEXT" (cdr (assoc 0 (entget (car x)))))) entsel nil
        )
      )
    )   ;(setq sel (entsel "\nChon cac Text can noi voi nhau: "))
   ;(setq ent (car sel))
   (if (= (cdr (assoc 0 (entget ent))) "TEXT")
     (ssadd ent ss)
   )
 )  
 (if (> (sslength ss) 0)
   (progn
     (setq i -1
    str ""
    center (centerSS ss)        
    data (entget (ssname ss 0))        )
     (while (setq ent (ssname ss (setq i (1+ i))))
       (setq edata (entget ent)
         str   (strcat (dxf 1 edata)" " str  )
       )
       (entdel ent)
     )
     (Change_Str data center (substr str 1) color)     )
   (princ "\nKhong chon duoc Text !"))
 (princ))
;===========
(defun LM:SelectIf ( msg pred func keyw / sel ) (setq pred (eval pred))
(while
(progn (setvar 'ERRNO 0) (if keyw (apply 'initget keyw)) (setq sel (func msg))
(cond
( (= 7 (getvar 'ERRNO))
(princ "\nB\U+1EA1n ch\U+1ECDn sai r\U+1ED3i _  B\U+1EA5m ch\U+1ECDn \U+0111\U+1ED1i t\U+01B0\U+1EE3ng, Try again.")
)
( (eq 'STR (type sel))
nil
)
( (vl-consp sel)
(if (and pred (not (pred sel)))
(princ "\n\U+0110\U+1ED1i t\U+01B0\U+1EE3ng  ch\U+1ECDn kh\U+00F4ng h\U+1EE3p l\U+1EC7.")
)
)
)
)
)
sel
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề [Yêu Cầu] Kết hợp lisp. Xem đúng bài viết #434456 để đọc hướng dẫn và trao đổi thêm.

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