Originally Posted by
bartstienaers
We want AutoCAD to control Excel. What we mean is: if we draw a rectangle in AutoCAD and we give it dimensions for example length 100, width 50. With a simple action we want those 2 dimensions to appear in excel.
Thanks Bart
------------- ~\\|//~ ------------
------------- [o]-[o] -------------
-------ooO---(_)---Ooo--------
Dear Bart,
Please try my program.
But first notice de variable DirExcel, you must change it (to let AutoCAD find Excel).
Email hofcad@yahoo.com
Groetjes HofCAD CSI
Code:
(setq DirExcel "C:\\progra~1\\micros~1\\office\\")
;;;
;;; HofREC
;;;
(Defun C:HofRec ()
(setq ~CMD (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
(setq ~OSM (getvar "OSMODE"))
(setvar "OSMODE" 0)
(setq naam "REC1")
(setq lop (getpoint "\nLeft lower corner.: "))
(setq rbp (getcorner lop "\nRight upper corner.: "))
(command "_PLINE"
lop
"W"
"0"
"0"
(list (car rbp) (cadr lop))
rbp
(list (car lop) (cadr rbp))
"C"
)
(setq e1 (entlast))
(setq b (- (car rbp) (car lop)))
(setq h (- (cadr rbp) (cadr lop)))
(regapp "HOFREC")
(setq xd (list -3
(list "HOFREC"
(cons 1000 naam)
(cons 1002 "{")
(cons 1010 lop)
(cons 1040 b)
(cons 1041 h)
(cons 1042 1.0)
(cons 1002 "}")
)
)
)
(setq ed1 (entget e1)
edx1 (append ed1 (list xd))
)
(entmod edx1)
(princ)
(setvar "OSMODE" ~OSM)
(setvar "CMDECHO" ~CMD)
)
;;;
;;;REC2XL
;;;
(defun c:REC2XL ()
(defun dxf (code elist)
(cdr (assoc code elist))
)
(setq naam nil)
(if (setq ss (ssget "X" '((-3 ("HOFREC")))))
(progn
(setq $acv (atoi (substr (getvar "ACADVER") 1 2)))
(setq teknaam (getvar "dwgname"))
(if (> $acv 13)
(setq teknaam (substr teknaam 1 (- (strlen teknaam) 4)))
)
(setq OutFile (strcat "c:\\temp\\" teknaam ".xls"))
(setq filedes (open OutFile "w"))
(mapcar '(lambda (x) (princ X filedes))
'("\t" "\t"
"Rectangle to Excel by HofCAD CSI" "\n"
"\n" "\t" "Lower left" "\n"
"Rectang" "\t" "X" "\t"
"Y" "\t" "Z" "\t"
"Width" "\t" "Height" "\t"
"Area" "\t" "Changed" "\n"
)
)
(setq ssmax (sslength ss)
i 0
)
(while (< i ssmax)
(setq en (ssname ss i)
ed (entget en '("HOFREC"))
xd (dxf -3 ed)
)
(setq b (- (cadr (nth 18 ed)) (cadr (nth 14 ed))))
(setq h (- (caddr (nth 22 ed)) (caddr (nth 18 ed))))
(setq lop (nth 14 ed))
(print lop)
(setq px (car lop)
px (cadr lop)
py (caddr lop)
)
(print px)
(print py)
(setq pz (cdr (nth 12 ed)))
(print pz)
(setq lop_org (dxf 1010 (cdar xd)))
(setq px_org (car lop_org)
py_org (cadr lop_org)
pz_org (caddr lop_org)
)
(setq naam (dxf 1000 (cdar xd)))
(setq b_org (dxf 1040 (cdar xd)))
(setq h_org (dxf 1041 (cdar xd)))
(setq opp (strcat "=E" (itoa (+ i 5)) "*F" (itoa (+ i 5))))
(if (or (/= px px_org)
(/= py py_org)
(/= pz pz_org)
(/= b B_org)
(/= h h_org)
)
(setq chg "Yes")
(setq chg "No")
)
(mapcar '(lambda (x) (princ X filedes))
(list naam "\t" px "\t" py "\t" pz "\t"
b "\t" h "\t" opp "\t" chg "\n"
)
)
(setq i (1+ i))
)
)
)
(close filedes)
(if (= naam nil)
(print "Geen Excel rechthoeken.")
(progn
(princ (strcat "\n " OutFile " is aangemaakt.")
(Startapp (strcat DirExcel "EXCEL") OutFile)
)
)
)
(princ)
)
(Print "HofREC loaded")
(textscr)
(princ
"\n********************IMPORTANT******************* ***********\n"
)
(princ "Draw rectangles with HofRec")
(princ "Export to EXCEL with Rec2XL")
(princ)