Jump to content

Lisp lệnh 2D3D trong chủ đề “Viết lisp theo yêu cầu [phần 2]”


@duongthanh85 : Bạn nên upload file .dwg và nói rõ hơn. Vì có thể mình chưa hiểu hết điều bạn nói

Cách dùng

  1. Tải tệp 72260_2d3d.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 2D3D để chạy lisp.

Mã nguồn 72260_2d3d.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/13203-vi%E1%BA%BFt-lisp-theo-y%C3%AAu-c%E1%BA%A7u-ph%E1%BA%A7n-2/
(defun c:2d3d(/ curve pre i p lstdiem z lstpoint x ss oldos)
(vl-load-com)
(setvar "orthomode" 0)
(setvar "cmdecho" 0)
(setq oldos (getvar "osmode"))
(setvar "osmode" 0)
(setq curve (car(entsel "\n Pick chon POlyline 2D hoac Polyline 3D :")))
(setq pre (vlax-curve-getEndParam curve) i 0 lstdiem '() lstpoint '() ss (ssadd))
(setq cao (getdist "\n Chon chieu cao chu :"))

(while ((setq p (vlax-curve-getPointAtParam curve i))
(setq lstdiem (append lstdiem (list p)))
(wtxt (rtos (caddr p) 2 2) p 0 cao)
(setq ss (ssadd (entlast) ss))
(setq i (1+ i))
)

(setq i 0)
(foreach x lstdiem
(setq z (getdist x (strcat "\n Nhap cao do cho diem nay  : ") ))
(setq lstpoint (append lstpoint (list(list (car x) (cadr x) z))))
(wtxt (rtos z 2 2) (list (car x) (cadr x) z) 0 cao)
(entdel (ssname ss i))
(setq i (1+ i))
)

(command "3dpoly")
(foreach y lstpoint (command y))
(command "")
(entdel curve)
(setvar "osmode" oldos)
(princ)
)
;
(defun wtxt (txt p ang h / sty)
(setq sty (getvar "textstyle"))
(entmake (list (cons 0 "TEXT") (cons 7 sty) 
(cons 1 txt) (cons 10 p) (cons 11 p) 
(cons 72 2) (cons 73 1) (cons 50 ang) 
(cons 40 h) (cons 41 0.8))
)
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Viết lisp theo yêu cầu [phần 2]. Xem đúng bài viết #72260 để đọc hướng dẫn và trao đổi thêm.

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