Lisp lệnh VE trong chủ đề “LISP VẼ ĐƯỜNG ỐNG 3D trên AutoCAD”
Sửa lsp ve.lsp theo yêu cầu số 1 của haanh.
(defun c:VE(/ lst_va old D ss lst_TC_DUC cao_tam_cut net R path cut base_w lst_ver lst_w obj i ss_ong ss_cut n len dau cuoi)
;ham bay loi
(setq temperr *error*)
(defun errorTrap (msg)
(mapcar 'setvar lst_va old)
(cond
((tblsearch "ucs" "save_ucs")
(command "ucs" "na" "r" "save_ucs")
(command "ucs" "na" "d" "save_ucs")
)
)
(cond
((tblsearch "ucs" "save1_ucs")
(command "ucs" "na" "r" "save1_ucs")
(command "ucs" "na" "d" "save1_ucs")
)
)
(setq *error* temperr)
(princ "\n*** Da set lai bien, OK ! ***")
(princ)
)
(setq *error* errorTrap)
;======het ham bay loi = P1 ============================
(setq lst_va '("osmode" "cmdecho"))
(setq old (mapcar 'getvar lst_va))
(mapcar 'setvar lst_va '(0 0))
(command ".undo" "be")
;=================
(setq lst_TC_DUC '((12 . 26.0) (18 . 35.0) (22 . 40.0) (28 . 50.0) (35 . 55.0) (40 . 60.0) (52 . 70.0) (70 . 80.0)
(85 . 90.0) (104 . 100.0) (129 . 187.5) (154 . 225.0) (204 . 300.0) (254 . 375.0))
lst_fi_tcduc '((12 . "DN10") (18 . "DN15") (22 . "DN20") (28 . "DN25") (35 . "DN32") (40 . "DN40")
(52 . "DN50") (70 . "DN65") (85 . "DN80") (104 . "DN100") (129 . "DN125")
(154 . "DN150") (204 . "DN200") (254 . "DN250"))
D (getdist (strcat "\nNhap duong kinh ong <"
(apply 'strcat (mapcar '(lambda (x) (strcat (itoa (car x)) " ")) lst_TC_DUC)) ">:"))
Lay (cdr (assoc D lst_fi_tcduc))
cao_tam_cut (cdr (assoc D lst_TC_DUC))
)
;=================
(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:
(setq net (getvar "clayer"))
(if (tblsearch "layer" (strcat "Cut_" lay))
(setvar "clayer" (strcat "Cut_" lay))
(command "layer" "m" (strcat "Cut_" lay) "c" "t" "45,159,225" "" "")
) ;if
(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 ==
(if (tblsearch "layer" (strcat "Ong_" lay))
(setvar "clayer" (strcat "Ong_" lay))
(command "layer" "m" (strcat "Ong_" lay) "c" "t" "133,230,244" "" "")
) ;if
;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 ".ERASE" cut "")
(command ".ERASE" path "")
(command ".ERASE" ss "")
(command "ucs" "na" "r" "save1_ucs")
(command "ucs" "na" "d" "save1_ucs")
(setvar "clayer" net)
)
(alert "***** Nhap du lieu chua dung ! *****")
)
(command ".undo" "end")
(setq *error* temperr) ;tra ham erorr nguyen thuy
(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)
)
- Tải lisp
- 320927_ve.lsp
Cách dùng
- Tải tệp 320927_ve.lsp về máy.
- 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 320927_ve.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/112854-lisp-v%E1%BA%BD-%C4%91%C6%B0%E1%BB%9Dng-%E1%BB%91ng-3d-tr%C3%AAn-autocad/
(defun c:VE(/ lst_va old D ss lst_TC_DUC cao_tam_cut net R path cut base_w lst_ver lst_w obj i ss_ong ss_cut n len dau cuoi)
;ham bay loi
(setq temperr *error*)
(defun errorTrap (msg)
(mapcar 'setvar lst_va old)
(cond
((tblsearch "ucs" "save_ucs")
(command "ucs" "na" "r" "save_ucs")
(command "ucs" "na" "d" "save_ucs")
)
)
(cond
((tblsearch "ucs" "save1_ucs")
(command "ucs" "na" "r" "save1_ucs")
(command "ucs" "na" "d" "save1_ucs")
)
)
(setq *error* temperr)
(princ "\n*** Da set lai bien, OK ! ***")
(princ)
)
(setq *error* errorTrap)
;======het ham bay loi = P1 ============================
(setq lst_va '("osmode" "cmdecho"))
(setq old (mapcar 'getvar lst_va))
(mapcar 'setvar lst_va '(0 0))
(command ".undo" "be")
;=================
(setq lst_TC_DUC '((12 . 26.0) (18 . 35.0) (22 . 40.0) (28 . 50.0) (35 . 55.0) (40 . 60.0) (52 . 70.0) (70 . 80.0)
(85 . 90.0) (104 . 100.0) (129 . 187.5) (154 . 225.0) (204 . 300.0) (254 . 375.0))
lst_fi_tcduc '((12 . "DN10") (18 . "DN15") (22 . "DN20") (28 . "DN25") (35 . "DN32") (40 . "DN40")
(52 . "DN50") (70 . "DN65") (85 . "DN80") (104 . "DN100") (129 . "DN125")
(154 . "DN150") (204 . "DN200") (254 . "DN250"))
D (getdist (strcat "\nNhap duong kinh ong <"
(apply 'strcat (mapcar '(lambda (x) (strcat (itoa (car x)) " ")) lst_TC_DUC)) ">:"))
Lay (cdr (assoc D lst_fi_tcduc))
cao_tam_cut (cdr (assoc D lst_TC_DUC))
)
;=================
(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:
(setq net (getvar "clayer"))
(if (tblsearch "layer" (strcat "Cut_" lay))
(setvar "clayer" (strcat "Cut_" lay))
(command "layer" "m" (strcat "Cut_" lay) "c" "t" "45,159,225" "" "")
) ;if
(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 ==
(if (tblsearch "layer" (strcat "Ong_" lay))
(setvar "clayer" (strcat "Ong_" lay))
(command "layer" "m" (strcat "Ong_" lay) "c" "t" "133,230,244" "" "")
) ;if
;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 ".ERASE" cut "")
(command ".ERASE" path "")
(command ".ERASE" ss "")
(command "ucs" "na" "r" "save1_ucs")
(command "ucs" "na" "d" "save1_ucs")
(setvar "clayer" net)
)
(alert "***** Nhap du lieu chua dung ! *****")
)
(command ".undo" "end")
(setq *error* temperr) ;tra ham erorr nguyen thuy
(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ủ đề LISP VẼ ĐƯỜNG ỐNG 3D trên AutoCAD. Xem đúng bài viết #320927 để đọc hướng dẫn và trao đổi thêm.