Lisp lệnh C1 C2 C4 trong chủ đề “Ứng dụng LISP để vẽ bản vẽ kiến trúc (phần cơ bản)”
Nhanh quá! Cái lisp NN kia giúp tôi đỡ được bao nhiêu công khi phải BO line thanh PLINE.
Giờ đến vễ cửa, cửa đi, cửa sổ... nhiều quá. Copy từ thư viện ra thì lại phải SCALE rồi làng nhằng LAYER không đúng với bản vẽ của mình ! Vậy thì co cách nào không nhỉ?
Bài 5: Vẽ cửa đi
;------------------------------------------------------------------------------------- ;ve cua di 1 canh ;------------------------------------------------------------------------------------- (defun c:c1 (/ p1 p2 p3 p4 p5 daicua x y) (setq osm (getvar "osmode")) (setq p1 (getpoint "\nHay vao diem goc cua: ") p2 (getpoint p1 "\nHay vao diem mut cua: ") p3 (getpoint p1 "\nHay vao huong cua: ") daicua (distance p1 p2) x (car p1) y (car (cdr p1)) x 25 y daicua p4 (list x y) p5 (list daicua 0) ) (setvar "OSMODE" 0) (if (l3d_khongthanghang p1 p2 p3) (progn (command ".UCS" "3" p1 p2 p3) (command ".rectangle" "0,0" p4) (command ".Arc" p5 "C" "0,0" p4) (command ".UCS" "P") ) (princ "\n3 diem nhap vao khong duoc thang hang") ) (setvar "osmode" osm) ) ;------------------------------------------------------------------------------------- ;ve cua di 2 canh ;------------------------------------------------------------------------------------- (defun c:c2 (/ p1 p2 p3 p4 p5 daicua x y) (setq osm (getvar "osmode")) (setq p1 (getpoint "\nHay vao diem goc cua: ") p2 (getpoint p1 "\nHay vao diem mut cua: ") p3 (getpoint p1 "\nHay vao huong cua: ") daicua (/ (distance p1 p2) 2.0) x (car p1) y (car (cdr p1)) x 25 y daicua p4 (list x y) p5 (list daicua 0) ) (setvar "OSMODE" 0) (if (l3d_khongthanghang p1 p2 p3) (progn (command ".UCS" "3" p1 p2 p3) (command ".rectangle" "0,0" p4) (command ".Arc" p5 "C" "0,0" p4) (command ".UCS" "P") (command ".UCS" "3" p2 p1 p3) (command ".rectangle" "0,0" p4) (command ".Arc" p5 "C" "0,0" p4) (command ".UCS" "P") ) (princ "\n3 diem nhap vao khong duoc thang hang") ) (setvar "osmode" osm) ) ;------------------------------------------------------------------------------------- ;ve cua di 4 canh ;------------------------------------------------------------------------------------- (defun c:c4 (/ p1 p2 p3 p4 p5 daicua x y) (setq osm (getvar "osmode")) (setq p1 (getpoint "\nHay vao diem goc cua: ") p2 (getpoint p1 "\nHay vao diem mut cua: ") p3 (getpoint p1 "\nHay vao huong cua: ") daicua (/ (distance p1 p2) 4.0) x (car p1) y (car (cdr p1)) x 25 y daicua p4 (list x y) p5 (list daicua 0) ) (setvar "OSMODE" 0) (if (l3d_khongthanghang p1 p2 p3) (progn (setq diem1 (diemgiua p1 (diemgiua p1 p2))) (setq diem2 (diemgiua p1 p2)) (setq diem3 (diemgiua p2 (diemgiua p1 p2))) (command ".UCS" "3" p1 p2 p3) (command ".rectangle" "0,0" p4) (command ".Arc" p5 "C" "0,0" p4) (command ".UCS" "P") (command ".UCS" "3" diem1 p2 p3) (command ".rectangle" "0,0" p4) (command ".Arc" p5 "C" "0,0" p4) (command ".UCS" "P") (command ".UCS" "3" p2 p1 p3) (command ".rectangle" "0,0" p4) (command ".Arc" p5 "C" "0,0" p4) (command ".UCS" "P") (command ".UCS" "3" diem3 p1 p3) (command ".rectangle" "0,0" p4) (command ".Arc" p5 "C" "0,0" p4) (command ".UCS" "P") ) (princ "\n3 diem nhap vao khong duoc thang hang") ) (setvar "osmode" osm) ) ;-----------------------------------------------------------------------------
Có 3 lệnh trong lisp này.
c1: vẽ cửa đi 1 cánh
c2: vẽ cửa đi 2 cánh
c4: vẽ cửa đi 4 cánh
Thế còn cửa sổ thì sao nhỉ ?
Bài 6: Vẽ cửa sổ
(defun c:w1(/ data_m l1 l2 p1 p2 check) (defun wd_import(/ p3 p4 p5 p6) (setq data_m (ssget)) (setq p1 (getpoint "\nfirst point :") p2 (getpoint "\nsecond point :")) (setq l1 nil l2 nil check 1) (if (not (= nil data_m)) (progn (setq l1 (entget (ssname data_m 0))) (setq l2 (entget (ssname data_m 1))) (if (or (= nil l1) (not (= "LINE" (cdr (assoc 0 l1))))) (setq check 0)) (if (or (= nil l2) (not (= "LINE" (cdr (assoc 0 l2))))) (setq check 0)) (if (not (= 0 (-(sslength data_m) 2))) (setq check 0)) (if (= 1 check) (progn (setq p3 (cdr (assoc 10 l1))) (setq p3 (list (nth 0 p3) (nth 1 p3))) (setq p4 (cdr (assoc 11 l1))) (setq p4 (list (nth 0 p4) (nth 1 p4))) (setq p5 (cdr (assoc 10 l2))) (setq p5 (list (nth 0 p5) (nth 1 p5))) (setq p6 (cdr (assoc 11 l2))) (setq p6 (list (nth 0 p6) (nth 1 p6))) (if (not (= nil (inters p3 p4 p5 p6 nil))) (setq check 0)) )) ) (setq check 0)) (princ) ) (defun wd_procced() (defun mkv(/ p3 p4 p5 p6 p7 p8 p9 ls1 ls2 getom ll1) (setq p3 (cdr (assoc 10 l1))) (setq p4 (cdr (assoc 11 l1))) (setq p5 (cdr (assoc 10 l2))) (setq p6 (cdr (assoc 11 l2))) (if (> (abs (- (nth 1 p1) (nth 1 p3))) (abs (- (nth 1 p3) (nth 1 p4))) ) (setq check 0)) (if (> (abs (- (nth 1 p1) (nth 1 p4))) (abs (- (nth 1 p3) (nth 1 p4))) ) (setq check 0)) (if (> (abs (- (nth 1 p2) (nth 1 p5))) (abs (- (nth 1 p5) (nth 1 p6))) ) (setq check 0)) (if (> (abs (- (nth 1 p2) (nth 1 p6))) (abs (- (nth 1 p5) (nth 1 p6))) ) (setq check 0)) (if (= 0 check) (princ "\ninvalid data") (progn (setq ls1 (arlst (list (nth 1 p1) (nth 1 p2) (nth 1 p3) (nth 1 p4) ))) ; (princ ls1) (setq p7 (list (nth 0 p3) (nth 0 ls1) 0)) (setq p8 (list (nth 0 p3) (nth 1 ls1) 0)) (mkline p7 p8 l1) (setq p7 (list (nth 0 p3) (nth 2 ls1) 0)) (setq p8 (list (nth 0 p3) (nth 3 ls1) 0)) (mkline p7 p8 l1) (setq ls1 (arlst (list (nth 1 p1) (nth 1 p2) (nth 1 p5) (nth 1 p6) ))) ; (princ ls1) (setq p7 (list (nth 0 p5) (nth 0 ls1) 0)) (setq p8 (list (nth 0 p5) (nth 1 ls1) 0)) (mkline p7 p8 l1) (setq p7 (list (nth 0 p5) (nth 2 ls1) 0)) (setq p8 (list (nth 0 p5) (nth 3 ls1) 0)) (mkline p7 p8 l1) (setq p7 (list (nth 0 p3) (nth 1 ls1) 0)) (setq p8 (list (nth 0 p5) (nth 1 ls1) 0)) (mkline p7 p8 l1) (setq p7 (list (nth 0 p3) (nth 2 ls1) 0)) (setq p8 (list (nth 0 p5) (nth 2 ls1) 0)) (mkline p7 p8 l1) (setq getom (getvar "osmode")) (setvar "osmode" 0) (setq ls2 (arlst (list (nth 0 p3) (nth 0 p5)))) (setq p7 (list (nth 0 ls2) (nth 1 ls1) 0)) (setq p8 (list (nth 1 ls2) (nth 2 ls1) 0)) (setq ll1 (list (cons 0 "line") (cons 8 (getvar "clayer")) )) (drawrt2 p7 p8 ll1) (setvar "osmode" getom) (command "erase" data_m "") )) (princ) ) (defun mkh(/ p3 p4 p5 p6 p7 p8 p9 ls1 ls2 getom ll1) (setq p3 (cdr (assoc 10 l1))) (setq p4 (cdr (assoc 11 l1))) (setq p5 (cdr (assoc 10 l2))) (setq p6 (cdr (assoc 11 l2))) (if (> (abs (- (nth 0 p1) (nth 0 p3))) (abs (- (nth 0 p3) (nth 0 p4))) ) (setq check 0)) (if (> (abs (- (nth 0 p1) (nth 0 p4))) (abs (- (nth 0 p3) (nth 0 p4))) ) (setq check 0)) (if (> (abs (- (nth 0 p2) (nth 0 p5))) (abs (- (nth 0 p5) (nth 0 p6))) ) (setq check 0)) (if (> (abs (- (nth 0 p2) (nth 0 p6))) (abs (- (nth 0 p5) (nth 0 p6))) ) (setq check 0)) (if (= 0 check) (princ "\ninvalid data") (progn (setq ls1 (arlst (list (nth 0 p1) (nth 0 p2) (nth 0 p3) (nth 0 p4) ))) ; (princ ls1) (setq p7 (list (nth 0 ls1) (nth 1 p3) 0)) (setq p8 (list (nth 1 ls1) (nth 1 p3) 0)) (mkline p7 p8 l1) (setq p7 (list (nth 2 ls1) (nth 1 p3) 0)) (setq p8 (list (nth 3 ls1) (nth 1 p3) 0)) (mkline p7 p8 l1) (setq ls1 (arlst (list (nth 0 p1) (nth 0 p2) (nth 0 p5) (nth 0 p6) ))) ; (princ ls1) (setq p7 (list (nth 0 ls1) (nth 1 p5) 0)) (setq p8 (list (nth 1 ls1) (nth 1 p5) 0)) (mkline p7 p8 l1) (setq p7 (list (nth 2 ls1) (nth 1 p5) 0)) (setq p8 (list (nth 3 ls1) (nth 1 p5) 0)) (mkline p7 p8 l1) (setq p7 (list (nth 1 ls1) (nth 1 p3) 0)) (setq p8 (list (nth 1 ls1) (nth 1 p5) 0)) (mkline p7 p8 l1) (setq p7 (list (nth 2 ls1) (nth 1 p3) 0)) (setq p8 (list (nth 2 ls1) (nth 1 p5) 0)) (mkline p7 p8 l1) (setq getom (getvar "osmode")) (setvar "osmode" 0) (setq ls2 (arlst (list (nth 1 p3) (nth 1 p5)))) (setq p7 (list (nth 1 ls1) (nth 0 ls2) 0)) (setq p8 (list (nth 2 ls1) (nth 1 ls2) 0)) (setq ll1 (list (cons 0 "line") (cons 8 (getvar "clayer")) )) (drawrt3 p7 p8 ll1) (setvar "osmode" getom) (command "erase" data_m "") )) (princ) ) (setvar "cmdecho" 0) (command "undo" "mark") (setvar "cmdecho" 1) (if (= 0 check) (princ "\ninvalid data") (progn (if (< (abs (- (nth 0 (cdr (assoc 10 l1))) (nth 0 (cdr (assoc 11 l1))) )) 0.00001) (mkv)) (if (< (abs (- (nth 1 (cdr (assoc 10 l1))) (nth 1 (cdr (assoc 11 l1))) )) 0.00001) (mkh)) )) (princ) ) (wd_import) (ai_undo_push) (wd_procced) (ai_undo_pop) ) (defun c:w2(/ data_m l1 l2 p1 p2 check) (defun wd_import(/ p3 p4 p5 p6) (setq data_m (ssget)) (setq p1 (getpoint "\nfirst point :") p2 (getpoint "\nsecond point :")) (setq l1 nil l2 nil check 1) (if (not (= nil data_m)) (progn (setq l1 (entget (ssname data_m 0))) (setq l2 (entget (ssname data_m 1))) (if (or (= nil l1) (not (= "LINE" (cdr (assoc 0 l1))))) (setq check 0)) (if (or (= nil l2) (not (= "LINE" (cdr (assoc 0 l2))))) (setq check 0)) (if (not (= 0 (-(sslength data_m) 2))) (setq check 0)) (if (= 1 check) (progn (setq p3 (cdr (assoc 10 l1))) (setq p3 (list (nth 0 p3) (nth 1 p3))) (setq p4 (cdr (assoc 11 l1))) (setq p4 (list (nth 0 p4) (nth 1 p4))) (setq p5 (cdr (assoc 10 l2))) (setq p5 (list (nth 0 p5) (nth 1 p5))) (setq p6 (cdr (assoc 11 l2))) (setq p6 (list (nth 0 p6) (nth 1 p6))) (if (not (= nil (inters p3 p4 p5 p6 nil))) (setq check 0)) )) ) (setq check 0)) (princ) ) (defun wd_procced() (defun mkv(/ p3 p4 p5 p6 p7 p8 p9 ls1 ls2 getom ll1) (setq p3 (cdr (assoc 10 l1))) (setq p4 (cdr (assoc 11 l1))) (setq p5 (cdr (assoc 10 l2))) (setq p6 (cdr (assoc 11 l2))) (if (> (abs (- (nth 1 p1) (nth 1 p3))) (abs (- (nth 1 p3) (nth 1 p4))) ) (setq check 0)) (if (> (abs (- (nth 1 p1) (nth 1 p4))) (abs (- (nth 1 p3) (nth 1 p4))) ) (setq check 0)) (if (> (abs (- (nth 1 p2) (nth 1 p5))) (abs (- (nth 1 p5) (nth 1 p6))) ) (setq check 0)) (if (> (abs (- (nth 1 p2) (nth 1 p6))) (abs (- (nth 1 p5) (nth 1 p6))) ) (setq check 0)) (if (= 0 check) (princ "\ninvalid data") (progn (setq ls1 (arlst (list (nth 1 p1) (nth 1 p2) (nth 1 p3) (nth 1 p4) ))) ; (princ ls1) (setq p7 (list (nth 0 p3) (nth 0 ls1) 0)) (setq p8 (list (nth 0 p3) (nth 1 ls1) 0)) (mkline p7 p8 l1) (setq p7 (list (nth 0 p3) (nth 2 ls1) 0)) (setq p8 (list (nth 0 p3) (nth 3 ls1) 0)) (mkline p7 p8 l1) (setq ls1 (arlst (list (nth 1 p1) (nth 1 p2) (nth 1 p5) (nth 1 p6) ))) ; (princ ls1) (setq p7 (list (nth 0 p5) (nth 0 ls1) 0)) (setq p8 (list (nth 0 p5) (nth 1 ls1) 0)) (mkline p7 p8 l1) (setq p7 (list (nth 0 p5) (nth 2 ls1) 0)) (setq p8 (list (nth 0 p5) (nth 3 ls1) 0)) (mkline p7 p8 l1) (setq p7 (list (nth 0 p3) (nth 1 ls1) 0)) (setq p8 (list (nth 0 p5) (nth 1 ls1) 0)) (mkline p7 p8 l1) (setq p7 (list (nth 0 p3) (nth 2 ls1) 0)) (setq p8 (list (nth 0 p5) (nth 2 ls1) 0)) (mkline p7 p8 l1) (setq ls2 (arlst (list (nth 0 p3) (nth 0 p5)))) (setq ll1 (list (cons 0 "line") (cons 8 (getvar "clayer")) )) (if (< (nth 0 p1) (nth 0 ls2)) (progn (setq p7 (list (nth 0 ls2) (nth 1 ls1) 0)) (setq p8 (list (nth 1 ls2) (nth 2 ls1) 0)) (setq p7 (list (* (+ (nth 0 p7) (nth 0 p8)) 0.5) (nth 1 p7) 0)) (drawrt2 p7 p8 ll1) (setq p7 (list (- (nth 0 ls2) 70) (- (nth 1 ls1) 100) 0)) (setq p8 (list (- (nth 0 ls2) 70) (+ (nth 2 ls1) 100) 0)) (mkline p7 p8 ll1) (setq p9 (list (+ (nth 0 p7) 70) (nth 1 p7) 0)) (mkline p7 p9 ll1) (setq p9 (list (+ (nth 0 p8) 70) (nth 1 p8) 0)) (mkline p8 p9 ll1) )(progn (setq p7 (list (nth 0 ls2) (nth 1 ls1) 0)) (setq p8 (list (nth 1 ls2) (nth 2 ls1) 0)) (setq p8 (list (* (+ (nth 0 p7) (nth 0 p8)) 0.5) (nth 1 p8) 0)) (drawrt2 p7 p8 ll1) (setq p7 (list (+ (nth 1 ls2) 70) (- (nth 1 ls1) 100) 0)) (setq p8 (list (+ (nth 1 ls2) 70) (+ (nth 2 ls1) 100) 0)) (mkline p7 p8 ll1) (setq p9 (list (- (nth 0 p7) 70) (nth 1 p7) 0)) (mkline p7 p9 ll1) (setq p9 (list (- (nth 0 p8) 70) (nth 1 p8) 0)) (mkline p8 p9 ll1) )) (command "erase" data_m "") )) (princ) ) (defun mkh(/ p3 p4 p5 p6 p7 p8 p9 ls1 ls2 getom ll1) (setq p3 (cdr (assoc 10 l1))) (setq p4 (cdr (assoc 11 l1))) (setq p5 (cdr (assoc 10 l2))) (setq p6 (cdr (assoc 11 l2))) (if (> (abs (- (nth 0 p1) (nth 0 p3))) (abs (- (nth 0 p3) (nth 0 p4))) ) (setq check 0)) (if (> (abs (- (nth 0 p1) (nth 0 p4))) (abs (- (nth 0 p3) (nth 0 p4))) ) (setq check 0)) (if (> (abs (- (nth 0 p2) (nth 0 p5))) (abs (- (nth 0 p5) (nth 0 p6))) ) (setq check 0)) (if (> (abs (- (nth 0 p2) (nth 0 p6))) (abs (- (nth 0 p5) (nth 0 p6))) ) (setq check 0)) (if (= 0 check) (princ "\ninvalid data") (progn (setq ls1 (arlst (list (nth 0 p1) (nth 0 p2) (nth 0 p3) (nth 0 p4) ))) ; (princ ls1) (setq p7 (list (nth 0 ls1) (nth 1 p3) 0)) (setq p8 (list (nth 1 ls1) (nth 1 p3) 0)) (mkline p7 p8 l1) (setq p7 (list (nth 2 ls1) (nth 1 p3) 0)) (setq p8 (list (nth 3 ls1) (nth 1 p3) 0)) (mkline p7 p8 l1) (setq ls1 (arlst (list (nth 0 p1) (nth 0 p2) (nth 0 p5) (nth 0 p6) ))) ; (princ ls1) (setq p7 (list (nth 0 ls1) (nth 1 p5) 0)) (setq p8 (list (nth 1 ls1) (nth 1 p5) 0)) (mkline p7 p8 l1) (setq p7 (list (nth 2 ls1) (nth 1 p5) 0)) (setq p8 (list (nth 3 ls1) (nth 1 p5) 0)) (mkline p7 p8 l1) (setq p7 (list (nth 1 ls1) (nth 1 p3) 0)) (setq p8 (list (nth 1 ls1) (nth 1 p5) 0)) (mkline p7 p8 l1) (setq p7 (list (nth 2 ls1) (nth 1 p3) 0)) (setq p8 (list (nth 2 ls1) (nth 1 p5) 0)) (mkline p7 p8 l1) (setq getom (getvar "osmode")) (setvar "osmode" 0) (setq ll1 (list (cons 0 "line") (cons 8 (getvar "clayer")) )) (setq ls2 (arlst (list (nth 1 p3) (nth 1 p5)))) ;(princ ls2) (if (> (nth 1 p1) (nth 1 ls2)) (progn (setq p7 (list (nth 1 ls1) (nth 0 ls2) 0)) (setq p8 (list (nth 2 ls1) (nth 1 ls2) 0)) (setq p8 (list (nth 2 ls1) (* (+ (nth 1 p7) (nth 1 p8)) 0.5) 0)) (drawrt3 p7 p8 ll1) (setq p7 (list (- (nth 1 ls1) 100) (+ (nth 1 ls2) 70) 0)) (setq p8 (list (+ (nth 2 ls1) 100) (+ (nth 1 ls2) 70) 0)) (mkline p7 p8 ll1) (setq p9 (list (nth 0 p7) (- (nth 1 p7) 70) 0)) (mkline p7 p9 ll1) (setq p9 (list (nth 0 p8) (- (nth 1 p8) 70) 0)) (mkline p8 p9 ll1) )(progn (setq p7 (list (nth 1 ls1) (nth 0 ls2) 0)) (setq p8 (list (nth 2 ls1) (nth 1 ls2) 0)) (setq p7 (list (nth 1 ls1) (* (+ (nth 1 p7) (nth 1 p8)) 0.5) 0)) (drawrt3 p7 p8 ll1) (setq p7 (list (- (nth 1 ls1) 100) (- (nth 0 ls2) 70) 0)) (setq p8 (list (+ (nth 2 ls1) 100) (- (nth 0 ls2) 70) 0)) (mkline p7 p8 ll1) (setq p9 (list (nth 0 p7) (+ (nth 1 p7) 70) 0)) (mkline p7 p9 ll1) (setq p9 (list (nth 0 p8) (+ (nth 1 p8) 70) 0)) (mkline p8 p9 ll1) )) (setvar "osmode" getom) (command "erase" data_m "") )) (princ) ) (setvar "cmdecho" 0) (command "undo" "mark") (setvar "cmdecho" 1) (if (= 0 check) (princ "\ninvalid data") (progn (if (< (abs (- (nth 0 (cdr (assoc 10 l1))) (nth 0 (cdr (assoc 11 l1))) )) 0.00001) (mkv)) (if (< (abs (- (nth 1 (cdr (assoc 10 l1))) (nth 1 (cdr (assoc 11 l1))) )) 0.00001) (mkh)) )) (princ) ) (wd_import) (wd_procced) )
Có 2 lệnh trong lisp này.
w1: vẽ cửa sổ kiểu 1
w2: vẽ cửa sổ kiểu 2
mình không thể sài nổi cái này
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 55108_c1_c2_c4.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 C1 C2 C4 để chạy lisp.
Mã nguồn 55108_c1_c2_c4.lsp (trích từ bài viết gốc)
;-------------------------------------------------------------------------------------
;ve cua di 1 canh
;-------------------------------------------------------------------------------------
(defun c:c1 (/ p1 p2 p3 p4 p5 daicua x y)
(setq osm (getvar "osmode"))
(setq p1 (getpoint "\nHay vao diem goc cua: ")
p2 (getpoint p1 "\nHay vao diem mut cua: ")
p3 (getpoint p1 "\nHay vao huong cua: ")
daicua (distance p1 p2)
x (car p1)
y (car (cdr p1))
x 25
y daicua
p4 (list x y)
p5 (list daicua 0)
)
(setvar "OSMODE" 0)
(if (l3d_khongthanghang p1 p2 p3)
(progn
(command ".UCS" "3" p1 p2 p3)
(command ".rectangle" "0,0" p4)
(command ".Arc" p5 "C" "0,0" p4)
(command ".UCS" "P")
)
(princ "\n3 diem nhap vao khong duoc thang hang")
)
(setvar "osmode" osm)
)
;-------------------------------------------------------------------------------------
;ve cua di 2 canh
;-------------------------------------------------------------------------------------
(defun c:c2 (/ p1 p2 p3 p4 p5 daicua x y)
(setq osm (getvar "osmode"))
(setq p1 (getpoint "\nHay vao diem goc cua: ")
p2 (getpoint p1 "\nHay vao diem mut cua: ")
p3 (getpoint p1 "\nHay vao huong cua: ")
daicua (/ (distance p1 p2) 2.0)
x (car p1)
y (car (cdr p1))
x 25
y daicua
p4 (list x y)
p5 (list daicua 0)
)
(setvar "OSMODE" 0)
(if (l3d_khongthanghang p1 p2 p3)
(progn
(command ".UCS" "3" p1 p2 p3)
(command ".rectangle" "0,0" p4)
(command ".Arc" p5 "C" "0,0" p4)
(command ".UCS" "P")
(command ".UCS" "3" p2 p1 p3)
(command ".rectangle" "0,0" p4)
(command ".Arc" p5 "C" "0,0" p4)
(command ".UCS" "P")
)
(princ "\n3 diem nhap vao khong duoc thang hang")
)
(setvar "osmode" osm)
)
;-------------------------------------------------------------------------------------
;ve cua di 4 canh
;-------------------------------------------------------------------------------------
(defun c:c4 (/ p1 p2 p3 p4 p5 daicua x y)
(setq osm (getvar "osmode"))
(setq p1 (getpoint "\nHay vao diem goc cua: ")
p2 (getpoint p1 "\nHay vao diem mut cua: ")
p3 (getpoint p1 "\nHay vao huong cua: ")
daicua (/ (distance p1 p2) 4.0)
x (car p1)
y (car (cdr p1))
x 25
y daicua
p4 (list x y)
p5 (list daicua 0)
)
(setvar "OSMODE" 0)
(if (l3d_khongthanghang p1 p2 p3)
(progn
(setq diem1 (diemgiua p1 (diemgiua p1 p2)))
(setq diem2 (diemgiua p1 p2))
(setq diem3 (diemgiua p2 (diemgiua p1 p2)))
(command ".UCS" "3" p1 p2 p3)
(command ".rectangle" "0,0" p4)
(command ".Arc" p5 "C" "0,0" p4)
(command ".UCS" "P")
(command ".UCS" "3" diem1 p2 p3)
(command ".rectangle" "0,0" p4)
(command ".Arc" p5 "C" "0,0" p4)
(command ".UCS" "P")
(command ".UCS" "3" p2 p1 p3)
(command ".rectangle" "0,0" p4)
(command ".Arc" p5 "C" "0,0" p4)
(command ".UCS" "P")
(command ".UCS" "3" diem3 p1 p3)
(command ".rectangle" "0,0" p4)
(command ".Arc" p5 "C" "0,0" p4)
(command ".UCS" "P")
)
(princ "\n3 diem nhap vao khong duoc thang hang")
)
(setvar "osmode" osm)
)
;-----------------------------------------------------------------------------
(defun c:w1(/ data_m l1 l2 p1 p2 check)
(defun wd_import(/ p3 p4 p5 p6)
(setq data_m (ssget))
(setq p1 (getpoint "\nfirst point :") p2 (getpoint "\nsecond point :"))
(setq l1 nil l2 nil check 1)
(if (not (= nil data_m)) (progn
(setq l1 (entget (ssname data_m 0)))
(setq l2 (entget (ssname data_m 1)))
(if (or (= nil l1) (not (= "LINE" (cdr (assoc 0 l1))))) (setq check 0))
(if (or (= nil l2) (not (= "LINE" (cdr (assoc 0 l2))))) (setq check 0))
(if (not (= 0 (-(sslength data_m) 2))) (setq check 0))
(if (= 1 check) (progn
(setq p3 (cdr (assoc 10 l1))) (setq p3 (list (nth 0 p3) (nth 1 p3)))
(setq p4 (cdr (assoc 11 l1))) (setq p4 (list (nth 0 p4) (nth 1 p4)))
(setq p5 (cdr (assoc 10 l2))) (setq p5 (list (nth 0 p5) (nth 1 p5)))
(setq p6 (cdr (assoc 11 l2))) (setq p6 (list (nth 0 p6) (nth 1 p6)))
(if (not (= nil (inters p3 p4 p5 p6 nil))) (setq check 0))
))
) (setq check 0))
(princ)
)
(defun wd_procced()
(defun mkv(/ p3 p4 p5 p6 p7 p8 p9 ls1 ls2 getom ll1)
(setq p3 (cdr (assoc 10 l1)))
(setq p4 (cdr (assoc 11 l1)))
(setq p5 (cdr (assoc 10 l2)))
(setq p6 (cdr (assoc 11 l2)))
(if (> (abs (- (nth 1 p1) (nth 1 p3)))
(abs (- (nth 1 p3) (nth 1 p4))) ) (setq check 0))
(if (> (abs (- (nth 1 p1) (nth 1 p4)))
(abs (- (nth 1 p3) (nth 1 p4))) ) (setq check 0))
(if (> (abs (- (nth 1 p2) (nth 1 p5)))
(abs (- (nth 1 p5) (nth 1 p6))) ) (setq check 0))
(if (> (abs (- (nth 1 p2) (nth 1 p6)))
(abs (- (nth 1 p5) (nth 1 p6))) ) (setq check 0))
(if (= 0 check) (princ "\ninvalid data") (progn
(setq ls1 (arlst (list (nth 1 p1) (nth 1 p2) (nth 1 p3) (nth 1 p4) )))
; (princ ls1)
(setq p7 (list (nth 0 p3) (nth 0 ls1) 0))
(setq p8 (list (nth 0 p3) (nth 1 ls1) 0))
(mkline p7 p8 l1)
(setq p7 (list (nth 0 p3) (nth 2 ls1) 0))
(setq p8 (list (nth 0 p3) (nth 3 ls1) 0))
(mkline p7 p8 l1)
(setq ls1 (arlst (list (nth 1 p1) (nth 1 p2) (nth 1 p5) (nth 1 p6) )))
; (princ ls1)
(setq p7 (list (nth 0 p5) (nth 0 ls1) 0))
(setq p8 (list (nth 0 p5) (nth 1 ls1) 0))
(mkline p7 p8 l1)
(setq p7 (list (nth 0 p5) (nth 2 ls1) 0))
(setq p8 (list (nth 0 p5) (nth 3 ls1) 0))
(mkline p7 p8 l1)
(setq p7 (list (nth 0 p3) (nth 1 ls1) 0))
(setq p8 (list (nth 0 p5) (nth 1 ls1) 0))
(mkline p7 p8 l1)
(setq p7 (list (nth 0 p3) (nth 2 ls1) 0))
(setq p8 (list (nth 0 p5) (nth 2 ls1) 0))
(mkline p7 p8 l1)
(setq getom (getvar "osmode"))
(setvar "osmode" 0)
(setq ls2 (arlst (list (nth 0 p3) (nth 0 p5))))
(setq p7 (list (nth 0 ls2) (nth 1 ls1) 0))
(setq p8 (list (nth 1 ls2) (nth 2 ls1) 0))
(setq ll1 (list
(cons 0 "line")
(cons 8 (getvar "clayer"))
))
(drawrt2 p7 p8 ll1)
(setvar "osmode" getom)
(command "erase" data_m "")
))
(princ)
)
(defun mkh(/ p3 p4 p5 p6 p7 p8 p9 ls1 ls2 getom ll1)
(setq p3 (cdr (assoc 10 l1)))
(setq p4 (cdr (assoc 11 l1)))
(setq p5 (cdr (assoc 10 l2)))
(setq p6 (cdr (assoc 11 l2)))
(if (> (abs (- (nth 0 p1) (nth 0 p3)))
(abs (- (nth 0 p3) (nth 0 p4))) ) (setq check 0))
(if (> (abs (- (nth 0 p1) (nth 0 p4)))
(abs (- (nth 0 p3) (nth 0 p4))) ) (setq check 0))
(if (> (abs (- (nth 0 p2) (nth 0 p5)))
(abs (- (nth 0 p5) (nth 0 p6))) ) (setq check 0))
(if (> (abs (- (nth 0 p2) (nth 0 p6)))
(abs (- (nth 0 p5) (nth 0 p6))) ) (setq check 0))
(if (= 0 check) (princ "\ninvalid data") (progn
(setq ls1 (arlst (list (nth 0 p1) (nth 0 p2) (nth 0 p3) (nth 0 p4) )))
; (princ ls1)
(setq p7 (list (nth 0 ls1) (nth 1 p3) 0))
(setq p8 (list (nth 1 ls1) (nth 1 p3) 0))
(mkline p7 p8 l1)
(setq p7 (list (nth 2 ls1) (nth 1 p3) 0))
(setq p8 (list (nth 3 ls1) (nth 1 p3) 0))
(mkline p7 p8 l1)
(setq ls1 (arlst (list (nth 0 p1) (nth 0 p2) (nth 0 p5) (nth 0 p6) )))
; (princ ls1)
(setq p7 (list (nth 0 ls1) (nth 1 p5) 0))
(setq p8 (list (nth 1 ls1) (nth 1 p5) 0))
(mkline p7 p8 l1)
(setq p7 (list (nth 2 ls1) (nth 1 p5) 0))
(setq p8 (list (nth 3 ls1) (nth 1 p5) 0))
(mkline p7 p8 l1)
(setq p7 (list (nth 1 ls1) (nth 1 p3) 0))
(setq p8 (list (nth 1 ls1) (nth 1 p5) 0))
(mkline p7 p8 l1)
(setq p7 (list (nth 2 ls1) (nth 1 p3) 0))
(setq p8 (list (nth 2 ls1) (nth 1 p5) 0))
(mkline p7 p8 l1)
(setq getom (getvar "osmode"))
(setvar "osmode" 0)
(setq ls2 (arlst (list (nth 1 p3) (nth 1 p5))))
(setq p7 (list (nth 1 ls1) (nth 0 ls2) 0))
(setq p8 (list (nth 2 ls1) (nth 1 ls2) 0))
(setq ll1 (list
(cons 0 "line")
(cons 8 (getvar "clayer"))
))
(drawrt3 p7 p8 ll1)
(setvar "osmode" getom)
(command "erase" data_m "")
))
(princ)
)
(setvar "cmdecho" 0) (command "undo" "mark") (setvar "cmdecho" 1)
(if (= 0 check) (princ "\ninvalid data") (progn
(if (< (abs (- (nth 0 (cdr (assoc 10 l1)))
(nth 0 (cdr (assoc 11 l1))) )) 0.00001) (mkv))
(if (< (abs (- (nth 1 (cdr (assoc 10 l1)))
(nth 1 (cdr (assoc 11 l1))) )) 0.00001) (mkh))
))
(princ)
)
(wd_import)
(ai_undo_push)
(wd_procced)
(ai_undo_pop)
)
(defun c:w2(/ data_m l1 l2 p1 p2 check)
(defun wd_import(/ p3 p4 p5 p6)
(setq data_m (ssget))
(setq p1 (getpoint "\nfirst point :") p2 (getpoint "\nsecond point :"))
(setq l1 nil l2 nil check 1)
(if (not (= nil data_m)) (progn
(setq l1 (entget (ssname data_m 0)))
(setq l2 (entget (ssname data_m 1)))
(if (or (= nil l1) (not (= "LINE" (cdr (assoc 0 l1))))) (setq check 0))
(if (or (= nil l2) (not (= "LINE" (cdr (assoc 0 l2))))) (setq check 0))
(if (not (= 0 (-(sslength data_m) 2))) (setq check 0))
(if (= 1 check) (progn
(setq p3 (cdr (assoc 10 l1))) (setq p3 (list (nth 0 p3) (nth 1 p3)))
(setq p4 (cdr (assoc 11 l1))) (setq p4 (list (nth 0 p4) (nth 1 p4)))
(setq p5 (cdr (assoc 10 l2))) (setq p5 (list (nth 0 p5) (nth 1 p5)))
(setq p6 (cdr (assoc 11 l2))) (setq p6 (list (nth 0 p6) (nth 1 p6)))
(if (not (= nil (inters p3 p4 p5 p6 nil))) (setq check 0))
))
) (setq check 0))
(princ)
)
(defun wd_procced()
(defun mkv(/ p3 p4 p5 p6 p7 p8 p9 ls1 ls2 getom ll1)
(setq p3 (cdr (assoc 10 l1)))
(setq p4 (cdr (assoc 11 l1)))
(setq p5 (cdr (assoc 10 l2)))
(setq p6 (cdr (assoc 11 l2)))
(if (> (abs (- (nth 1 p1) (nth 1 p3)))
(abs (- (nth 1 p3) (nth 1 p4))) ) (setq check 0))
(if (> (abs (- (nth 1 p1) (nth 1 p4)))
(abs (- (nth 1 p3) (nth 1 p4))) ) (setq check 0))
(if (> (abs (- (nth 1 p2) (nth 1 p5)))
(abs (- (nth 1 p5) (nth 1 p6))) ) (setq check 0))
(if (> (abs (- (nth 1 p2) (nth 1 p6)))
(abs (- (nth 1 p5) (nth 1 p6))) ) (setq check 0))
(if (= 0 check) (princ "\ninvalid data") (progn
(setq ls1 (arlst (list (nth 1 p1) (nth 1 p2) (nth 1 p3) (nth 1 p4) )))
; (princ ls1)
(setq p7 (list (nth 0 p3) (nth 0 ls1) 0))
(setq p8 (list (nth 0 p3) (nth 1 ls1) 0))
(mkline p7 p8 l1)
(setq p7 (list (nth 0 p3) (nth 2 ls1) 0))
(setq p8 (list (nth 0 p3) (nth 3 ls1) 0))
(mkline p7 p8 l1)
(setq ls1 (arlst (list (nth 1 p1) (nth 1 p2) (nth 1 p5) (nth 1 p6) )))
; (princ ls1)
(setq p7 (list (nth 0 p5) (nth 0 ls1) 0))
(setq p8 (list (nth 0 p5) (nth 1 ls1) 0))
(mkline p7 p8 l1)
(setq p7 (list (nth 0 p5) (nth 2 ls1) 0))
(setq p8 (list (nth 0 p5) (nth 3 ls1) 0))
(mkline p7 p8 l1)
(setq p7 (list (nth 0 p3) (nth 1 ls1) 0))
(setq p8 (list (nth 0 p5) (nth 1 ls1) 0))
(mkline p7 p8 l1)
(setq p7 (list (nth 0 p3) (nth 2 ls1) 0))
(setq p8 (list (nth 0 p5) (nth 2 ls1) 0))
(mkline p7 p8 l1)
(setq ls2 (arlst (list (nth 0 p3) (nth 0 p5))))
(setq ll1 (list
(cons 0 "line")
(cons 8 (getvar "clayer"))
))
(if (< (nth 0 p1) (nth 0 ls2)) (progn
(setq p7 (list (nth 0 ls2) (nth 1 ls1) 0))
(setq p8 (list (nth 1 ls2) (nth 2 ls1) 0))
(setq p7 (list (* (+ (nth 0 p7) (nth 0 p8)) 0.5) (nth 1 p7) 0))
(drawrt2 p7 p8 ll1)
(setq p7 (list (- (nth 0 ls2) 70) (- (nth 1 ls1) 100) 0))
(setq p8 (list (- (nth 0 ls2) 70) (+ (nth 2 ls1) 100) 0))
(mkline p7 p8 ll1)
(setq p9 (list (+ (nth 0 p7) 70) (nth 1 p7) 0))
(mkline p7 p9 ll1)
(setq p9 (list (+ (nth 0 p8) 70) (nth 1 p8) 0))
(mkline p8 p9 ll1)
)(progn
(setq p7 (list (nth 0 ls2) (nth 1 ls1) 0))
(setq p8 (list (nth 1 ls2) (nth 2 ls1) 0))
(setq p8 (list (* (+ (nth 0 p7) (nth 0 p8)) 0.5) (nth 1 p8) 0))
(drawrt2 p7 p8 ll1)
(setq p7 (list (+ (nth 1 ls2) 70) (- (nth 1 ls1) 100) 0))
(setq p8 (list (+ (nth 1 ls2) 70) (+ (nth 2 ls1) 100) 0))
(mkline p7 p8 ll1)
(setq p9 (list (- (nth 0 p7) 70) (nth 1 p7) 0))
(mkline p7 p9 ll1)
(setq p9 (list (- (nth 0 p8) 70) (nth 1 p8) 0))
(mkline p8 p9 ll1)
))
(command "erase" data_m "")
))
(princ)
)
(defun mkh(/ p3 p4 p5 p6 p7 p8 p9 ls1 ls2 getom ll1)
(setq p3 (cdr (assoc 10 l1)))
(setq p4 (cdr (assoc 11 l1)))
(setq p5 (cdr (assoc 10 l2)))
(setq p6 (cdr (assoc 11 l2)))
(if (> (abs (- (nth 0 p1) (nth 0 p3)))
(abs (- (nth 0 p3) (nth 0 p4))) ) (setq check 0))
(if (> (abs (- (nth 0 p1) (nth 0 p4)))
(abs (- (nth 0 p3) (nth 0 p4))) ) (setq check 0))
(if (> (abs (- (nth 0 p2) (nth 0 p5)))
(abs (- (nth 0 p5) (nth 0 p6))) ) (setq check 0))
(if (> (abs (- (nth 0 p2) (nth 0 p6)))
(abs (- (nth 0 p5) (nth 0 p6))) ) (setq check 0))
(if (= 0 check) (princ "\ninvalid data") (progn
(setq ls1 (arlst (list (nth 0 p1) (nth 0 p2) (nth 0 p3) (nth 0 p4) )))
; (princ ls1)
(setq p7 (list (nth 0 ls1) (nth 1 p3) 0))
(setq p8 (list (nth 1 ls1) (nth 1 p3) 0))
(mkline p7 p8 l1)
(setq p7 (list (nth 2 ls1) (nth 1 p3) 0))
(setq p8 (list (nth 3 ls1) (nth 1 p3) 0))
(mkline p7 p8 l1)
(setq ls1 (arlst (list (nth 0 p1) (nth 0 p2) (nth 0 p5) (nth 0 p6) )))
; (princ ls1)
(setq p7 (list (nth 0 ls1) (nth 1 p5) 0))
(setq p8 (list (nth 1 ls1) (nth 1 p5) 0))
(mkline p7 p8 l1)
(setq p7 (list (nth 2 ls1) (nth 1 p5) 0))
(setq p8 (list (nth 3 ls1) (nth 1 p5) 0))
(mkline p7 p8 l1)
(setq p7 (list (nth 1 ls1) (nth 1 p3) 0))
(setq p8 (list (nth 1 ls1) (nth 1 p5) 0))
(mkline p7 p8 l1)
(setq p7 (list (nth 2 ls1) (nth 1 p3) 0))
(setq p8 (list (nth 2 ls1) (nth 1 p5) 0))
(mkline p7 p8 l1)
(setq getom (getvar "osmode"))
(setvar "osmode" 0)
(setq ll1 (list
(cons 0 "line")
(cons 8 (getvar "clayer"))
))
(setq ls2 (arlst (list (nth 1 p3) (nth 1 p5))))
;(princ ls2)
(if (> (nth 1 p1) (nth 1 ls2)) (progn
(setq p7 (list (nth 1 ls1) (nth 0 ls2) 0))
(setq p8 (list (nth 2 ls1) (nth 1 ls2) 0))
(setq p8 (list (nth 2 ls1) (* (+ (nth 1 p7) (nth 1 p8)) 0.5) 0))
(drawrt3 p7 p8 ll1)
(setq p7 (list (- (nth 1 ls1) 100) (+ (nth 1 ls2) 70) 0))
(setq p8 (list (+ (nth 2 ls1) 100) (+ (nth 1 ls2) 70) 0))
(mkline p7 p8 ll1)
(setq p9 (list (nth 0 p7) (- (nth 1 p7) 70) 0))
(mkline p7 p9 ll1)
(setq p9 (list (nth 0 p8) (- (nth 1 p8) 70) 0))
(mkline p8 p9 ll1)
)(progn
(setq p7 (list (nth 1 ls1) (nth 0 ls2) 0))
(setq p8 (list (nth 2 ls1) (nth 1 ls2) 0))
(setq p7 (list (nth 1 ls1) (* (+ (nth 1 p7) (nth 1 p8)) 0.5) 0))
(drawrt3 p7 p8 ll1)
(setq p7 (list (- (nth 1 ls1) 100) (- (nth 0 ls2) 70) 0))
(setq p8 (list (+ (nth 2 ls1) 100) (- (nth 0 ls2) 70) 0))
(mkline p7 p8 ll1)
(setq p9 (list (nth 0 p7) (+ (nth 1 p7) 70) 0))
(mkline p7 p9 ll1)
(setq p9 (list (nth 0 p8) (+ (nth 1 p8) 70) 0))
(mkline p8 p9 ll1)
))
(setvar "osmode" getom)
(command "erase" data_m "")
))
(princ)
)
(setvar "cmdecho" 0) (command "undo" "mark") (setvar "cmdecho" 1)
(if (= 0 check) (princ "\ninvalid data") (progn
(if (< (abs (- (nth 0 (cdr (assoc 10 l1)))
(nth 0 (cdr (assoc 11 l1))) )) 0.00001) (mkv))
(if (< (abs (- (nth 1 (cdr (assoc 10 l1)))
(nth 1 (cdr (assoc 11 l1))) )) 0.00001) (mkh))
))
(princ)
)
(wd_import)
(wd_procced)
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề Ứng dụng LISP để vẽ bản vẽ kiến trúc (phần cơ bản). Xem đúng bài viết #55108 để đọc hướng dẫn và trao đổi thêm.