Jump to content

Lisp Vẽ Polyline Kín +Hatch Khi Biết Trước Diện Tích Và Nhập Số Điểm

Nói chung là đoán mò. Vẽ pline bằng cách pick điểm. Scale cho cái pline đó có diện tích như mong muốn. Nếu đúng thì viết như này:

(defun c:vdt ()

(command "pline")
(princ "\nSpecify start point:")
(while (< 0 (getvar "CMDACTIVE"))
(command pause)
(princ "\nSpecify next point or [Arc/Close/Halfwidth/Length/Undo/Width]:")
) 

(command "area" "object" "last")
(setq dtt (getvar "area"))
(setq cheot (* dtt 2)) 
(setq cheotr (sqrt cheot)) 
(setq dts (getreal "\nDien tich mong muon : "))
(setq cheos (* dts 2)) 
(setq cheosr (sqrt cheos)) 
(setq tilenhan (/ cheosr cheotr))
(setq dc (getpoint "\nChon diem goc: "))
(command "scale" "last" "" "_non" dc tilenhan)
(princ))

Phần hatch thì cần đề cho tên. tỉ lệ của hatch thì mới viết không mất công sửa mệt.

Cách dùng

  1. Tải tệp 407756_vdt.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 VDT để chạy lisp.

Mã nguồn 407756_vdt.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/165891-nh%E1%BB%9D-ch%E1%BB%89nh-s%E1%BB%ADa-lisp-lisp-v%E1%BA%BD-polyline-k%C3%ADn-hatch-khi-bi%E1%BA%BFt-tr%C6%B0%E1%BB%9Bc-di%E1%BB%87n-t%C3%ADch-v%C3%A0-nh%E1%BA%ADp-s%E1%BB%91-%C4%91i%E1%BB%83m/
(defun c:vdt ()

(command "pline")
(princ "\nSpecify start point:")
(while (< 0 (getvar "CMDACTIVE"))
(command pause)
(princ "\nSpecify next point or [Arc/Close/Halfwidth/Length/Undo/Width]:")
) 

(command "area" "object" "last")
(setq dtt (getvar "area"))
(setq cheot (* dtt 2)) 
(setq cheotr (sqrt cheot)) 
(setq dts (getreal "\nDien tich mong muon : "))
(setq cheos (* dts 2)) 
(setq cheosr (sqrt cheos)) 
(setq tilenhan (/ cheosr cheotr))
(setq dc (getpoint "\nChon diem goc: "))
(command "scale" "last" "" "_non" dc tilenhan)
(princ))

Thảo luận gốc

Lisp được chia sẻ trong chủ đề [Nhờ Chỉnh Sửa Lisp] Lisp Vẽ Polyline Kín +Hatch Khi Biết Trước Diện Tích Và Nhập Số Điểm. Xem đúng bài viết #407756 để đọc hướng dẫn và trao đổi thêm.

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