Lisp thao tác trong 3D
Chắc là haanh đã thử lisp trong bài này:
@ 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 !
.............................
Lỗi tại ko đọc kĩ hdsd trước khi dùng ^^
Giờ thì có cái để thử rồi đây !
Hơi dài, do chưa tìm đc cách rút ngắn code
Mèo đen, mèo trắng miễn là bắt đc chuột :D :D :D
p/s: Lệnh là VE nghe haanh ^^
;lisp ve duong ong 3d
(defun c:VE(/ lst_va old D ss lst_TC_DUC cao_tam_cut R path cut base_w lst_ver lst_w obj i ss_ong ss_cut n len dau cuoi)
(setq lst_va '("osmode" "cmdecho"))
(setq old (mapcar 'getvar lst_va))
(mapcar 'setvar lst_va '(0 0))
;=================
(setq D (getdist "\nNhap duong kinh ong: ")
lst_TC_DUC '((12 . 26.0) (13 . 26.0) (18 . 35.0) (19 . 35.0) (22 . 40.0) (23 . 40.0) (28 .
50.0) (29 . 50.0) (35 . 55.0) (34 . 55.0) (40 . 60.0) (52 . 70.0) (53 . 70.0)
(70 . 80.0) (69 . 80.0) (85 . 90.0) (84 . 90.0) (104 . 100.0) (129 . 187.5)
(154 . 225.0) (204 . 300.0) (254 . 375.0))
cao_tam_cut (cdr (assoc D lst_TC_DUC))
) ;setq
;=================
(prompt "\nChon 3DPOLY: ")
(setq ss (ssget "+.:E:S" '((0 . "POLYLINE"))))
(if (and
D
(member D (mapcar 'car lst_TC_DUC))
ss)
(progn
(or #lan_ve (setq #lan_ve 0))
(setq #lan_ve (1+ #lan_ve))
;ve cut mau:
(command "arc" "c" '(0 0 0) (list cao_tam_cut 0 0) (list 0 cao_tam_cut 0))
(setq path (entlast))
(command "circle" '(0 0 0) (setq R (/ D 2.0)))
(command "sweep" (entlast) "" path)
(setq cut (entlast))
(setq base_w (mapcar '(lambda (x) (trans x 1 0)) (list (list cao_tam_cut 0 0) (list cao_tam_cut cao_tam_cut 0) (list 0 cao_tam_cut 0))))
;== xong cut mau ==
;Luu UCS:
(command "ucs" "na" "s" "save1_ucs")
;(command "-view" "s" "save_v")
;*******************************
(setq lst_ver (acet-geom-vertex-list (setq ename (ssname ss 0)))
lst_w (mapcar '(lambda (x) (trans x 1 0)) lst_ver)
obj (vlax-ename->vla-object ename))
(setq i 0
ss_ong (ssadd)
ss_cut (ssadd)
)
(repeat (setq n (1- (length lst_w)))
(setq len (distance (setq dau (nth i lst_w)) (setq cuoi (nth (1+ i) lst_w))))
(command "UCS" "za" (trans dau 0 1) (trans cuoi 0 1))
(cond
((= i 0) (command "CYLINDER" (trans dau 0 1) R (- len cao_tam_cut)) ;ve ong
(setq ss_ong (ssadd (entlast) ss_ong))
(3DDD cut
(trans (car base_w) 0 1)
(trans (cadr base_w) 0 1)
(trans (last base_w) 0 1)
(trans (vlax-curve-getPointAtDist obj (- (vlax-curve-getDistAtParam obj 1) cao_tam_cut)) 0 1)
(trans (vlax-curve-getPointAtParam obj 1) 0 1)
(trans (vlax-curve-getPointAtDist obj (+ (vlax-curve-getDistAtParam obj 1) cao_tam_cut)) 0 1)) ;align_copy cut
(setq ss_cut (ssadd (entlast) ss_cut))
)
((= i (1- n)) (command "CYLINDER" (mapcar '+ (list 0 0 cao_tam_cut) (trans dau 0 1)) R (- len cao_tam_cut)) ;ve ong
(setq ss_ong (ssadd (entlast) ss_ong))
)
(t (command "CYLINDER" (mapcar '+ (list 0 0 cao_tam_cut) (trans dau 0 1)) R (- len (* 2 cao_tam_cut))) ;ve ong
(setq ss_ong (ssadd (entlast) ss_ong))
(3DDD cut
(trans (car base_w) 0 1)
(trans (cadr base_w) 0 1)
(trans (last base_w) 0 1)
(trans (vlax-curve-getPointAtDist obj (- (vlax-curve-getDistAtParam obj (1+ i)) cao_tam_cut)) 0 1)
(trans (vlax-curve-getPointAtParam obj (1+ i)) 0 1)
(trans (vlax-curve-getPointAtDist obj (+ (vlax-curve-getDistAtParam obj (1+ i)) cao_tam_cut)) 0 1)) ;align_copy cut
(setq ss_cut (ssadd (entlast) ss_cut))
)
)
(setq i (1+ i))
) ;repeat
;(command "-block" (strcat "Ong_" (rtos (getvar 'cdate) 2 4)) (trans (nth 0 lst_w) 0 1) ss_ong "")
;(command "-block" (strcat "Cut_" (rtos (getvar 'cdate) 2 4)) (trans (nth 0 lst_w) 0 1) ss_cut "")
(command "group" "c" (strcat "Ong_" (rtos (getvar 'cdate) 2 0) (itoa #lan_ve)) "Group_ong" ss_ong "")
(command "group" "c" (strcat "Cut_" (rtos (getvar 'cdate) 2 0) (itoa #lan_ve)) "Group_cut" ss_cut "")
;(mapcar 'entdel (list cut path)) ;Cai nay chay tren cad2014 thay co loi ko xoa path nen thay bang command
(command ".ERASE" cut "")
(command ".ERASE" path "")
(command "ucs" "na" "r" "save1_ucs")
(command "ucs" "na" "d" "save1_ucs")
;(command "-view" "r" "save_v")
;(command "-view" "d" "save_v")
(mapcar 'setvar lst_va old)
(princ)
)
(alert "***** Nhap du lieu chua dung ! *****")
)
)
(vl-load-com)
;*****************************************************************************************************************************
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;=============================================================================================================================
(defun 3DDD(ss pt_a pt_b pt_c pt_1 pt_2 pt_3 / lst_va old lst_point_w moc new pre
huong_12_xoy huong_13_xoy huong_ab_xoy huong_ac_xoy
huong_12_yoz huong_13_yoz huong_ab_yoz huong_ac_yoz
huong_12_xoz huong_13_xoz huong_ab_xoz huong_ac_xoz
pt_phu pt_phu_w pt_phu2 pt_phu2_w base truc truc_w ang anh anh_c anh_w pt_phu2_2d pt_phu2_w_3d pt_phu_2d pt_phu_3d pt_phu_w_3d)
;Ham 3dalign khong scale Voi 3 diem chon phai "bang nhau" ve kich thuoc hinh dang
(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
;======================================================================
;Kiem tra trung phuong, chieu
(command "ucs" "za" '(0 0 0) '(2.357 1.312 4.235))
(setq huong_12_xoy (angle (nth 3 lst_point_w) (nth 4 lst_point_w))
huong_13_xoy (angle (nth 3 lst_point_w) (nth 5 lst_point_w))
huong_ab_xoy (angle (nth 0 lst_point_w) (nth 1 lst_point_w))
huong_ac_xoy (angle (nth 0 lst_point_w) (nth 2 lst_point_w))
)
(command "ucs" "za" '(0 0 0) '(1 0 0))
(setq huong_12_yoz (angle (trans (nth 3 lst_point_w) 0 1) (trans (nth 4 lst_point_w) 0 1))
huong_13_yoz (angle (trans (nth 3 lst_point_w) 0 1) (trans (nth 5 lst_point_w) 0 1))
huong_ab_yoz (angle (trans (nth 0 lst_point_w) 0 1) (trans (nth 1 lst_point_w) 0 1))
huong_ac_yoz (angle (trans (nth 0 lst_point_w) 0 1) (trans (nth 2 lst_point_w) 0 1))
)
(command "ucs" "za" '(0 0 0) '(1 0 0))
(setq huong_12_xoz (angle (trans (nth 3 lst_point_w) 0 1) (trans (nth 4 lst_point_w) 0 1))
huong_13_xoz (angle (trans (nth 3 lst_point_w) 0 1) (trans (nth 5 lst_point_w) 0 1))
huong_ab_xoz (angle (trans (nth 0 lst_point_w) 0 1) (trans (nth 1 lst_point_w) 0 1))
huong_ac_xoz (angle (trans (nth 0 lst_point_w) 0 1) (trans (nth 2 lst_point_w) 0 1))
)
(command "ucs" "na" "r" "save_ucs")
;=====================================================================
(cond
((and
(equal huong_12_xoy huong_ab_xoy 1e-5)
(equal huong_12_yoz huong_ab_yoz 1e-5)
(equal huong_12_xoz huong_ab_xoz 1e-5)
)
(cond
((and
(equal huong_13_xoy huong_ac_xoy 1e-5)
(equal huong_13_yoz huong_ac_yoz 1e-5)
(equal huong_13_xoz huong_ac_xoz 1e-5)
)
(princ "\nAlign = Copy ! ")
(princ)
)
(t
(setq pt_phu (mapcar '+ pt_1 (mapcar '- pt_c pt_a))
pt_phu_w (trans pt_phu 1 0))
(command "ucs" "za" pt_1 pt_2)
(command "rotate" new ""
(setq base (trans (nth 3 lst_point_w) 0 1))
(- (angle base (trans (nth 5 lst_point_w) 0 1)) (angle base (trans pt_phu_w 0 1)))
)
)
)
)
;========================================================
((and
(or (equal (+ huong_12_xoy pi) huong_ab_xoy 1e-5) (equal (- huong_12_xoy pi) huong_ab_xoy 1e-5))
(or (equal (+ huong_12_yoz pi) huong_ab_yoz 1e-5) (equal (- huong_12_yoz pi) huong_ab_yoz 1e-5))
(or (equal (+ huong_12_xoz pi) huong_ab_xoz 1e-5) (equal (- huong_12_xoz pi) huong_ab_xoz 1e-5))
)
(setq truc (mapcar '+ pt_1 (mapcar '- pt_c pt_a))
truc_w (trans truc 1 0))
(setq anh (mapcar '+ pt_1 (mapcar '- pt_b pt_a))
anh_w (trans anh 1 0))
(command "ucs" "za" pt_1 truc)
(command "rotate" new "" (setq base (trans (nth 3 lst_point_w) 0 1)) pi)
(setq pt_phu2_2d
(polar
base
(+ pi (angle base (setq anh_c (trans anh_w 0 1))))
(distance base (list (car anh_c) (cadr anh_c)))
)
pt_phu2_w_3d (trans (list (car pt_phu2_2d) (cadr pt_phu2_2d) (last anh_c)) 1 0)
)
(cond
((and
(equal huong_13_xoy huong_ac_xoy 1e-5)
(equal huong_13_yoz huong_ac_yoz 1e-5)
(equal huong_13_xoz huong_ac_xoz 1e-5)
)
(princ)
)
((and
(or (equal (+ huong_13_xoy pi) huong_ac_xoy 1e-5) (equal (- huong_13_xoy pi) huong_ac_xoy 1e-5))
(or (equal (+ huong_13_yoz pi) huong_ac_yoz 1e-5) (equal (- huong_13_yoz pi) huong_ac_yoz 1e-5))
(or (equal (+ huong_13_xoz pi) huong_ac_xoz 1e-5) (equal (- huong_13_xoz pi) huong_ac_xoz 1e-5))
)
(command "ucs" "za" base (mapcar '(lambda (x) (* 0.5 x)) (mapcar '+ (trans pt_phu2_w_3d 0 1) (trans (nth 4 lst_point_w) 0 1))))
(command "rotate" new "" (trans (nth 3 lst_point_w) 0 1) pi)
)
(t
(command "ucs" "3p" base (trans (nth 5 lst_point_w) 0 1) (trans truc_w 0 1))
(command "rotate" new ""
(setq base (trans (nth 3 lst_point_w) 0 1))
(* -1 (angle base (trans truc_w 0 1)))
)
)
)
)
;==================================================================
(t
(cond
((and
(equal huong_13_xoy huong_ac_xoy 1e-5)
(equal huong_13_yoz huong_ac_yoz 1e-5)
(equal huong_13_xoz huong_ac_xoz 1e-5)
)
(setq pt_phu (mapcar '+ pt_1 (mapcar '- pt_b pt_a))
pt_phu_w (trans pt_phu 1 0))
(command "ucs" "za" pt_1 pt_3)
(command "rotate" new ""
(setq base (trans (nth 3 lst_point_w) 0 1))
(- (angle base (trans (nth 4 lst_point_w) 0 1)) (angle base (trans pt_phu_w 0 1)))
)
)
((and
(or (equal (+ huong_13_xoy pi) huong_ac_xoy 1e-5) (equal (- huong_13_xoy pi) huong_ac_xoy 1e-5))
(or (equal (+ huong_13_yoz pi) huong_ac_yoz 1e-5) (equal (- huong_13_yoz pi) huong_ac_yoz 1e-5))
(or (equal (+ huong_13_xoz pi) huong_ac_xoz 1e-5) (equal (- huong_13_xoz pi) huong_ac_xoz 1e-5))
)
(setq truc (mapcar '+ pt_1 (mapcar '- pt_b pt_a))
truc_w (trans truc 1 0))
(setq anh (mapcar '+ pt_1 (mapcar '- pt_c pt_a))
anh_w (trans anh 1 0))
(command "ucs" "za" pt_1 truc)
(command "rotate" new "" (setq base (trans (nth 3 lst_point_w) 0 1)) pi)
(command "ucs" "3p" base (trans (nth 4 lst_point_w) 0 1) (trans truc_w 0 1))
(command "rotate" new ""
(setq base (trans (nth 3 lst_point_w) 0 1))
(* -1 (angle base (trans truc_w 0 1)))
)
)
(t
(setq pt_phu (mapcar '+ pt_1 (mapcar '- pt_b pt_a))
pt_phu_w (trans pt_phu 1 0)
pt_phu2 (mapcar '+ pt_1 (mapcar '- pt_c pt_a))
pt_phu2_w (trans pt_phu2 1 0))
(command "ucs" "3p" pt_1 pt_2 pt_phu)
(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_c (trans pt_phu2_w 0 1))))
(distance (list (car base) (cadr base)) (list (car anh_c) (cadr anh_c))))
pt_phu_3d (list (car pt_phu_2d) (cadr pt_phu_2d) (last anh_c))
pt_phu_w_3d (trans pt_phu_3d 1 0))
(command "ucs" "za" (trans (nth 3 lst_point_w) 0 1) (trans (nth 4 lst_point_w) 0 1))
(command "rotate" new ""
(setq base (trans (nth 3 lst_point_w) 0 1))
(- (angle base (trans (nth 5 lst_point_w) 0 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)
(princ)
)
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 313604_ve.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 VE để chạy lisp.
Mã nguồn 313604_ve.lsp (trích từ bài viết gốc)
;lisp ve duong ong 3d
(defun c:VE(/ lst_va old D ss lst_TC_DUC cao_tam_cut R path cut base_w lst_ver lst_w obj i ss_ong ss_cut n len dau cuoi)
(setq lst_va '("osmode" "cmdecho"))
(setq old (mapcar 'getvar lst_va))
(mapcar 'setvar lst_va '(0 0))
;=================
(setq D (getdist "\nNhap duong kinh ong: ")
lst_TC_DUC '((12 . 26.0) (13 . 26.0) (18 . 35.0) (19 . 35.0) (22 . 40.0) (23 . 40.0) (28 .
50.0) (29 . 50.0) (35 . 55.0) (34 . 55.0) (40 . 60.0) (52 . 70.0) (53 . 70.0)
(70 . 80.0) (69 . 80.0) (85 . 90.0) (84 . 90.0) (104 . 100.0) (129 . 187.5)
(154 . 225.0) (204 . 300.0) (254 . 375.0))
cao_tam_cut (cdr (assoc D lst_TC_DUC))
) ;setq
;=================
(prompt "\nChon 3DPOLY: ")
(setq ss (ssget "+.:E:S" '((0 . "POLYLINE"))))
(if (and
D
(member D (mapcar 'car lst_TC_DUC))
ss)
(progn
(or #lan_ve (setq #lan_ve 0))
(setq #lan_ve (1+ #lan_ve))
;ve cut mau:
(command "arc" "c" '(0 0 0) (list cao_tam_cut 0 0) (list 0 cao_tam_cut 0))
(setq path (entlast))
(command "circle" '(0 0 0) (setq R (/ D 2.0)))
(command "sweep" (entlast) "" path)
(setq cut (entlast))
(setq base_w (mapcar '(lambda (x) (trans x 1 0)) (list (list cao_tam_cut 0 0) (list cao_tam_cut cao_tam_cut 0) (list 0 cao_tam_cut 0))))
;== xong cut mau ==
;Luu UCS:
(command "ucs" "na" "s" "save1_ucs")
;(command "-view" "s" "save_v")
;*******************************
(setq lst_ver (acet-geom-vertex-list (setq ename (ssname ss 0)))
lst_w (mapcar '(lambda (x) (trans x 1 0)) lst_ver)
obj (vlax-ename->vla-object ename))
(setq i 0
ss_ong (ssadd)
ss_cut (ssadd)
)
(repeat (setq n (1- (length lst_w)))
(setq len (distance (setq dau (nth i lst_w)) (setq cuoi (nth (1+ i) lst_w))))
(command "UCS" "za" (trans dau 0 1) (trans cuoi 0 1))
(cond
((= i 0) (command "CYLINDER" (trans dau 0 1) R (- len cao_tam_cut)) ;ve ong
(setq ss_ong (ssadd (entlast) ss_ong))
(3DDD cut
(trans (car base_w) 0 1)
(trans (cadr base_w) 0 1)
(trans (last base_w) 0 1)
(trans (vlax-curve-getPointAtDist obj (- (vlax-curve-getDistAtParam obj 1) cao_tam_cut)) 0 1)
(trans (vlax-curve-getPointAtParam obj 1) 0 1)
(trans (vlax-curve-getPointAtDist obj (+ (vlax-curve-getDistAtParam obj 1) cao_tam_cut)) 0 1)) ;align_copy cut
(setq ss_cut (ssadd (entlast) ss_cut))
)
((= i (1- n)) (command "CYLINDER" (mapcar '+ (list 0 0 cao_tam_cut) (trans dau 0 1)) R (- len cao_tam_cut)) ;ve ong
(setq ss_ong (ssadd (entlast) ss_ong))
)
(t (command "CYLINDER" (mapcar '+ (list 0 0 cao_tam_cut) (trans dau 0 1)) R (- len (* 2 cao_tam_cut))) ;ve ong
(setq ss_ong (ssadd (entlast) ss_ong))
(3DDD cut
(trans (car base_w) 0 1)
(trans (cadr base_w) 0 1)
(trans (last base_w) 0 1)
(trans (vlax-curve-getPointAtDist obj (- (vlax-curve-getDistAtParam obj (1+ i)) cao_tam_cut)) 0 1)
(trans (vlax-curve-getPointAtParam obj (1+ i)) 0 1)
(trans (vlax-curve-getPointAtDist obj (+ (vlax-curve-getDistAtParam obj (1+ i)) cao_tam_cut)) 0 1)) ;align_copy cut
(setq ss_cut (ssadd (entlast) ss_cut))
)
)
(setq i (1+ i))
) ;repeat
;(command "-block" (strcat "Ong_" (rtos (getvar 'cdate) 2 4)) (trans (nth 0 lst_w) 0 1) ss_ong "")
;(command "-block" (strcat "Cut_" (rtos (getvar 'cdate) 2 4)) (trans (nth 0 lst_w) 0 1) ss_cut "")
(command "group" "c" (strcat "Ong_" (rtos (getvar 'cdate) 2 0) (itoa #lan_ve)) "Group_ong" ss_ong "")
(command "group" "c" (strcat "Cut_" (rtos (getvar 'cdate) 2 0) (itoa #lan_ve)) "Group_cut" ss_cut "")
;(mapcar 'entdel (list cut path)) ;Cai nay chay tren cad2014 thay co loi ko xoa path nen thay bang command
(command ".ERASE" cut "")
(command ".ERASE" path "")
(command "ucs" "na" "r" "save1_ucs")
(command "ucs" "na" "d" "save1_ucs")
;(command "-view" "r" "save_v")
;(command "-view" "d" "save_v")
)
(alert "***** Nhap du lieu chua dung ! *****")
)
(mapcar 'setvar lst_va old)
(princ)
)
(vl-load-com)
;*****************************************************************************************************************************
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;=============================================================================================================================
(defun 3DDD(ss pt_a pt_b pt_c pt_1 pt_2 pt_3 / lst_va old lst_point_w moc new pre
huong_12_xoy huong_13_xoy huong_ab_xoy huong_ac_xoy
huong_12_yoz huong_13_yoz huong_ab_yoz huong_ac_yoz
huong_12_xoz huong_13_xoz huong_ab_xoz huong_ac_xoz
pt_phu pt_phu_w pt_phu2 pt_phu2_w base truc truc_w ang anh anh_c anh_w pt_phu2_2d pt_phu2_w_3d pt_phu_2d pt_phu_3d pt_phu_w_3d)
;Ham 3dalign khong scale Voi 3 diem chon phai "bang nhau" ve kich thuoc hinh dang
(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
;======================================================================
;Kiem tra trung phuong, chieu
(command "ucs" "za" '(0 0 0) '(2.357 1.312 4.235))
(setq huong_12_xoy (angle (nth 3 lst_point_w) (nth 4 lst_point_w))
huong_13_xoy (angle (nth 3 lst_point_w) (nth 5 lst_point_w))
huong_ab_xoy (angle (nth 0 lst_point_w) (nth 1 lst_point_w))
huong_ac_xoy (angle (nth 0 lst_point_w) (nth 2 lst_point_w))
)
(command "ucs" "za" '(0 0 0) '(1 0 0))
(setq huong_12_yoz (angle (trans (nth 3 lst_point_w) 0 1) (trans (nth 4 lst_point_w) 0 1))
huong_13_yoz (angle (trans (nth 3 lst_point_w) 0 1) (trans (nth 5 lst_point_w) 0 1))
huong_ab_yoz (angle (trans (nth 0 lst_point_w) 0 1) (trans (nth 1 lst_point_w) 0 1))
huong_ac_yoz (angle (trans (nth 0 lst_point_w) 0 1) (trans (nth 2 lst_point_w) 0 1))
)
(command "ucs" "za" '(0 0 0) '(1 0 0))
(setq huong_12_xoz (angle (trans (nth 3 lst_point_w) 0 1) (trans (nth 4 lst_point_w) 0 1))
huong_13_xoz (angle (trans (nth 3 lst_point_w) 0 1) (trans (nth 5 lst_point_w) 0 1))
huong_ab_xoz (angle (trans (nth 0 lst_point_w) 0 1) (trans (nth 1 lst_point_w) 0 1))
huong_ac_xoz (angle (trans (nth 0 lst_point_w) 0 1) (trans (nth 2 lst_point_w) 0 1))
)
(command "ucs" "na" "r" "save_ucs")
;=====================================================================
(cond
((and
(equal huong_12_xoy huong_ab_xoy 1e-5)
(equal huong_12_yoz huong_ab_yoz 1e-5)
(equal huong_12_xoz huong_ab_xoz 1e-5)
)
(cond
((and
(equal huong_13_xoy huong_ac_xoy 1e-5)
(equal huong_13_yoz huong_ac_yoz 1e-5)
(equal huong_13_xoz huong_ac_xoz 1e-5)
)
(princ "\nAlign = Copy ! ")
(princ)
)
(t
(setq pt_phu (mapcar '+ pt_1 (mapcar '- pt_c pt_a))
pt_phu_w (trans pt_phu 1 0))
(command "ucs" "za" pt_1 pt_2)
(command "rotate" new ""
(setq base (trans (nth 3 lst_point_w) 0 1))
(- (angle base (trans (nth 5 lst_point_w) 0 1)) (angle base (trans pt_phu_w 0 1)))
)
)
)
)
;========================================================
((and
(or (equal (+ huong_12_xoy pi) huong_ab_xoy 1e-5) (equal (- huong_12_xoy pi) huong_ab_xoy 1e-5))
(or (equal (+ huong_12_yoz pi) huong_ab_yoz 1e-5) (equal (- huong_12_yoz pi) huong_ab_yoz 1e-5))
(or (equal (+ huong_12_xoz pi) huong_ab_xoz 1e-5) (equal (- huong_12_xoz pi) huong_ab_xoz 1e-5))
)
(setq truc (mapcar '+ pt_1 (mapcar '- pt_c pt_a))
truc_w (trans truc 1 0))
(setq anh (mapcar '+ pt_1 (mapcar '- pt_b pt_a))
anh_w (trans anh 1 0))
(command "ucs" "za" pt_1 truc)
(command "rotate" new "" (setq base (trans (nth 3 lst_point_w) 0 1)) pi)
(setq pt_phu2_2d
(polar
base
(+ pi (angle base (setq anh_c (trans anh_w 0 1))))
(distance base (list (car anh_c) (cadr anh_c)))
)
pt_phu2_w_3d (trans (list (car pt_phu2_2d) (cadr pt_phu2_2d) (last anh_c)) 1 0)
)
(cond
((and
(equal huong_13_xoy huong_ac_xoy 1e-5)
(equal huong_13_yoz huong_ac_yoz 1e-5)
(equal huong_13_xoz huong_ac_xoz 1e-5)
)
(princ)
)
((and
(or (equal (+ huong_13_xoy pi) huong_ac_xoy 1e-5) (equal (- huong_13_xoy pi) huong_ac_xoy 1e-5))
(or (equal (+ huong_13_yoz pi) huong_ac_yoz 1e-5) (equal (- huong_13_yoz pi) huong_ac_yoz 1e-5))
(or (equal (+ huong_13_xoz pi) huong_ac_xoz 1e-5) (equal (- huong_13_xoz pi) huong_ac_xoz 1e-5))
)
(command "ucs" "za" base (mapcar '(lambda (x) (* 0.5 x)) (mapcar '+ (trans pt_phu2_w_3d 0 1) (trans (nth 4 lst_point_w) 0 1))))
(command "rotate" new "" (trans (nth 3 lst_point_w) 0 1) pi)
)
(t
(command "ucs" "3p" base (trans (nth 5 lst_point_w) 0 1) (trans truc_w 0 1))
(command "rotate" new ""
(setq base (trans (nth 3 lst_point_w) 0 1))
(* -1 (angle base (trans truc_w 0 1)))
)
)
)
)
;==================================================================
(t
(cond
((and
(equal huong_13_xoy huong_ac_xoy 1e-5)
(equal huong_13_yoz huong_ac_yoz 1e-5)
(equal huong_13_xoz huong_ac_xoz 1e-5)
)
(setq pt_phu (mapcar '+ pt_1 (mapcar '- pt_b pt_a))
pt_phu_w (trans pt_phu 1 0))
(command "ucs" "za" pt_1 pt_3)
(command "rotate" new ""
(setq base (trans (nth 3 lst_point_w) 0 1))
(- (angle base (trans (nth 4 lst_point_w) 0 1)) (angle base (trans pt_phu_w 0 1)))
)
)
((and
(or (equal (+ huong_13_xoy pi) huong_ac_xoy 1e-5) (equal (- huong_13_xoy pi) huong_ac_xoy 1e-5))
(or (equal (+ huong_13_yoz pi) huong_ac_yoz 1e-5) (equal (- huong_13_yoz pi) huong_ac_yoz 1e-5))
(or (equal (+ huong_13_xoz pi) huong_ac_xoz 1e-5) (equal (- huong_13_xoz pi) huong_ac_xoz 1e-5))
)
(setq truc (mapcar '+ pt_1 (mapcar '- pt_b pt_a))
truc_w (trans truc 1 0))
(setq anh (mapcar '+ pt_1 (mapcar '- pt_c pt_a))
anh_w (trans anh 1 0))
(command "ucs" "za" pt_1 truc)
(command "rotate" new "" (setq base (trans (nth 3 lst_point_w) 0 1)) pi)
(command "ucs" "3p" base (trans (nth 4 lst_point_w) 0 1) (trans truc_w 0 1))
(command "rotate" new ""
(setq base (trans (nth 3 lst_point_w) 0 1))
(* -1 (angle base (trans truc_w 0 1)))
)
)
(t
(setq pt_phu (mapcar '+ pt_1 (mapcar '- pt_b pt_a))
pt_phu_w (trans pt_phu 1 0)
pt_phu2 (mapcar '+ pt_1 (mapcar '- pt_c pt_a))
pt_phu2_w (trans pt_phu2 1 0))
(command "ucs" "3p" pt_1 pt_2 pt_phu)
(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_c (trans pt_phu2_w 0 1))))
(distance (list (car base) (cadr base)) (list (car anh_c) (cadr anh_c))))
pt_phu_3d (list (car pt_phu_2d) (cadr pt_phu_2d) (last anh_c))
pt_phu_w_3d (trans pt_phu_3d 1 0))
(command "ucs" "za" (trans (nth 3 lst_point_w) 0 1) (trans (nth 4 lst_point_w) 0 1))
(command "rotate" new ""
(setq base (trans (nth 3 lst_point_w) 0 1))
(- (angle base (trans (nth 5 lst_point_w) 0 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)
(princ)
)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 #313604 để đọc hướng dẫn và trao đổi thêm.