Jump to content

Lisp lệnh V trong chủ đề “nhờ kết hợp 2 lisp”

Vậy bạn thử cái này, lệnh V, chọn tỷ lệ, chọn vị trí đặt text kết quả, nhấp vùng cần chọn, xong enter.

Trước khi vào lệnh thì cho biến textsize to nhỏ tùy ý (trong bản vẽ bạn đưa thấy biến này hơi nhỏ).

Nếu nó không bắt được cái hatch naò trong vùng pick thì nó sẽ hỏi chọn đối tượng để lấy layer.

 

 

(defun c:v(/ tl1 ntl tl2 dtl ss hat hatlay oslast txtsiz pt1 et vsize dtcon elst)
  (if (= tl nil) 
    (setq tl (getreal "\nDrawing scale : "))    
  )
  (setq ntl (/ 1000 tl))
  (setq tl2 (* ntl ntl))
  (setq dtl 0)
  (setq ss (ssadd) hat nil)
  (setq oslast (getvar "OSMODE"))
  (setvar "OSMODE" 0)
  (print)
  (if (not pt0) (setq pt0 (getpoint "\nChon diem dat text:")))
  (setq txtsiz (getvar "textsize"))
 
  (setq pt1 (getpoint "\nPick internal point : "))
  (while (/= pt1 nil)
    (if (not hat)
      (progn
        (setq hat (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget pt1 '((0 . "HATCH")))))))
        (if hat (setq hatlay (cdr (assoc 8 (entget (car hat)))))))
    )    
    (command "-boundary" pt1 "")
    (setq et (entlast))
    (ssadd et ss)
    (command "area" "e" "last")
    (setq vsize ( / (getvar "VIEWSIZE") 3 ))
    (command "hatch" "ANSI31" vsize "0" "last" "")
    (setq et (entlast))
    (ssadd et ss)
    (setq dtcon (getvar "AREA"))
    (setq dtl (+ dtcon dtl))
    (print)
    (setq pt1 (getpoint "\nPick internal point : "))
  )
  (command "setvar" "OSMODE" oslast)
  (command "erase" ss "")
  (setq ss nil)
  (command "redraw")
  (setq dtl (/ dtl tl2))
  (print dtl)
  (if (not hatlay) (setq hatlay (cdr (assoc 8 (entget (car (entsel "\Chon layer theo:")))))))
  (vla-addtext (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))
    (strcat hatlay " : " (rtos dtl 2 2)) (vlax-3d-point pt0) txtsiz)
  (setq pt0 (polar pt0 -1.5708 (* 2 txtsiz)))
  (print)
)

Cách dùng

  1. Tải tệp 311928_v.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 V để chạy lisp.

Mã nguồn 311928_v.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/108785-nh%E1%BB%9D-k%E1%BA%BFt-h%E1%BB%A3p-2-lisp/
(defun c:v(/ tl1 ntl tl2 dtl ss hat hatlay oslast txtsiz pt1 et vsize dtcon elst)
  (if (= tl nil) 
    (setq tl (getreal "\nDrawing scale : "))    
  )
  (setq ntl (/ 1000 tl))
  (setq tl2 (* ntl ntl))
  (setq dtl 0)
  (setq ss (ssadd) hat nil)
  (setq oslast (getvar "OSMODE"))
  (setvar "OSMODE" 0)
  (print)
  (if (not pt0) (setq pt0 (getpoint "\nChon diem dat text:")))
  (setq txtsiz (getvar "textsize"))
 
  (setq pt1 (getpoint "\nPick internal point : "))
  (while (/= pt1 nil)
    (if (not hat)
      (progn
        (setq hat (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget pt1 '((0 . "HATCH")))))))
        (if hat (setq hatlay (cdr (assoc 8 (entget (car hat)))))))
    )    
    (command "-boundary" pt1 "")
    (setq et (entlast))
    (ssadd et ss)
    (command "area" "e" "last")
    (setq vsize ( / (getvar "VIEWSIZE") 3 ))
    (command "hatch" "ANSI31" vsize "0" "last" "")
    (setq et (entlast))
    (ssadd et ss)
    (setq dtcon (getvar "AREA"))
    (setq dtl (+ dtcon dtl))
    (print)
    (setq pt1 (getpoint "\nPick internal point : "))
  )
  (command "setvar" "OSMODE" oslast)
  (command "erase" ss "")
  (setq ss nil)
  (command "redraw")
  (setq dtl (/ dtl tl2))
  (print dtl)
  (if (not hatlay) (setq hatlay (cdr (assoc 8 (entget (car (entsel "\Chon layer theo:")))))))
  (vla-addtext (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))
    (strcat hatlay " : " (rtos dtl 2 2)) (vlax-3d-point pt0) txtsiz)
  (setq pt0 (polar pt0 -1.5708 (* 2 txtsiz)))
  (print)
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề nhờ kết hợp 2 lisp. Xem đúng bài viết #311928 để đọc hướng dẫn và trao đổi thêm.

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