Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

List command dumping to text file locally.

11 REPLIES 11
Reply
Message 1 of 12
elfert
1110 Views, 11 Replies

List command dumping to text file locally.

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.

11 REPLIES 11
Message 2 of 12
pbejse
in reply to: elfert


@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.


 

look into

 

LOGFILEON

LOGFILENAME

LOGFILEMODE

LOGFILEPATH

QAFLAGS <-- 2 

 

 

Message 3 of 12
aqdam1978
in reply to: elfert

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,

 

 

 

Message 4 of 12
hmsilva
in reply to: elfert


@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

EESignature

Message 5 of 12
Lee_Mac
in reply to: hmsilva

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)
)
Message 6 of 12
hmsilva
in reply to: Lee_Mac

As usual, nice one Lee!

 

Just one note, if Logfile exists, all content is copied to list.txt... Smiley Wink

 

Cheers

Henrique

EESignature

Message 7 of 12
Lee_Mac
in reply to: hmsilva


@hmsilva wrote:

As usual, nice one Lee!


 

Thank you Henrique! Smiley Happy

 


@hmsilva wrote:

Just one note, if Logfile exists, all content is copied to list.txt... Smiley Wink


 

Are you sure?

 

EDIT: Do you mean if LOGFILEMODE=0 and the log file exists?

Message 8 of 12
hmsilva
in reply to: Lee_Mac


Lee_Mac wrote:
 

EDIT: Do you mean if LOGFILEMODE=0 and the log file exists?



yes...

EESignature

Message 9 of 12
Lee_Mac
in reply to: hmsilva

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)
)
Message 10 of 12
hmsilva
in reply to: Lee_Mac


@Lee_Mac wrote:

Fixed:


Great thinking!

Nicely done, Lee.

 

Cheers

Henrique

EESignature

Message 11 of 12
Lee_Mac
in reply to: hmsilva


@hmsilva wrote:

@Lee_Mac wrote:

Fixed:


Great thinking!


Thanks Henrique! Smiley Happy

Message 12 of 12
hmsilva
in reply to: Lee_Mac


@Lee_Mac wrote:
Thanks Henrique! Smiley Happy

You're welcome, Lee. Smiley Happy
It's always a pleasure to see a code so well coded!

 

Henrique

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost