hello,
anybody know lisp code's fragment, how exporti info to excel,
such as select line, and export to excel line's length,
but I need only lisp code, no data extraction
Solved! Go to Solution.
Solved by Lee_Mac. Go to Solution.
Solved by hmsilva. Go to Solution.
Hi CADGISCODES,
the easiest way is to create a .csv file, then open Excel and import the .csv file as text...
i.e.
(defun c:test (/ *error* ent file fname i line ss) (vl-load-com) (defun *error* (msg) (if file (close file) ) (cond ((not msg)) ((member msg '("Function cancelled" "quit / exit abort"))) ((princ (strcat "\n** Error: " msg " ** "))) );; cond (princ) );;; *error* (if (and (not (prompt "\n<<< Select the lines >>>")) (setq ss (ssget '((0 . "LINE")))) (setq fname (getfiled "Enter the file name: " (strcat (getvar "dwgprefix") (vl-filename-base (getvar "dwgname")) ) "csv" 1 ) ) );; and (progn (setq file (open fname "w")) (setq line "Layer\tlength\tStart Point\tEnd Point") (write-line line file) (repeat (setq i (sslength ss)) (setq ent (entget (ssname ss (setq i (1- i))))) (setq line (strcat (cdr (assoc 8 ent)) "\t" (rtos (distance (cdr (assoc 10 ent)) (cdr (assoc 11 ent))) 2 3 ) "\t" (rtos (car (cdr (assoc 10 ent))) 2 3) "," (rtos (car (cddr (assoc 10 ent))) 2 3) "," (rtos (car (cdddr (assoc 10 ent))) 2 3) "\t" (rtos (car (cdr (assoc 11 ent))) 2 3) "," (rtos (car (cddr (assoc 11 ent))) 2 3) "," (rtos (car (cdddr (assoc 11 ent))) 2 3) ) ) (write-line line file) );; repeat (close file) );; progn );; if (*error* nil) (princ) );;; test
HTH
Henrique
The code could become slightly more concise through the use of mapcar, e.g.:
(defun c:test ( / *error* des enx ept idx sel spt txt ) (defun *error* ( msg ) (if (= 'file (type des)) (close des)) (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")) (princ (strcat "\nError: " msg)) ) (princ) ) (if (and (setq sel (ssget '((0 . "LINE")))) (setq txt (getfiled "Create output file" "" "txt" 1)) ) (if (setq des (open txt "w")) (progn (write-line "Layer\tLength\tSx\tSy\tSz\tEx\tEy\tEz" des) (repeat (setq idx (sslength sel)) (setq enx (entget (ssname sel (setq idx (1- idx)))) spt (cdr (assoc 10 enx)) ept (cdr (assoc 11 enx)) ) (write-line (strcat (cdr (assoc 8 enx)) (apply 'strcat (mapcar '(lambda ( x ) (strcat "\t" (rtos x 2 3))) (cons (distance spt ept) (append spt ept)) ) ) ) des ) ) (setq des (close des)) ) (princ (strcat "\nUnable to open \"" txt "\" for writing.")) ) ) (princ) )