Mình viết một lisp đo diện tích MCN, xuất kết quả ra màn hình CAD, xuất Kq ra Excel
nhưng khi xuất kq ra Excel thì lần thứ hai lại lặp lại từ đầu (mở lại Excel và ghi vào Book mới)
Mình muốn khi xuất kq ra Excel thì lần thứ hai, ba, bốn... kết quả vẫn ghi tiếp tục vào Book1 đầu tiên.
Nhờ mọi người chỉnh sửa lisp giúp nhé.
;---------Tinh Dien Tich Dao, Dap (Cho M.cat) - dientich-01
;**********************************************************
(defun Get_tle (/ g:tle)
(set_tile "error" "")
(setq g:tle (get_tile "tle"))
(setq tle (atof g:tle))
)
;------------------------------------------
(defun Get_ten (/ g:ten)
(set_tile "error" "")
(setq g:ten (get_tile "ten"))
(setq ten g:ten)
)
;------------------------------------------
(defun Get_cdon (/ g:cdon)
(set_tile "error" "")
(setq g:cdon (get_tile "cdon"))
(setq cdon (atof g:cdon))
)
;------------------------------------------
;------------------------------------------
(defun Get_t1()
(set_tile "error" "")
(setq g:t1 (get_tile "t1"))
(setq t1 g:t1)
(cond
((= g:t1 "1")
(mode_tile "e1" 0)
(mode_tile "s1" 0)
(mode_tile "p1" 0)
)
(T
(mode_tile "e1" 1)
(mode_tile "s1" 1)
(mode_tile "p1" 1)
(set_tile "e1" (setq g:e1 ""))
(set_tile "s1" (STRCAT "= " (setq g:s1 (rtos 0.0 2 3)) " m2"))
)
)
)
;------------------------------------------
(defun Get_t2()
(set_tile "error" "")
(setq g:t2 (get_tile "t2"))
(setq t2 g:t2)
(cond
((= g:t2 "1")
(mode_tile "e2" 0)
(mode_tile "s2" 0)
(mode_tile "p2" 0)
)
(T
(mode_tile "e2" 1)
(mode_tile "s2" 1)
(mode_tile "p2" 1)
(set_tile "e2" (setq g:e2 ""))
(set_tile "s2" (STRCAT "= " (setq g:s2 (rtos 0.0 2 3)) " m2"))
)
)
)
;------------------------------------------
(defun Get_t3()
(set_tile "error" "")
(setq g:t3 (get_tile "t3"))
(setq t3 g:t3)
(cond
((= g:t3 "1")
(mode_tile "e3" 0)
(mode_tile "s3" 0)
(mode_tile "p3" 0)
)
(T
(mode_tile "e3" 1)
(mode_tile "s3" 1)
(mode_tile "p3" 1)
(set_tile "e3" (setq g:e3 ""))
(set_tile "s3" (STRCAT "= " (setq g:s3 (rtos 0.0 2 3)) " m2"))
)
)
)
;------------------------------------------
(defun Get_t4()
(set_tile "error" "")
(setq g:t4 (get_tile "t4"))
(setq t4 g:t4)
(cond
((= g:t4 "1")
(mode_tile "e4" 0)
(mode_tile "s4" 0)
(mode_tile "p4" 0)
)
(T
(mode_tile "e4" 1)
(mode_tile "s4" 1)
(mode_tile "p4" 1)
(set_tile "e4" (setq g:e4 ""))
(set_tile "s4" (STRCAT "= " (setq g:s4 (rtos 0.0 2 3)) " m2"))
)
)
)
;------------------------------------------
(defun Get_t5()
(set_tile "error" "")
(setq g:t5 (get_tile "t5"))
(setq t5 g:t5)
(cond
((= g:t5 "1")
(mode_tile "e5" 0)
(mode_tile "s5" 0)
(mode_tile "p5" 0)
)
(T
(mode_tile "e5" 1)
(mode_tile "s5" 1)
(mode_tile "p5" 1)
(set_tile "e5" (setq g:e5 ""))
(set_tile "s5" (STRCAT "= " (setq g:s5 (rtos 0.0 2 3)) " m2"))
)
)
)
;------------------------------------------
(defun Get_t6()
(set_tile "error" "")
(setq g:t6 (get_tile "t6"))
(setq t6 g:t6)
(cond
((= g:t6 "1")
(mode_tile "e6" 0)
(mode_tile "s1" 0)
(mode_tile "p6" 0)
)
(T
(mode_tile "e6" 1)
(mode_tile "s6" 1)
(mode_tile "p6" 1)
(set_tile "e6" (setq g:e6 ""))
(set_tile "s6" (STRCAT "= " (setq g:s6 (rtos 0.0 2 3)) " m2"))
)
)
)
;------------------------------------------
(defun Get_t7()
(set_tile "error" "")
(setq g:t7 (get_tile "t7"))
(setq t7 g:t7)
(cond
((= g:t7 "1")
(mode_tile "e7" 0)
(mode_tile "s7" 0)
(mode_tile "p7" 0)
)
(T
(mode_tile "e7" 1)
(mode_tile "s7" 1)
(mode_tile "p7" 1)
(set_tile "e7" (setq g:e7 ""))
(set_tile "s7" (STRCAT "= " (setq g:s7 (rtos 0.0 2 3)) " m2"))
)
)
)
;------------------------------------------
(defun Get_t8()
(set_tile "error" "")
(setq g:t8 (get_tile "t8"))
(setq t8 g:t8)
(cond
((= g:t8 "1")
(mode_tile "e8" 0)
(mode_tile "s8" 0)
(mode_tile "p8" 0)
)
(T
(mode_tile "e8" 1)
(mode_tile "s8" 1)
(mode_tile "p8" 1)
(set_tile "e8" (setq g:e8 ""))
(set_tile "s8" (STRCAT "= " (setq g:s8 (rtos 0.0 2 3)) " m2"))
)
)
)
;------------------------------------------
(defun Get_t9()
(set_tile "error" "")
(setq g:t9 (get_tile "t9"))
(setq t9 g:t9)
(cond
((= g:t9 "1")
(mode_tile "e9" 0)
(mode_tile "s9" 0)
(mode_tile "p9" 0)
)
(T
(mode_tile "e9" 1)
(mode_tile "s9" 1)
(mode_tile "p9" 1)
(set_tile "e9" (setq g:e9 ""))
(set_tile "s9" (STRCAT "= " (setq g:s9 (rtos 0.0 2 3)) " m2"))
)
)
)
;------------------------------------------
(defun Get_t10()
(set_tile "error" "")
(setq g:t10 (get_tile "t10"))
(setq t10 g:t10)
(cond
((= g:t10 "1")
(mode_tile "e10" 0)
(mode_tile "s10" 0)
(mode_tile "p10" 0)
)
(T
(mode_tile "e10" 1)
(mode_tile "s10" 1)
(mode_tile "p10" 1)
(set_tile "e10" (setq g:e10 ""))
(set_tile "s10" (STRCAT "= " (setq g:s10 (rtos 0.0 2 3)) " m2"))
)
)
)
;------------------------------------------
;------------------------------------------
(defun Get_e1()
(set_tile "error" "")
(setq g:e1 (get_tile "e1"))
(setq e1 g:e1)
)
;------------------------------------------
(defun Get_e2()
(set_tile "error" "")
(setq g:e2 (get_tile "e2"))
(setq e2 g:e2)
)
;------------------------------------------
(defun Get_e3()
(set_tile "error" "")
(setq g:e3 (get_tile "e3"))
(setq e3 g:e3)
)
;------------------------------------------
(defun Get_e4()
(set_tile "error" "")
(setq g:e4 (get_tile "e4"))
(setq e4 g:e4)
)
;------------------------------------------
(defun Get_e5()
(set_tile "error" "")
(setq g:e5 (get_tile "e5"))
(setq e5 g:e5)
)
;------------------------------------------
(defun Get_e6()
(set_tile "error" "")
(setq g:e6 (get_tile "e6"))
(setq e6 g:e6)
)
;------------------------------------------
(defun Get_e7()
(set_tile "error" "")
(setq g:e7 (get_tile "e7"))
(setq e7 g:e7)
)
;------------------------------------------
(defun Get_e8()
(set_tile "error" "")
(setq g:e8 (get_tile "e8"))
(setq e8 g:e8)
)
;------------------------------------------
(defun Get_e9()
(set_tile "error" "")
(setq g:e9 (get_tile "e9"))
(setq e9 g:e9)
)
;------------------------------------------
(defun Get_e10()
(set_tile "error" "")
(setq g:e10 (get_tile "e10"))
(setq e10 g:e10)
)
;------------------------------------------
;------------------------------------------
(defun Get_p1()
(set_tile "error" "")
(dientich)
; (alert (strcat "\n tri so g:btct = " g:btct))
)
;------------------------------------------
(defun Get_p2()
(set_tile "error" "")
(dientich)
)
;------------------------------------------
(defun Get_p3()
(set_tile "error" "")
(dientich)
)
;------------------------------------------
(defun Get_p4()
(set_tile "error" "")
(dientich)
)
;------------------------------------------
(defun Get_p5()
(set_tile "error" "")
(dientich)
)
;------------------------------------------
(defun Get_p6()
(set_tile "error" "")
(dientich)
)
;------------------------------------------
(defun Get_p7()
(set_tile "error" "")
(dientich)
)
;------------------------------------------
(defun Get_p8()
(set_tile "error" "")
(dientich)
)
;------------------------------------------
(defun Get_p9()
(set_tile "error" "")
(dientich)
)
;------------------------------------------
(defun Get_p10()
(set_tile "error" "")
(dientich)
)
;------------------------------------------
;;;mode_tile - 0 = an (Tat), 1 = Hien (mo)
;------------------------------------------
(defun Setloc()
(if (not tle) (setq tle 50.0))
(set_tile "tle" (setq g:tle (rtos tle 2 0)))
(if (not ten) (setq ten "A-A"))
(set_tile "ten" (setq g:ten ten))
(if (not cdon) (setq cdon 0.0))
(set_tile "cdon" (setq g:cdon (rtos cdon 2 2)))
(if (not e1) (setq e1 ""))
(set_tile "e1" (setq g:e1 e1))
(if (not e2) (setq e2 ""))
(set_tile "e2" (setq g:e2 e2))
(if (not e3) (setq e3 ""))
(set_tile "e3" (setq g:e3 e3))
(if (not e4) (setq e4 ""))
(set_tile "e4" (setq g:e4 e4))
(if (not e5) (setq e5 ""))
(set_tile "e5" (setq g:e5 e5))
(if (not e6) (setq e6 ""))
(set_tile "e6" (setq g:e6 e6))
(if (not e7) (setq e7 ""))
(set_tile "e7" (setq g:e7 e7))
(if (not e8) (setq e8 ""))
(set_tile "e8" (setq g:e8 e8))
(if (not e9) (setq e9 ""))
(set_tile "e9" (setq g:e9 e9))
(if (not e10) (setq e10 ""))
(set_tile "e10" (setq g:e10 e10))
(if (not dt1) (setq dt1 0.0))
(set_tile "s1" (STRCAT "= " (setq g:s1 (rtos dt1 2 3)) " m2"))
(if (not dt2) (setq dt2 0.0))
(set_tile "s2" (STRCAT "= " (setq g:s2 (rtos dt2 2 3)) " m2"))
(if (not dt3) (setq dt3 0.0))
(set_tile "s3" (STRCAT "= " (setq g:s3 (rtos dt3 2 3)) " m2"))
(if (not dt4) (setq dt4 0.0))
(set_tile "s4" (STRCAT "= " (setq g:s4 (rtos dt4 2 3)) " m2"))
(if (not dt5) (setq dt5 0.0))
(set_tile "s5" (STRCAT "= " (setq g:s5 (rtos dt5 2 3)) " m2"))
(if (not dt6) (setq dt6 0.0))
(set_tile "s6" (STRCAT "= " (setq g:s6 (rtos dt6 2 3)) " m2"))
(if (not dt7) (setq dt7 0.0))
(set_tile "s7" (STRCAT "= " (setq g:s7 (rtos dt7 2 3)) " m2"))
(if (not dt8) (setq dt8 0.0))
(set_tile "s8" (STRCAT "= " (setq g:s8 (rtos dt8 2 3)) " m2"))
(if (not dt9) (setq dt9 0.0))
(set_tile "s9" (STRCAT "= " (setq g:s9 (rtos dt9 2 3)) " m2"))
(if (not dt10) (setq dt10 0.0))
(set_tile "s10" (STRCAT "= " (setq g:s10 (rtos dt10 2 3)) " m2"))
(if (not g:t1) (setq g:t1 "1"))
(set_tile "t1" g:t1)
(cond
((= g:t1 "1")
(mode_tile "e1" 0)
(mode_tile "s1" 0)
(mode_tile "p1" 0)
)
(T
(mode_tile "e1" 1)
(mode_tile "s1" 1)
(mode_tile "p1" 1)
)
)
(if (not g:t2) (setq g:t2 "0"))
(set_tile "t2" g:t2)
(cond
((= g:t2 "1")
(mode_tile "e2" 0)
(mode_tile "s2" 0)
(mode_tile "p2" 0)
)
(T
(mode_tile "e2" 1)
(mode_tile "s2" 1)
(mode_tile "p2" 1)
)
)
(if (not g:t3) (setq g:t3 "0"))
(set_tile "t3" g:t3)
(cond
((= g:t3 "1")
(mode_tile "e3" 0)
(mode_tile "s3" 0)
(mode_tile "p3" 0)
)
(T
(mode_tile "e3" 1)
(mode_tile "s3" 1)
(mode_tile "p3" 1)
)
)
(if (not g:t4) (setq g:t4 "0"))
(set_tile "t4" g:t4)
(cond
((= g:t4 "1")
(mode_tile "e4" 0)
(mode_tile "s4" 0)
(mode_tile "p4" 0)
)
(T
(mode_tile "e4" 1)
(mode_tile "s4" 1)
(mode_tile "p4" 1)
)
)
(if (not g:t5) (setq g:t5 "0"))
(set_tile "t5" g:t5)
(cond
((= g:t5 "1")
(mode_tile "e5" 0)
(mode_tile "s5" 0)
(mode_tile "p5" 0)
)
(T
(mode_tile "e5" 1)
(mode_tile "s5" 1)
(mode_tile "p5" 1)
)
)
(if (not g:t6) (setq g:t6 "0"))
(set_tile "t6" g:t6)
(cond
((= g:t6 "1")
(mode_tile "e6" 0)
(mode_tile "s1" 0)
(mode_tile "p6" 0)
)
(T
(mode_tile "e6" 1)
(mode_tile "s6" 1)
(mode_tile "p6" 1)
)
)
(if (not g:t7) (setq g:t7 "0"))
(set_tile "t7" g:t7)
(cond
((= g:t7 "1")
(mode_tile "e7" 0)
(mode_tile "s7" 0)
(mode_tile "p7" 0)
)
(T
(mode_tile "e7" 1)
(mode_tile "s7" 1)
(mode_tile "p7" 1)
)
)
(if (not g:t8) (setq g:t8 "0"))
(set_tile "t8" g:t8)
(cond
((= g:t8 "1")
(mode_tile "e8" 0)
(mode_tile "s8" 0)
(mode_tile "p8" 0)
)
(T
(mode_tile "e8" 1)
(mode_tile "s8" 1)
(mode_tile "p8" 1)
)
)
(if (not g:t9) (setq g:t9 "0"))
(set_tile "t9" g:t9)
(cond
((= g:t9 "1")
(mode_tile "e9" 0)
(mode_tile "s9" 0)
(mode_tile "p9" 0)
)
(T
(mode_tile "e9" 1)
(mode_tile "s9" 1)
(mode_tile "p9" 1)
)
)
(if (not g:t10) (setq g:t10 "0"))
(set_tile "t10" g:t10)
(cond
((= g:t10 "1")
(mode_tile "e10" 0)
(mode_tile "s10" 0)
(mode_tile "p10" 0)
)
(T
(mode_tile "e10" 1)
(mode_tile "s10" 1)
(mode_tile "p10" 1)
)
)
)
;---------------
(defun Restore()
(command "LUPREC" 2 "color" "bylayer" "osmode" 97)
(setq *ERROR* Olderr)
(setvar "BLIPMODE" Oldblp) (setvar "CMDECHO" Oldech)
(setvar "PICKBOX" 4) (setvar "DIMZIN" 8)
)
;----------------------------------------------------------------------------
(defun C:dientich-01 (/ Oldblp Oldech Olderr Dial nhim What_next ten cdon sdo
t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 s1 s2 s3 s4 s5 s6 s7 s8 s9 s10
p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 dt1 dt2 dt3 dt4 dt5 dt6 dt7 dt8 dt9 dt10
g:e1 g:e2 g:e3 g:e4 g:e5 g:e6 g:e7 g:e8 g:e9 g:e10
g:s1 g:s2 g:s3 g:s4 g:s5 g:s6 g:s7 g:s8 g:s9 g:s10)
(setq Oldblp (getvar "BLIPMODE") Oldech (getvar "CMDECHO") Olderr *ERROR*)
(setvar "BLIPMODE" 0) (setvar "DIMZIN" 0) (setvar "PICKBOX" 0) (setvar "CMDECHO" 0)
(COMMAND "LUPREC" 4 "osnap" "None" "UCS" "W")
;----------------------------------------------
(defun *ERROR* (Msg)
(princ "\nError: ") (princ Msg)
(unload_dialog Dial)
(Restore)
(princ)
)
;---------------------------------------------
(setq Dial (load_dialog "Dien_tich_01.DCL"))
(setq What_next 2)
(while (> What_next 1)
(if (not (new_dialog "Dientich01" Dial))
(progn (Restore) (exit))
)
(Setloc)
(action_tile "tle" "(Get_tle)")
(action_tile "ten" "(Get_ten)")
(action_tile "cdon" "(Get_cdon)")
(action_tile "t1" "(Get_t1)")
(action_tile "t2" "(Get_t2)")
(action_tile "t3" "(Get_t3)")
(action_tile "t4" "(Get_t4)")
(action_tile "t5" "(Get_t5)")
(action_tile "t6" "(Get_t6)")
(action_tile "t7" "(Get_t7)")
(action_tile "t8" "(Get_t8)")
(action_tile "t9" "(Get_t9)")
(action_tile "t10" "(Get_t10)")
(action_tile "e1" "(Get_e1)")
(action_tile "e2" "(Get_e2)")
(action_tile "e3" "(Get_e3)")
(action_tile "e4" "(Get_e4)")
(action_tile "e5" "(Get_e5)")
(action_tile "e6" "(Get_e6)")
(action_tile "e7" "(Get_e7)")
(action_tile "e8" "(Get_e8)")
(action_tile "e9" "(Get_e9)")
(action_tile "e10" "(Get_e10)")
(action_tile "p1" "(done_dialog 2)")
(action_tile "p2" "(done_dialog 3)")
(action_tile "p3" "(done_dialog 4)")
(action_tile "p4" "(done_dialog 5)")
(action_tile "p5" "(done_dialog 6)")
(action_tile "p6" "(done_dialog 7)")
(action_tile "p7" "(done_dialog 8)")
(action_tile "p8" "(done_dialog 9)")
(action_tile "p9" "(done_dialog 10)")
(action_tile "p10" "(done_dialog 11)")
(action_tile "excel" "(done_dialog 12)")
(action_tile "Accept" "(done_dialog 1)")
(action_tile "cancel" "(done_dialog 0)")
(setq What_next (start_dialog))
(cond
((= What_next 1) (Go))
((= What_next 2) (Get_p1))
((= What_next 3) (Get_p2))
((= What_next 4) (Get_p3))
((= What_next 5) (Get_p4))
((= What_next 6) (Get_p5))
((= What_next 7) (Get_p6))
((= What_next 8) (Get_p7))
((= What_next 9) (Get_p8))
((= What_next 10) (Get_p9))
((= What_next 11) (Get_p10))
((= What_next 12) (if (vlax-get-or-create-object "Excel.Application")
(WriteToExcel)
))
)
)
(unload_dialog Dial)
(Restore)
(princ)
)
;;;---------------------------------------------------------------
(defun dientich (/ bli cmd E Eo En do diem s name Ename oldcolor)
(setq do nil s nil Ename (ssadd))
(setq E "P") (initget 128 "P S")
(setq Eo (getkword "\nSelect Entity or Pick Point (S/<P>) : "))
(if Eo (setq E Eo))
(cond
((= E "P")
(command "color" 6 "linetype" "S" "hidden" "" "osmode" 0)
(while
(setq diem (getpoint "\n Pick point...(<Retern>to end) :"))
(command "boundary" diem "" "area" "E" "L")
(setq s (getvar "area"))
(setq name (entlast))
(setq do (cons s do))
(setq Ename (ssadd name Ename))
)
(setq Sdo (eval (cons + do)))
(command "erase" Ename "" "color" "Bylayer" "linetype" "S" "continuous" "")u
)
(T
(setq En (ssget))
(command "area" "E" En)
(setq Sdo (getvar "area"))
)
)
(setq tile (/ tle 100))
(cond
((= What_next 2) (setq dt1 (* Sdo tile tile)))
((= What_next 3) (setq dt2 (* Sdo tile tile)))
((= What_next 4) (setq dt3 (* Sdo tile tile)))
((= What_next 5) (setq dt4 (* Sdo tile tile)))
((= What_next 6) (setq dt5 (* Sdo tile tile)))
((= What_next 7) (setq dt6 (* Sdo tile tile)))
((= What_next 8) (setq dt7 (* Sdo tile tile)))
((= What_next 9) (setq dt8 (* Sdo tile tile)))
((= What_next 10) (setq dt9 (* Sdo tile tile)))
((= What_next 11) (setq dt10 (* Sdo tile tile)))
)
)
;;;-------------------------------------------
(defun Go ()
(SETQ P (GETPOINT "\nStart point...: "))
(setq oblist (ssadd))
(if (> dt1 0)
(progn
(command "text" "J" "R" p "0" (strcat "S " e1 " (m2) ="))
; (setq obl (entlast) oblist (ssadd obl oblist))
(command "text" (polar p 0.0 (getvar "Textsize")) "0" (rtos dt1 2 3))
; (setq obl (entlast) oblist (ssadd obl oblist))
; (command "attdef" "" e1 e1 dt1 (polar p 0.0 (getvar "Textsize")) "")
; (setq obl (entlast) oblist (ssadd obl oblist))
(setq p (polar p (- (/ pi 2)) (* (getvar "Textsize") 2.0)))
)
)
(if (> dt2 0)
(progn
(command "text" "J" "R" p "0" (strcat "S " e2 " (m2) ="))
(command "text" (polar p 0.0 (getvar "Textsize")) "0" (rtos dt2 2 3))
(setq p (polar p (- (/ pi 2)) (* (getvar "Textsize") 2.0)))
)
)
(if (> dt3 0)
(progn
(command "text" "J" "R" p "0" (strcat "S " e3 " (m2) ="))
(command "text" (polar p 0.0 (getvar "Textsize")) "0" (rtos dt3 2 3))
(setq p (polar p (- (/ pi 2)) (* (getvar "Textsize") 2.0)))
)
)
(if (> dt4 0)
(progn
(command "text" "J" "R" p "0" (strcat "S " e4 " (m2) ="))
(command "text" (polar p 0.0 (getvar "Textsize")) "0" (rtos dt4 2 3))
(setq p (polar p (- (/ pi 2)) (* (getvar "Textsize") 2.0)))
)
)
(if (> dt5 0)
(progn
(command "text" "J" "R" p "0" (strcat "S " e5 " (m2) ="))
(command "text" (polar p 0.0 (getvar "Textsize")) "0" (rtos dt5 2 3))
(setq p (polar p (- (/ pi 2)) (* (getvar "Textsize") 2.0)))
)
)
(if (> dt6 0)
(progn
(command "text" "J" "R" p "0" (strcat "S " e6 " (m2) ="))
(command "text" (polar p 0.0 (getvar "Textsize")) "0" (rtos dt6 2 3))
(setq p (polar p (- (/ pi 2)) (* (getvar "Textsize") 2.0)))
)
)
(if (> dt7 0)
(progn
(command "text" "J" "R" p "0" (strcat "S " e7 " (m2) ="))
(command "text" (polar p 0.0 (getvar "Textsize")) "0" (rtos dt7 2 3))
(setq p (polar p (- (/ pi 2)) (* (getvar "Textsize") 2.0)))
)
)
(if (> dt8 0)
(progn
(command "text" "J" "R" p "0" (strcat "S " e8 " (m2) ="))
(command "text" (polar p 0.0 (getvar "Textsize")) "0" (rtos dt8 2 3))
(setq p (polar p (- (/ pi 2)) (* (getvar "Textsize") 2.0)))
)
)
(if (> dt9 0)
(progn
(command "text" "J" "R" p "0" (strcat "S " e9 " (m2) ="))
(command "text" (polar p 0.0 (getvar "Textsize")) "0" (rtos dt9 2 3))
(setq p (polar p (- (/ pi 2)) (* (getvar "Textsize") 2.0)))
)
)
(if (> dt10 0)
(progn
(command "text" "J" "R" p "0" (strcat "S " e10 " (m2) ="))
(command "text" (polar p 0.0 (getvar "Textsize")) "0" (rtos dt10 2 3))
(setq p (polar p (- (/ pi 2)) (* (getvar "Textsize") 2.0)))
)
)
; (command "Block" "Du" "Y" p oblist "")
(COMMAND "LUPREC" 4 "osmode" 33 "linetype" "S" "Continuous" "" "OOPS")
)
;;;-----------------------------------------------------
(defun WriteToExcel (/ col row x xlApp xlCells)
(setq lst_data '())
(setq lst_data (cons ten lst_data) lst_data (cons (rtos cdon 2 2) lst_data))
(if (> dt1 0) (setq lst_data (cons (rtos dt1 2 3) lst_data)))
(if (> dt2 0) (setq lst_data (cons (rtos dt2 2 3) lst_data)))
(if (> dt3 0) (setq lst_data (cons (rtos dt3 2 3) lst_data)))
(if (> dt4 0) (setq lst_data (cons (rtos dt4 2 3) lst_data)))
(if (> dt5 0) (setq lst_data (cons (rtos dt5 2 3) lst_data)))
(if (> dt6 0) (setq lst_data (cons (rtos dt6 2 3) lst_data)))
(if (> dt7 0) (setq lst_data (cons (rtos dt7 2 3) lst_data)))
(if (> dt8 0) (setq lst_data (cons (rtos dt8 2 3) lst_data)))
(if (> dt9 0) (setq lst_data (cons (rtos dt9 2 3) lst_data)))
(if (> dt10 0) (setq lst_data (cons (rtos dt10 2 3) lst_data)))
(setq lst_data (reverse lst_data))
(vl-load-com)
(setq xlApp (vlax-get-or-create-object "Excel.Application")
xlCells (vlax-get-property
(vlax-get-property
(vlax-get-property
(vlax-invoke-method
(vlax-get-property xlApp "Workbooks")
"Add")
"Sheets")
"Item" 1)
"Cells"))
(vlax-put-property xlCells 'Item 1 1 "M.cat")
(vlax-put-property xlCells 'Item 1 2 "C.Don")
(if (> dt1 0) (vlax-put-property xlCells 'Item 1 3 e1))
(if (> dt2 0) (vlax-put-property xlCells 'Item 1 4 e2))
(if (> dt3 0) (vlax-put-property xlCells 'Item 1 5 e3))
(if (> dt4 0) (vlax-put-property xlCells 'Item 1 6 e4))
(if (> dt5 0) (vlax-put-property xlCells 'Item 1 7 e5))
(if (> dt6 0) (vlax-put-property xlCells 'Item 1 8 e6))
(if (> dt7 0) (vlax-put-property xlCells 'Item 1 9 e7))
(if (> dt8 0) (vlax-put-property xlCells 'Item 1 10 e8))
(if (> dt9 0) (vlax-put-property xlCells 'Item 1 11 e9))
(if (> dt10 0) (vlax-put-property xlCells 'Item 1 12 e10))
(setq row 2 col 1)
(foreach pt lst_data
(vlax-put-property xlCells 'Item row col pt)
(setq col (1+ col))
)
(vla-put-visible xlApp :vlax-true)
(mapcar
(function (lambda (x)
(vl-catch-all-apply (function (lambda ()(if x (vlax-release-object x))))))
)
(list xlCells xlApp)
)
(gc)
(gc)
)
- File *.DCL: Dien_tich_01.dcl
Dientich01 : dialog {
label = " *** - TÝnh DiÖn TÝch Cho C¸c MÆt C¾t Ngang - Hec 13";
fixed_width = center;
:spacer { height=1; }
: row {
fixed_width = true;
children_alignment = centered;
: edit_box {
label = "Ti Le Ve MCN:";
key = "tle";
edit_width = 6;
edit_height = 1;
}
: edit_box {
label = "Ten Mat Cat:";
fixed_width = true;
key = "ten";
edit_width = 6;
edit_height = 1;
}
: edit_box {
label = "Khoang Cach C.Don:";
fixed_width = true;
key = "cdon";
edit_width = 6;
edit_height = 1;
}
}
:spacer { height=1; }
//-----------------------------
: row {
fixed_width = true;
children_alignment = Right;
: toggle {
key = "t1";
mnemonic = "b";
value = "0";
}
: edit_box {
label = "S";
key = "e1";
edit_width = 30;
}
: text {
label = "= ";
key = "s1";
edit_width = 100;
}
: button {
label = "Pick" ;
is_default = true ;
key = "p1" ;
width = 26;
}
}
//-----------------------------
: row {
fixed_width = true;
children_alignment = Right;
: toggle {
key = "t2";
mnemonic = "b";
value = "0";
}
: edit_box {
label = "S";
key = "e2";
edit_width = 30;
}
: text {
label = "= ";
key = "s2";
edit_width = 100;
}
: button {
label = "Pick" ;
is_default = true ;
key = "p2" ;
width = 26;
}
}
//-----------------------------
: row {
fixed_width = true;
children_alignment = Right;
: toggle {
key = "t3";
mnemonic = "b";
value = "0";
}
: edit_box {
label = "S";
key = "e3";
edit_width = 30;
}
: text {
label = "= ";
key = "s3";
edit_width = 100;
}
: button {
label = "Pick" ;
is_default = true ;
key = "p3" ;
width = 26;
}
}
//-----------------------------
: row {
fixed_width = true;
children_alignment = Right;
: toggle {
key = "t4";
mnemonic = "b";
value = "0";
}
: edit_box {
label = "S";
key = "e4";
edit_width = 30;
}
: text {
label = "= ";
key = "s4";
edit_width = 100;
}
: button {
label = "Pick" ;
is_default = true ;
key = "p4" ;
width = 26;
}
}
//-----------------------------
: row {
fixed_width = true;
children_alignment = Right;
: toggle {
key = "t5";
mnemonic = "b";
value = "0";
}
: edit_box {
label = "S";
key = "e5";
edit_width = 30;
}
: text {
label = "= ";
key = "s5";
edit_width = 100;
}
: button {
label = "Pick" ;
is_default = true ;
key = "p5" ;
width = 26;
}
}
//-----------------------------
: row {
fixed_width = true;
children_alignment = Right;
: toggle {
key = "t6";
mnemonic = "b";
value = "0";
}
: edit_box {
label = "S";
key = "e6";
edit_width = 30;
}
: text {
label = "= ";
key = "s6";
edit_width = 100;
}
: button {
label = "Pick" ;
is_default = true ;
key = "p6" ;
width = 26;
}
}
//-----------------------------
: row {
fixed_width = true;
children_alignment = Right;
: toggle {
key = "t7";
mnemonic = "b";
value = "0";
}
: edit_box {
label = "S";
key = "e7";
edit_width = 30;
}
: text {
label = "= ";
key = "s7";
edit_width = 100;
}
: button {
label = "Pick" ;
is_default = true ;
key = "p7" ;
width = 26;
}
}
//-----------------------------
: row {
fixed_width = true;
children_alignment = Right;
: toggle {
key = "t8";
mnemonic = "b";
value = "0";
}
: edit_box {
label = "S";
key = "e8";
edit_width = 30;
}
: text {
label = "= ";
key = "s8";
edit_width = 100;
}
: button {
label = "Pick" ;
is_default = true ;
key = "p8" ;
width = 26;
}
}
//-----------------------------
: row {
fixed_width = true;
children_alignment = Right;
: toggle {
key = "t9";
mnemonic = "b";
value = "0";
}
: edit_box {
label = "S";
key = "e9";
edit_width = 30;
}
: text {
label = "= ";
key = "s9";
edit_width = 100;
}
: button {
label = "Pick" ;
is_default = true ;
key = "p9" ;
width = 26;
}
}
//-----------------------------
: row {
fixed_width = true;
children_alignment = Right;
: toggle {
key = "t10";
mnemonic = "b";
value = "0";
}
: edit_box {
label = "S";
key = "e10";
edit_width = 30;
}
: text {
label = "= ";
key = "s10";
edit_width = 100;
}
: button {
label = "Pick" ;
is_default = true ;
key = "p10" ;
width = 26;
}
}
//-----------------------------
: row {
fixed_height = true;
children_alignment = centered;
: spacer { height=3; }
// : spacer { width=3; }
: button {
label = "Xuat sang Excel" ;
is_default = true ;
key = "excel" ;
width = 20;
}
: button {
label = "OK" ;
is_default = true ;
key = "start" ;
width = 20;
}
: button {
label = "Cancel" ;
width = 20;
is_cancel= true ;
}
// : text_part { label = "paragraph 1"; }
// : paragraph {
// : text_part { label = "paragraph 1"; }
// : spacer { height=0.1; }
// : text_part { label = "paragraph 2"; }
// : text_part { label = "paragraph 3"; }
// }
// : paragraph {
// : concatenation {
// : text_part {label = "column 1";}
// : text_part {label = "column 2";}
// : text_part {label = "column 3";}
// }
// }
:spacer { height=3; }
}
}
- Ảnh minh họa: http://www.cadviet.com/upfiles/3/88193_anh.rar
<<