Lisp lệnh LP trong chủ đề “[Hỏi] Hàm polar”
Em đã sửa lại như sau, giờ lisp đã chạy OK, nhưng có vẻ vẫn cần phải gọt giũa tiếp (em chưa làm phần kiểm tra 2 điểm pt1 và pt2 có trùng nhau hay không:D).
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 147043_lp.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 LP để chạy lisp.
Mã nguồn 147043_lp.lsp (trích từ bài viết gốc)
;;; Create 3 lines, that lie on a line, and on different layers
;;; written by pdle
(defun C:lp (/ pt1 pt2 X1 Y1 Z1 X2 Y2 Z2 u tmp1 tmp2)
(setq pt1 (getpoint "\nSpecify the first point: ")
pt2 (getpoint "\nSpecify the second point: ")
)
(ImportData)
(setq
X1 (nth 0 pt1)
Y1 (nth 1 pt1)
Z1 (nth 2 pt1)
X2 (nth 0 pt2)
Y2 (nth 1 pt2)
Z2 (nth 2 pt2)
u (distance pt1 pt2)
tmp1 (list (+ X1 (* (/ a u) (- X2 X1))) (+ Y1 (* (/ a u) (- Y2 Y1))) (+ Z1 (* (/ a u) (- Z2 Z1))))
tmp2 (list (+ X2 (* (/ a u) (- X1 X2))) (+ Y2 (* (/ a u) (- Y1 Y2))) (+ Z2 (* (/ a u) (- Z1 Z2))))
);;; Calculate the points' coordinates
(Line pt1 tmp1 lay1);;; Create the first line
(Line pt2 tmp2 lay1);;; Create the third line
(Line tmp1 tmp2 lay2);;; Create the second line
)
(defun Line (1st 2nd Lay)
(entmakex (list (cons 0 "LINE") (cons 10 1st ) (cons 11 2nd ) (cons 8 Lay)))
);;; Create a line from by 2 points and it's on a defined layer
(defun ImportData (/ OK lay1pre lay2pre apre amax amin )
(setq OK nil)(if (= lay1 nil) (setq lay1pre "0") (setq lay1pre lay1))
(while (not OK )
(setq lay1 (getstring (strcat "\nSpecify the layer of the 1st and 3rd <" lay1pre ">: ")) )
(if (= lay1 "") (setq lay1 lay1pre))
(if (not (tblsearch "layer" lay1))
(progn
(setq ask (getstring (strcat "The layer " lay1 " does not exist. Do you want to create this layer ? (Y/N) : ")))
(if (= (strcase ask) "Y")
(progn (command "-layer" "new" lay1 "") (setq OK T))
)
)
(setq OK T)
)
);;; The part of importing the layer of the 1st and 3rd lines
(setq OK nil)(if (= lay2 nil) (setq lay2pre "0") (setq lay2pre lay2))
(while (not OK )
(setq lay2 (getstring (strcat "\nSpecify the layer of the 2nd <" lay2pre ">: ")) )
(if (= lay2 "") (setq lay2 lay2pre))
(if (not (tblsearch "layer" lay2))
(progn
(setq ask (getstring (strcat "The layer " lay2 " does not exist. Do you want to create this layer ? (Y/N): ")))
(if (= (strcase ask) "Y")
(progn (command "-layer" "new" lay2 "") (setq OK T))
)
)
(setq OK T)
)
);;; The part of importing the layer of the 2nd line
(setq
OK nil
amax (* 0.5 (distance pt1 pt2))
amin 0.001
)
(if (= a nil) (setq apre 0.338) (setq apre a))
(while (not OK )
(setq a (getreal (strcat "\nThe length of the 1st and 3rd <" (rtos apre) ">: ")) )
(if (= a nil) (setq a apre))
(if (or (>= (* 2 a) (distance pt1 pt2)) (>= 0 a) )
(setq ask (getstring "\n amax= " (rtos amax) " amin= " (rtos amin))) (setq OK T)
)
);;; The part of importing the length of the 1st and 3rd lines
);;; Import the layers and the lengthThảo luận gốc
Lisp được chia sẻ trong chủ đề [Hỏi] Hàm polar. Xem đúng bài viết #147043 để đọc hướng dẫn và trao đổi thêm.