Need a lisp that could dump the values of a list command in a text fil placed in a folder C:\user121\list.txt.
Thx
Best regards.
Hi elfert,
try this one:
(defun c:List2TXT ( / e) (vl-file-delete (getvar "logfilename")) (setvar 'Qaflags 2) (command "_Logfileon") (setq e (car(entsel "\nPlease Select Just One Object!:"))) (command "_list" e "") (vlax-dump-object (vlax-ename->vla-object e) t) (command "_LogfileOff") (setvar 'Qaflags 0) (startapp "Notepad" (getvar "Logfilename")) ) ;| Qaflags: 1 : ^C in menu macro cancels grips (acts like keyboard <Esc>). 2 : no pause during text screen listings. 4 : no "alert" dialogs (text display instead). 128 : accepts "screen picks" (point lists) via (command) function. 512 : sets Bind type to insert in R14 |;
hope to help you 🙂
Also, Special thanks to Pbejse 🙂
Abbas,
@elfert wrote:
Need a lisp that could dump the values of a list command in a text fil placed in a folder C:\user121\list.txt.
Thx
Best regards.
my attempt...
(defun c:MyList ( / A DUMP FILE FILEUSER FOPEN FOPEN1 ITM LINE LOGF NUM OLDLOGFILE OLDQAFLAGS REST SS STR) (if (and (findfile "C:\\user121") (setq a (car (entsel "\nSelect an object to list: "))) );; and (progn (setq OldLogFile (getvar 'logfilemode) OldQaflags (getvar 'QaFlags) );; setq (setvar 'logfilemode 1) (setvar 'QaFlags 2) (setq file (getvar "logfilename")) (command "_.list" a "") (graphscr) (setvar 'logfilemode OldLogFile) (setvar 'QaFlags OldQaflags) (if (setq fopen (open file "r")) (progn (while (setq line (read-line fopen)) (if (> (strlen line) 0) (setq logf (cons line logf)) );; if );; while (close fopen) );; progn );; if (if (setq fileuser "C:\\user121\\list.txt") (progn (setq rest (member "Select objects: " logf) num (- (length logf) (length rest)) itm 1 );; setq (while (< itm num) (setq str (nth itm logf) dump (cons str dump) itm (1+ itm) );; setq );; while (setq fopen1 (open fileuser "a")) (write-line "" fopen1) (foreach x dump (write-line x fopen1) );; foreach (close fopen1) );;progn );; if );; progn (prompt "\nOr you didn't select an object, or you don't have the \"C:\\user121\" directory...") );; if (princ) );; MyList
HTH
Henrique
My version:
(defun c:mylist ( / *error* cnt dir lgf lin rfd sel tar val var wfd ) (setq tar "C:\\user121\\list.txt") ;; Target list file (defun *error* ( msg ) (if (= 'file (type rfd)) (close rfd) ) (if (= 'file (type wfd)) (close wfd) ) (if (and (= 0 (cadr val)) (setq lgf (findfile (getvar 'logfilename)))) (vl-file-delete lgf) ) (mapcar 'setvar var val) (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))) (princ (strcat "\nError: " msg)) ) (princ) ) (if (and (setq cnt 0) (= 1 (getvar 'logfilemode)) (setq lgf (findfile (getvar 'logfilename))) (setq rfd (open lgf "r")) ) (progn (while (read-line rfd) (setq cnt (1+ cnt))) (setq rfd (close rfd)) ) ) (if (setq sel (ssget)) (progn (setq var '(cmdecho logfilemode qaflags) val (mapcar 'getvar var) ) (mapcar 'setvar var '(0 1 2)) (command "_.list" sel "") (graphscr) (cond ( (not (or (vl-file-directory-p (setq dir (vl-filename-directory tar))) (vl-mkdir dir) ) ) (princ (strcat "\nUnable to create target directory: " dir)) ) ( (not (setq lgf (findfile (getvar 'logfilename)))) (princ "\nUnable to locate log file.") ) ( (not (setq rfd (open lgf "r"))) (princ "\nUnable to open log file for reading.") ) ( (not (setq wfd (open tar "w"))) (princ "\nUnable to open target list file for writing.") ) ( t (repeat (+ 5 cnt)(read-line rfd)) (while (setq lin (read-line rfd)) (write-line lin wfd)) ) ) (*error* nil) ) ) (princ) )
Fixed:
(defun c:mylist ( / *error* cnt dir lgf lin rfd sel tar val var wfd ) (setq tar "C:\\user121\\list.txt") ;; Target list file (defun *error* ( msg ) (if (= 'file (type rfd)) (close rfd) ) (if (= 'file (type wfd)) (close wfd) ) (if (and (= 0 cnt (cadr val)) (setq lgf (findfile (getvar 'logfilename)))) (vl-file-delete lgf) ) (mapcar 'setvar var val) (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))) (princ (strcat "\nError: " msg)) ) (princ) ) (if (and (setq cnt 0) (setq lgf (findfile (getvar 'logfilename))) (setq rfd (open lgf "r")) ) (progn (while (read-line rfd) (setq cnt (1+ cnt))) (setq rfd (close rfd)) ) ) (if (setq sel (ssget)) (progn (setq var '(cmdecho logfilemode qaflags) val (mapcar 'getvar var) ) (mapcar 'setvar var '(0 1 2)) (command "_.list" sel "") (graphscr) (cond ( (not (or (vl-file-directory-p (setq dir (vl-filename-directory tar))) (vl-mkdir dir) ) ) (princ (strcat "\nUnable to create target directory: " dir)) ) ( (not (setq lgf (findfile (getvar 'logfilename)))) (princ "\nUnable to locate log file.") ) ( (not (setq rfd (open lgf "r"))) (princ "\nUnable to open log file for reading.") ) ( (not (setq wfd (open tar "w"))) (princ "\nUnable to open target list file for writing.") ) ( t (repeat (+ 2 cnt)(read-line rfd)) (while (setq lin (read-line rfd)) (write-line lin wfd)) ) ) (*error* nil) ) ) (princ) )