Visual LISP, AutoLISP and General Customization

Reply
Mentor
aqdam1978
Posts: 265
Registered: ‎11-05-2008
Message 1 of 6 (447 Views)
Accepted Solution

vlax-dump-object problem

447 Views, 5 Replies
03-16-2013 09:13 AM

Hi,

 

I prepared a code to dump properties of selected object to a text file:

(defun elist ( e / d)
	(cond
        (   (or(and(eq 'ENAME (type e)) (setq d (entget e)))
               (and (listp e) (setq d e) (setq e (cdr (assoc -1 d))))
            )
            (princ "(\n" des)
            (foreach pair d
                (princ " " des)
				(prin1 pair des)
                (princ "\n" des)
            )
            (princ ")\n\n\n" des)
			
			(princ "\n");;;in text screen (command prompt window)
			(vlax-dump-object (vlax-ename->vla-object e) T);; dump in text screen :(
			
			(princ "------------------------ Nested Object: ----------------------------\n" des)
            (if (= 1 (cdr (assoc 66 d)))
                (while
                    (progn
						(elist (setq e (entnext e)))
                        (not (eq "SEQEND" (cdr (assoc 0 (entget e)))))
                    )
                )
            )
        )
    )
    (princ)
)

(defun c:AA-EE ( / des)
	(setq des (open "elist.txt" "w" ))
	(repeat 10 (princ "\n"))
	(elist (car (entsel)))
	(close des)
	(textpage)
	(startapp "Notepad" "elist.txt")
)

;|
usage:
load this file
type AA-EE in command window
|;

(test it on 1 simple object and one complex object e.g. a title block)

 It works fine, but "vlax-dump-object" command just sent datas to text screen and I can't control it to send its datas to a text file.

 

does anybody has an idea?

 

Thanks,

 

Abbas

 

*Expert Elite*
pbejse
Posts: 2,406
Registered: ‎11-24-2009
Message 2 of 6 (415 Views)

Re: vlax-dump-object problem

03-16-2013 10:51 PM in reply to: aqdam1978

aqdam1978 wrote:

 

 

does anybody has an idea?

 

Thanks,

 

Abbas

 


(defun c:Demo ()
  (setvar 'Qaflags 2)
  (command "_Logfileon")
  (vlax-dump-object (vlax-ename->vla-object (car (entsel "\nSelect Object:"))) t)
  (command "_LogfileOff")
  (setvar 'Qaflags 0)
  (startapp "Notepad" (getvar "Logfilename"))
)

 

*Expert Elite*
hmsilva
Posts: 2,639
Registered: ‎12-17-2004
Message 3 of 6 (397 Views)

Re: vlax-dump-object problem

03-17-2013 07:45 AM in reply to: aqdam1978

aqdam1978 wrote:

...

It works fine, but "vlax-dump-object" command just sent datas to text screen and I can't control it to send its datas to a text file.

...

 

Abbas,

as pbejse already shown, the only way I also know is through the "logfile", and as you wrote, "I can't control it to send its datas to a text file", here is an example on how you can do that, in this "test", the data from "vlax-dump-object" is stored in a variable named "dump", this way it is possible to send all the information to your text file.

 

 

(defun c:test (/ obj file fopen line logf rest str itm)
  (if (setq obj (vlax-ename->vla-object (car (entsel))))
    (progn
      (setvar "logfilemode" 1)
      (setq file  (getvar "logfilename")
	    dump  nil
	    logf nil
      );; setq
      (vlax-dump-object obj T)
      (princ)
      (setvar "logfilemode" 0)
      (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 rest (member "; Property values:" logf))
	(setq num (+ (- (length logf) (length rest)) 2))
      );; if
      (setq itm 0)
      (while (< itm num)
	(setq str  (nth itm logf)
	      dump (cons str dump)
	      itm  (1+ itm)
	);; setq
      );; while
    );; progn
  );; if
  (princ)
);; test

 

hope that helps
Henrique

 

Mentor
aqdam1978
Posts: 265
Registered: ‎11-05-2008
Message 4 of 6 (393 Views)

Re: vlax-dump-object problem

03-17-2013 08:08 AM in reply to: pbejse

Hi Pbejse,

 

Thank you for your code.

You teach me new things in AutoCAD!

 

Thanks aqgain,

 

Abbas

-----------------------------------------------

LOGFILEMODE
LOGFILEPATH
LOGFILENAME
LOGFILEON
LOGFILEOFF

 

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

 

 

Mentor
aqdam1978
Posts: 265
Registered: ‎11-05-2008
Message 5 of 6 (383 Views)

Re: vlax-dump-object problem

03-17-2013 09:45 AM in reply to: hmsilva

Hi Henrique,

 

Thanks for your code, I updated my code with your code! and it's all I wanted!

 

(defun LOG2lst (e / file fopen line logf rest str itm)
  (setvar "logfilemode" 1)
  (setq	file (getvar "logfilename")
	dump nil
	logf nil
  )
  ;; setq
  (vlax-dump-object e T)
  (princ)
  (setvar "logfilemode" 0)
  (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 rest (member "; Property values:" logf))
    (setq num (+ (- (length logf) (length rest)) 2))
  )
  ;; if
  (setq itm 0)
  (while (< itm num)
    (setq str  (nth itm logf)
	  dump (cons str dump)
	  itm  (1+ itm)
    )
    ;; setq
  )
  ;; while
  (princ)
  DUMP
)
;; LOG2lst


(defun elist (e / d d1 i)
  (cond
    ((or (and (eq 'ENAME (type e)) (setq d (entget e)))
	 (and (listp e) (setq d e) (setq e (cdr (assoc -1 d))))
     )
     (princ "(\n" des)
     (foreach pair d
       (princ " " des)
       (prin1 pair des)
       (princ "\n" des)
     )
     (princ ")\n\n\n" des)

     (setq d1 (LOG2lst (vlax-ename->vla-object e)))
     (setq i 0)
     (repeat (length d1)
       (write-line (vl-string-translate ";" " " (nth i d1)) des)
       (setq i (1+ i))
     )

     (princ
       "\n\n------------------------ Nested Object: ----------------------------\n\n"
       des
     )
     (if (= 1 (cdr (assoc 66 d)))
       (while
	 (progn
	   (elist (setq e (entnext e)))
	   (not (eq "SEQEND" (cdr (assoc 0 (entget e)))))
	 )
       )
     )
    )
  )
  (princ)
)

(defun c:AA-EE (/ des)
  (setq des (open "elist.txt" "w"))
  (repeat 10 (princ "\n"))
  (elist (car (entsel)))
  (close des)
  (textpage)
  (startapp "Notepad" "elist.txt")
)

 ;|
usage:
load this file
type AA-EE in command window
|;

 

Thanks again,

 

Abbas

 

 

*Expert Elite*
hmsilva
Posts: 2,639
Registered: ‎12-17-2004
Message 6 of 6 (381 Views)

Re: vlax-dump-object problem

03-17-2013 09:48 AM in reply to: aqdam1978

You're welcome, Abbas

glad you got a solution

 

Henrique

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community