Lisp thao tác trong 3D
@ Tue_NV:
Nghe lời "xúi dại" của bác, em làm công cụ thay cho 3dalign ^^
Quả thật 2d thì còn dễ ngốn chứ quả 3d này đã làm em mất ngày chủ nhật đó :D :D :D
Tạm xong, em đưa lên đây xin đá ^^ :D :D :D
Đến khi ổn thì em cho vào code !
p/s:
1) Hạn chế của nó là "em đã phát hiện có sai số trong các phép toán của lisp"
Tuy ko lớn >>> nhưng chỉ sợ nếu ứng dụng vào bài toán của haanh thì ko sao mà dùng trong các trường hợp khác để xđịnh giao cắt ... thì có thể "dính đòn"
Mong đc chỉ giáo thêm !
2) Đang để dạng thủ tục để các bác dễ đường test !
3) Chưa xét đến tỉ lệ scale
;lisp thay the lenh 3dalign tuy chon "Copy"
;pt_a, pt_b, pt_c la 3 diem chuan
;pt_1, pt_2, pt_3 la 3 diem dich
; ss co the la 1 ename hoac mot tap chon ss
;ti le (length pt_1 pt_2) / (length pt_a pt_b) la ti le scale
(defun c:3DDD(/ )
;ss pt_a pt_b pt_c pt_1 pt_2 pt_3
;lst_var old lst_point_w moc new pre pt_phu pt_phu_w base ang anh pt_phu_2d pt_phu_3d pt_phu_w_3d
(setq pt_a (getpoint "\nchon a:")
pt_b (getpoint "\nchon b:")
pt_c (getpoint "\nchon c:")
pt_1 (getpoint "\nchon d:")
pt_2 (getpoint "\nchon e:")
pt_3 (getpoint "\nchon f:")
ss (car(entsel "\nChon vat: ")))
(setq lst_va '("osmode" "cmdecho" "AUNITS" "ANGDIR"))
(setq old (mapcar 'getvar lst_va))
(mapcar 'setvar lst_va '(0 0 3 0))
(setq lst_point_w (mapcar '(lambda (x) (trans x 1 0)) (list pt_a pt_b pt_c pt_1 pt_2 pt_3)))
(command "ucs" "na" "s" "save_ucs")
(command "-view" "s" "save_v")
(setq moc (entlast)
new (ssadd))
(command "_.copy" ss "" pt_a pt_1)
(while (setq pre (entnext moc))
(setq new (ssadd pre new)
moc pre)
) ;while
(setq pt_phu (mapcar '+ pt_1 (mapcar '- pt_b pt_a))
pt_phu_w (trans pt_phu 1 0))
(command "ucs" "3p" pt_1 pt_2 pt_phu)
(command "plan" "c")
(command "rotate" new ""
(setq base (trans (nth 3 lst_point_w) 0 1))
(setq ang (* -1 (angle base (trans pt_phu_w 0 1))))
)
(setq pt_phu_2d
(polar
base
(+ ang (angle base (setq anh (mapcar '+ base (mapcar '- (trans (nth 2 lst_point_w) 0 1) (trans (nth 0 lst_point_w) 0 1))))))
(distance (list (car base) (cadr base)) (list (car anh) (cadr anh))))
pt_phu_3d (list (car pt_phu_2d) (cadr pt_phu_2d) (last anh))
pt_phu_w_3d (trans pt_phu_3d 1 0))
(command "ucs" "3p" base (trans (nth 5 lst_point_w) 0 1) pt_phu_3d)
(command "plan" "c")
(command "rotate" new ""
(setq base (trans (nth 3 lst_point_w) 0 1))
(* -1 (angle base (trans pt_phu_w_3d 0 1)))
)
(command "ucs" "na" "r" "save_ucs")
(command "ucs" "na" "d" "save_ucs")
(command "-view" "r" "save_v")
(command "-view" "d" "save_v")
(mapcar 'setvar lst_va old)
)
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 312714_3ddd.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 3DDD để chạy lisp.
Mã nguồn 312714_3ddd.lsp (trích từ bài viết gốc)
;lisp thay the lenh 3dalign tuy chon "Copy"
;pt_a, pt_b, pt_c la 3 diem chuan
;pt_1, pt_2, pt_3 la 3 diem dich
; ss co the la 1 ename hoac mot tap chon ss
;ti le (length pt_1 pt_2) / (length pt_a pt_b) la ti le scale
(defun c:3DDD(/ )
;ss pt_a pt_b pt_c pt_1 pt_2 pt_3
;lst_var old lst_point_w moc new pre pt_phu pt_phu_w base ang anh pt_phu_2d pt_phu_3d pt_phu_w_3d
(setq pt_a (getpoint "\nchon a:")
pt_b (getpoint "\nchon b:")
pt_c (getpoint "\nchon c:")
pt_1 (getpoint "\nchon d:")
pt_2 (getpoint "\nchon e:")
pt_3 (getpoint "\nchon f:")
ss (car(entsel "\nChon vat: ")))
(setq lst_va '("osmode" "cmdecho" "AUNITS" "ANGDIR"))
(setq old (mapcar 'getvar lst_va))
(mapcar 'setvar lst_va '(0 0 3 0))
(setq lst_point_w (mapcar '(lambda (x) (trans x 1 0)) (list pt_a pt_b pt_c pt_1 pt_2 pt_3)))
(command "ucs" "na" "s" "save_ucs")
(command "-view" "s" "save_v")
(setq moc (entlast)
new (ssadd))
(command "_.copy" ss "" pt_a pt_1)
(while (setq pre (entnext moc))
(setq new (ssadd pre new)
moc pre)
) ;while
(setq pt_phu (mapcar '+ pt_1 (mapcar '- pt_b pt_a))
pt_phu_w (trans pt_phu 1 0))
(command "ucs" "3p" pt_1 pt_2 pt_phu)
(command "plan" "c")
(command "rotate" new ""
(setq base (trans (nth 3 lst_point_w) 0 1))
(setq ang (* -1 (angle base (trans pt_phu_w 0 1))))
)
(setq pt_phu_2d
(polar
base
(+ ang (angle base (setq anh (mapcar '+ base (mapcar '- (trans (nth 2 lst_point_w) 0 1) (trans (nth 0 lst_point_w) 0 1))))))
(distance (list (car base) (cadr base)) (list (car anh) (cadr anh))))
pt_phu_3d (list (car pt_phu_2d) (cadr pt_phu_2d) (last anh))
pt_phu_w_3d (trans pt_phu_3d 1 0))
(command "ucs" "3p" base (trans (nth 5 lst_point_w) 0 1) pt_phu_3d)
(command "plan" "c")
(command "rotate" new ""
(setq base (trans (nth 3 lst_point_w) 0 1))
(* -1 (angle base (trans pt_phu_w_3d 0 1)))
)
(command "ucs" "na" "r" "save_ucs")
(command "ucs" "na" "d" "save_ucs")
(command "-view" "r" "save_v")
(command "-view" "d" "save_v")
(mapcar 'setvar lst_va old)
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề [Hỏi] Lisp thao tác trong 3D. Xem đúng bài viết #312714 để đọc hướng dẫn và trao đổi thêm.