Lisp lệnh VEHOGA VHGA trong chủ đề “[nhờ chỉnh sửa] lisp vẽ pline”
mình đang viết lisp vẽ kích thước hố ga nhưng vướng 1 cái là vẽ các pline không được (nó chồng lên nhau hoặc khi được khi không) nhờ mọi người giúp đỡ cám ơn nhiều
đây là đoạn lisp
(defun c:vehoga ()
(setq p (getpoint "\nNhap diem ve:"))
(setq h 2.5);(distof cc))
(setq b 1.2);(distof cr))
(setq l 1.0);(distof cd))
(setq d 0.2);(distof dt))
(setq goc (/ pi 2))
(setq b1 (+ b (* 2 d)))
(setq h1 (- h d))
(setq goc1 (* 3 (/ pi 2)))
(setq p0 (polar p goc1 d))
(vethanhtrong)
(vethanhngoai)
(princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun vethanhtrong ()
(setq p1 (polar p 0 (/ b 2)))
(setq p2 (polar p1 goc h1))
(setq p3 (polar p pi (/ b 2)))
(setq p4 (polar p3 goc h1))
(command ".Pline" p2 p1 p3 p4 "")
(COMMAND ".PEDIT" "last" "W" "0" "")
)
(defun vethanhngoai ()
(setq p5 (polar p0 0 (/ b1 2)))
(setq p6 (polar p5 goc h))
(setq p7 (polar p0 pi (/ b1 2)))
(setq p8 (polar p7 goc h))
(command ".Pline" p6 p5 p7 p8 "")
(COMMAND ".PEDIT" "last" "W" "0" "")
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun C:vhga ()
(dodegoi))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun dodegoi (/ COM)
(setq DCL_ID (load_dialog (strcat odiachay "\\tlkt\\dcl\\chon.DCL")))
(new_dialog "CONG" DCL_ID)
(if (not cc) (setq cc "0.00"))
(set_tile "cc" cc)
(if (not cr) (setq cr "0.00"))
(set_tile "cr" cr)
(if (not cd) (setq cd "0.00"))
(set_tile "cd" cd)
(if (not dt) (setq dt "0.00"))
(set_tile "dt" dt)
(action_tile "cc" "(setq cc $value) (KIEM_TRA_LOI)")
(action_tile "cr" "(setq cr $value) (KIEM_TRA_LOI)")
(action_tile "cd" "(setq cd $value) (KIEM_TRA_LOI)")
(action_tile "dt" "(setq dt $value) (KIEM_TRA_LOI)")
(action_tile "ve" "(done_dialog 1)")
(action_tile "thoat" "(done_dialog 14)")
(setq phepchon(start_dialog))
(cond
((= phepchon 1) (vehoga))
((= phepchon 14) (thoi))
)
(unload_dialog DCL_ID)
(princ))
(defun KIEM_TRA_LOI ()
(set_tile "error" "")
(if
(/= (type (distof cc)) 'real)
(progn
(set_tile "error" "Nhap lai chieu cao!")
(mode_tile "cc" 2)))
(if
(/= (type (distof cr)) 'real)
(progn
(set_tile "error" "Nhap lai chieu rong!")
(mode_tile "cr" 2)))
(if
(/= (type (distof cd)) 'real)
(progn
(set_tile "error" "Nhap lai chieu dai!")
(mode_tile "cd" 2)))
(if
(/= (type (distof dt)) 'real)
(progn
(set_tile "error" "Nhap lai day thanh!")
(mode_tile "dt" 2)))
)
đây là đoạn lisp
(defun c:vehoga ()
(setq p (getpoint "\nNhap diem ve:"))
(setq h 2.5);(distof cc))
(setq b 1.2);(distof cr))
(setq l 1.0);(distof cd))
(setq d 0.2);(distof dt))
(setq goc (/ pi 2))
(setq b1 (+ b (* 2 d)))
(setq h1 (- h d))
(setq goc1 (* 3 (/ pi 2)))
(setq p0 (polar p goc1 d))
(vethanhtrong)
(vethanhngoai)
(princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun vethanhtrong ()
(setq p1 (polar p 0 (/ b 2)))
(setq p2 (polar p1 goc h1))
(setq p3 (polar p pi (/ b 2)))
(setq p4 (polar p3 goc h1))
(command ".Pline" p2 p1 p3 p4 "")
(COMMAND ".PEDIT" "last" "W" "0" "")
)
(defun vethanhngoai ()
(setq p5 (polar p0 0 (/ b1 2)))
(setq p6 (polar p5 goc h))
(setq p7 (polar p0 pi (/ b1 2)))
(setq p8 (polar p7 goc h))
(command ".Pline" p6 p5 p7 p8 "")
(COMMAND ".PEDIT" "last" "W" "0" "")
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun C:vhga ()
(dodegoi))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun dodegoi (/ COM)
(setq DCL_ID (load_dialog (strcat odiachay "\\tlkt\\dcl\\chon.DCL")))
(new_dialog "CONG" DCL_ID)
(if (not cc) (setq cc "0.00"))
(set_tile "cc" cc)
(if (not cr) (setq cr "0.00"))
(set_tile "cr" cr)
(if (not cd) (setq cd "0.00"))
(set_tile "cd" cd)
(if (not dt) (setq dt "0.00"))
(set_tile "dt" dt)
(action_tile "cc" "(setq cc $value) (KIEM_TRA_LOI)")
(action_tile "cr" "(setq cr $value) (KIEM_TRA_LOI)")
(action_tile "cd" "(setq cd $value) (KIEM_TRA_LOI)")
(action_tile "dt" "(setq dt $value) (KIEM_TRA_LOI)")
(action_tile "ve" "(done_dialog 1)")
(action_tile "thoat" "(done_dialog 14)")
(setq phepchon(start_dialog))
(cond
((= phepchon 1) (vehoga))
((= phepchon 14) (thoi))
)
(unload_dialog DCL_ID)
(princ))
(defun KIEM_TRA_LOI ()
(set_tile "error" "")
(if
(/= (type (distof cc)) 'real)
(progn
(set_tile "error" "Nhap lai chieu cao!")
(mode_tile "cc" 2)))
(if
(/= (type (distof cr)) 'real)
(progn
(set_tile "error" "Nhap lai chieu rong!")
(mode_tile "cr" 2)))
(if
(/= (type (distof cd)) 'real)
(progn
(set_tile "error" "Nhap lai chieu dai!")
(mode_tile "cd" 2)))
(if
(/= (type (distof dt)) 'real)
(progn
(set_tile "error" "Nhap lai day thanh!")
(mode_tile "dt" 2)))
)
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
- Chép mã nguồn, lưu thành tệp 225829_vehoga_vhga.lsp.
- 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ẽ.
- Gõ lệnh VEHOGA VHGA để chạy lisp.
Mã nguồn 225829_vehoga_vhga.lsp (trích từ bài viết gốc)
(defun c:vehoga ()
(setq p (getpoint "\nNhap diem ve:"))
(setq h 2.5);(distof cc))
(setq b 1.2);(distof cr))
(setq l 1.0);(distof cd))
(setq d 0.2);(distof dt))
(setq goc (/ pi 2))
(setq b1 (+ b (* 2 d)))
(setq h1 (- h d))
(setq goc1 (* 3 (/ pi 2)))
(setq p0 (polar p goc1 d))
(vethanhtrong)
(vethanhngoai)
(princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun vethanhtrong ()
(setq p1 (polar p 0 (/ b 2)))
(setq p2 (polar p1 goc h1))
(setq p3 (polar p pi (/ b 2)))
(setq p4 (polar p3 goc h1))
(command ".Pline" p2 p1 p3 p4 "")
(COMMAND ".PEDIT" "last" "W" "0" "")
)
(defun vethanhngoai ()
(setq p5 (polar p0 0 (/ b1 2)))
(setq p6 (polar p5 goc h))
(setq p7 (polar p0 pi (/ b1 2)))
(setq p8 (polar p7 goc h))
(command ".Pline" p6 p5 p7 p8 "")
(COMMAND ".PEDIT" "last" "W" "0" "")
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun C:vhga ()
(dodegoi))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun dodegoi (/ COM)
(setq DCL_ID (load_dialog (strcat odiachay "\\tlkt\\dcl\\chon.DCL")))
(new_dialog "CONG" DCL_ID)
(if (not cc) (setq cc "0.00"))
(set_tile "cc" cc)
(if (not cr) (setq cr "0.00"))
(set_tile "cr" cr)
(if (not cd) (setq cd "0.00"))
(set_tile "cd" cd)
(if (not dt) (setq dt "0.00"))
(set_tile "dt" dt)
(action_tile "cc" "(setq cc $value) (KIEM_TRA_LOI)")
(action_tile "cr" "(setq cr $value) (KIEM_TRA_LOI)")
(action_tile "cd" "(setq cd $value) (KIEM_TRA_LOI)")
(action_tile "dt" "(setq dt $value) (KIEM_TRA_LOI)")
(action_tile "ve" "(done_dialog 1)")
(action_tile "thoat" "(done_dialog 14)")
(setq phepchon(start_dialog))
(cond
((= phepchon 1) (vehoga))
((= phepchon 14) (thoi))
)
(unload_dialog DCL_ID)
(princ))
(defun KIEM_TRA_LOI ()
(set_tile "error" "")
(if
(/= (type (distof cc)) 'real)
(progn
(set_tile "error" "Nhap lai chieu cao!")
(mode_tile "cc" 2)))
(if
(/= (type (distof cr)) 'real)
(progn
(set_tile "error" "Nhap lai chieu rong!")
(mode_tile "cr" 2)))
(if
(/= (type (distof cd)) 'real)
(progn
(set_tile "error" "Nhap lai chieu dai!")
(mode_tile "cd" 2)))
(if
(/= (type (distof dt)) 'real)
(progn
(set_tile "error" "Nhap lai day thanh!")
(mode_tile "dt" 2)))
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề [nhờ chỉnh sửa] lisp vẽ pline. Xem đúng bài viết #225829 để đọc hướng dẫn và trao đổi thêm.