Jump to content

Lisp lệnh VC trong chủ đề “Bảng toạ độ các đỉnh thửa đất”

To SSG !



Bác SSG có thể giúp làm cho cái CT ở trên khi chạy số thứ tự đỉnh sẽ theo chiều thuận kim đồng hồ không ? vì khi dùng lệnh BO bao giờ cad cũng cho các đỉnh theo chiều ngược kim đồng hồ.
Tôi ko rành về lisp lắm nên ko biết cách sửa đoạn code trên mặc dù về thuật toán thì tôi biết làm thế nào để cho các đỉnh thửa chạy theo chiều thuận kim đồng hồ. VD các vertex List(x1y1, x2y2, xiyi...) thì khi đánh số thứ tự chỉ việc đảo ngược lại .

TKS

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 10421_vc.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 VC để chạy lisp.

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

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;This program make ordinal numbers and co-ordinate table for vertexs.
;;;Accept any objects that are Region, Polyline, Line and Arc (except Spline)
;;;providing there is a closed area between them.
;;;Written by Ssg - December 2007 - www.cadviet.com
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;PUBLIC FUNCTIONS
;;;-------------------------------------------------------------------------------
(Defun DTR(x) (/ (* x pi) 180) ) ;;;change degree to radian, return REAL
;;;-------------------------------------------------------------------------------
(defun lineP (p0 a r / p1) ;;;Line polar: point, degree angle, radius
(setq p1 (polar p0 (dtr a) r))
(command "line" p0 p1 "")
)
;;;-------------------------------------------------------------------------------
(defun linePX (p0 x) (lineP p0 0 x)) ;;;Horizontal line: length x, from p0
;;;-------------------------------------------------------------------------------
(defun linePY (p0 y) (lineP p0 90 y)) ;;;Vertical line: length y, from p0
;;;-------------------------------------------------------------------------------
(defun getVert (e / i L) ;;;Return list of all vertex from pline e
(setq i 0 L nil)
(vl-load-com)
(repeat (fix (+ (vlax-curve-getEndParam e) 1))
(setq L (append L (list (vlax-curve-getPointAtParam e i))))
(setq i (1+ i))
)
L
)
;;;-------------------------------------------------------------------------------
(defun getth( / d h) ;;;Return current text height
(setq
d (tblsearch "style" (getvar "textstyle"))
h (cdr (assoc 40 d))
)
(if (= h 0) (setq h (cdr (assoc 42 d))))
h
)
;;;-------------------------------------------------------------------------------
(defun wtxtMC (txt p / sty d h) ;;;Write txt on graphic screen, Middle Center
(setq
sty (getvar "textstyle")
d (tblsearch "style" sty)
h1 (cdr (assoc 40 d))
h2 (cdr (assoc 42 d))
)
(if (> h1 0) (command "text" "j" "mc" p 0 txt)
(command "text" "j" "mc" p h2 0 txt)
)
)
;;;-------------------------------------------------------------------------------
;;;PRIVATE FUNCTIONS
;;;-------------------------------------------------------------------------------
(defun txt1(txtL / p1 p2 p3 p4 pL i) ;;;Write texts in 1 row
(setq
p1 (list (+ (car p0) (* 2 h)) (- (cadr p0) (* 1.5 h)))
p2 (polar p1 0 (* 6 h))
p3 (polar p2 0 (* 8 h))
p4 (polar p3 0 (* 8 h))
pL (list p1 p2 p3 p4)
i 0
)
(repeat 4
(wtxtMC (nth i txtL) (nth i pL))
(setq i (1+ i))
)
)
;;;-------------------------------------------------------------------------------
(defun mesh1() ;;;Make 1 mesh unit
(linepy p0 (* -3 h))
(command "copy" "L" "" p0 (list (+ (car p0) (* 4 h)) (cadr p0)))
(command "array" "L" "" "r" 1 4 (* 8 h))
(linepx (polar p0 (* 1.5 pi) (* 3 h)) (* 28 h))
)
;;;-------------------------------------------------------------------------------
;;;MAIN PROGRAM
;;;-------------------------------------------------------------------------------
(defun C:VC( / p et p0 pvL h oldos i pv num txtL)
;;;Vertex Co-ordinate

;;;INPUT DATA
(setq p (getpoint "\nPick a point inside polygon or region:"))
(command "boundary" p "")
(setq et (entlast))
(redraw et 3)
(setq
p0 (getpoint "\nBase point of table (upper left):")
pvL (getvert et)
h (getTh)
oldos (getvar "osmode")
)
(setvar "osmode" 0)

;;;HEADER
(linepx p0 (* 28 h))
(mesh1)
(txt1 (list "TT" "X" "Y" "Z"))
(setq p0 (polar p0 (* 1.5 pi) (* 3 h)))

;;;MAKE RECORDS AND ORDINAL NUMBER
(setq i 0)
(repeat (1- (length pvL))
(mesh1)
(setq
pv (nth i pvL)
num (itoa (1+ i))
txtL (list num (rtos (car pv)) (rtos (cadr pv)) (rtos (caddr pv)))
)
(txt1 txtL)
(wtxtMC num (polar pv 0 h))
(setq p0 (polar p0 (* 1.5 pi) (* 3 h)))
(setq i (1+ i))
)

;;;FINISH
(command "erase" et "")
(setvar "osmode" oldos)
(princ)
)
;;;-------------------------------------------------------------------------------

Thảo luận gốc

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

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