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

vlax-dump-object problem

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
aqdam1978
2784 Views, 14 Replies

vlax-dump-object problem

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

 

14 REPLIES 14
Message 2 of 15
pbejse
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"))
)

 

Message 3 of 15
hmsilva
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

 

EESignature

Message 4 of 15
aqdam1978
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

 

 

Message 5 of 15
aqdam1978
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

 

 

Message 6 of 15
hmsilva
in reply to: aqdam1978

You're welcome, Abbas

glad you got a solution

 

Henrique

EESignature

Message 7 of 15
john.uhden
in reply to: hmsilva

@hmsilva ,

(@kent1cooper & @paullimapa & @pbejse)

Even turning LOGFILEMODE off and setting QAFLAGS to 2, I can't get the logfile open for read.

Any clues?

John F. Uhden

Message 8 of 15
Sea-Haven
in reply to: john.uhden

I made a get properties that looks at a object Line, circle etc and you can set what properties you want to retrieve. It checks what object "AcDbCircle" so can get layer, center and Radius etc, "AcDbLwpolyline" can get, Co-ords, length, area, layer and so on. Can add more parameters to code. Happy if you want to add some more.

 

 

 

; properties use as a library function
; By Alan H july 2020

(defun AH:cords (obj / co-ords xy )
(setq coordsxy '())
(setq co-ords (vlax-get obj 'Coordinates))
(setq numb (/ (length co-ords) 2))
(setq I 0)
(repeat numb
(setq xy (list (nth (+ I 1) co-ords)(nth I co-ords) ))
(setq coordsxy (cons xy coordsxy))
(setq I (+ I 2))
)
)


(defun AH:chkcwccw (obj / lst newarea)
(setq lst (CORDS obj))
(setq newarea
(/ (apply (function +)
            (mapcar (function (lambda (x y)
                                (- (* (car x) (cadr y)) (* (car y) (cadr x)))))
                    (cons (last lst) lst)
                    l)) 
2.)
)
(if (< newarea  0)
(setq cw "F")
(setq cw "T")
)
)

; Can use reverse in Autocad - pedit reverse in Bricscad.

(defun AH:plprops (obj txt / lst)
(foreach val lst
(cond
((= (strcase val)  "LAY") (setq lay (vla-get-layer obj)))
((= (strcase val) "AREA")(setq area (vla-get-area obj)))
((= (strcase val) "START")(setq start (vlax-curve-getstartpoint obj)))
((= (strcase val) "END" (strcase txt))(setq end (vlax-curve-getendpoint obj)))
((= (strcase val) "LEN" (strcase txt))(setq len (vlax-get obj 'Length)))
((= (strcase val) "CW" (strcase txt))(AH:chkcwccw obj))
((= (strcase val) "CORDS" (strcase txt))(CORDS obj))
((= (strcase val) "MID" (strcase txt))(setq mp (vlax-curve-getpointatdist obj(/ (vlax-get obj 'Length) 2.0))))
)
)
)

(defun AH:lineprops (obj lst / )
(foreach val lst
(cond
((= (strcase val)  "LAY") (setq lay (vlax-get obj 'layer)))
((= (strcase val) "START")(setq start (vlax-get obj 'startpoint)))
((= (strcase val) "END" (strcase txt))(setq end (vlax-get obj 'endpoint)))
((= (strcase val) "LEN" (strcase txt))(setq len (vlax-get obj 'Length)))
((= (strcase val) "MID" (strcase txt))(setq mp (mapcar '* (mapcar '+ (vlax-get obj 'startpoint)(vlax-get obj 'endpoint)) '(0.5 0.5))))
)
)
)

(defun AH:circprops (obj lst / )
(foreach val lst
(cond
((= (strcase val)  "LAY") (setq lay (vlax-get obj 'layer)))
((= (strcase val) "LEN" (strcase txt))(setq len (vlax-get obj 'Circumference)))
((= (strcase val) "RAD" (strcase txt))(setq rad (vla-get-radius obj)))
((= (strcase val) "CEN" (strcase txt))(setq cen (vlax-get obj 'Center)))
((= (strcase val) "AREA" (strcase txt))(setq end (vlax-get obj 'AREA)))
)
)
)

(defun AH:arcprops (obj txtlst)
(foreach val lst
(cond
((= (strcase val) "LAY") (setq lay (vlax-get obj 'layer)))
((= (strcase val) "LEN" (strcase txt))(setq len (vlax-get obj 'length)))
((= (strcase val) "RAD" (strcase txt))(setq rad (vlax-get obj 'radius)))
((= (strcase val) "CEN" (strcase txt))(setq cen (vlax-get obj 'Center)))
((= (strcase val) "START" (strcase txt))(setq start (vlax-get obj 'startpoint)))
((= (strcase val) "END" (strcase txt))(setq area (vlax-get obj 'endpoint)))
((= (strcase val) "AREA" (strcase txt))(setq end (vlax-get obj 'AREA)))
((= (strcase val) "MID" (strcase txt))(setq mp (vlax-curve-getpointatdist obj(/ (vlax-get obj 'ArcLength) 2.0))))
)
)
)

; starts here
; (setq ent (vlax-ename->vla-object (car (entsel "Pick Object "))))
; do a check for object type then use defun
; pick an example below


; many examples copy to command line for testing mix and match 
; (AH:plprops ent '("LAY"))(princ lay)
; (AH:plprops ent '("END"))(princ end)
; (AH:plprops ent '("START"))(princ start)
; (AH:plprops ent '("END" "START"))(princ end)(princ start)
; (AH:plprops ent '("AREA" "LAY" "END" "START"))(princ area)(princ lay)(princ end)(princ start)
; (AH:plprops ent '("START" "AREA" "LAY" "CW"))(princ start)(princ area)(princ cw)
; (AH:plprops ent '("start" "END" "CORDS" "cw"))(princ start)(princ end)(princ coordsxy)(princ cw)
; (AH:plprops ent '("CW"))(princ cw)
; (AH:plprops ent '("AREA"))(princ area)
; (AH:plprops ent '("CORDS"))(princ coordsxy)
; (AH:lineprops ent "len"))(princ len)
; (AH:lineprops ent '("len" "lay"))(princ len)(princ lay)
; (AH:lineprops ent '("lay" "end" "start" "len"))(princ len)(princ lay)(princ start)(princ end)
; (AH:circprops ent '("lay" "rad" "area" "cen"))(princ lay)(princ rad)(princ area)(princ cen)
; (AH:circprops ent '("lay" "rad"))
; (AH:arcprops ent '("lay" "rad"))


 

 

Message 9 of 15
hmsilva
in reply to: john.uhden

@john.uhden probably the log file was left open for editing.

Try to restart AutoCAD.

 

Hope this helps,
Henrique

EESignature

Message 10 of 15
john.uhden
in reply to: Sea-Haven

@Sea-Haven ,

Major difference in goals...

You know the properties you want to retrieve.

I want to find out all the properties an object has.

John F. Uhden

Message 11 of 15
Sea-Haven
in reply to: john.uhden

Need a super dumpit. Look at a dim how many properties.

Message 12 of 15
john.uhden
in reply to: Sea-Haven

@Sea-Haven ,

@getprops revealed that a dimension has 110 properties.

John F. Uhden

Message 13 of 15
Sea-Haven
in reply to: john.uhden

Yep (dumpallproperties (car (entsel "\nPick object "))) have a look at file. Interesting for pline no co-ordinates ?

 

Message 14 of 15
john.uhden
in reply to: Sea-Haven

@Sea-Haven ,

Good job!

At least we know that plines do have 'Coordinates properties.

John F. Uhden

Message 15 of 15
Kent1Cooper
in reply to: Sea-Haven


@Sea-Haven wrote:

.... (dumpallproperties .... for pline no co-ordinates ?


No, but near the end it does have Vertices.  But I see from your log file that you have the same problem I have, in that a lot of the entries say "Failed to get value":

....

Vertices (type: AcDbPolylineVertex)
  Item 0:
  Bulge (type: double) = Failed to get value
  ClassName (type: AcString) (RO) =
  EndWidth (type: double) (LocalName: End segment width) = Failed to get value
  Id (type: int) = Failed to get value
  IsA (type: AcRxClass*) (RO) = AcRxBoxedValueOnStack
  LocalizedName (type: AcString) (RO) =
  Position/X (type: double) (LocalName: Vertex X) = Failed to get value
  Position/Y (type: double) (LocalName: Vertex Y) = Failed to get value
  StartWidth (type: double) (LocalName: Start segment width) = Failed to get value

....

and it goes on to Item 1, etc.

 

I haven't found a way to (getpropertyvalue) those, but keep getting

  ; error: ADS request error

I assume that's because of the "Failed" part.  For something that at least it can "read," this format works:

  (getpropertyvalue (entlast) "Vertices" 1 "LocalizedName")

at least doesn't return the error, but rather:
  ""

where "Vertices" is what the AutoLisp Reference calls the "collection name," and 1 is the index, then the property name.  So if it didn't Fail with those Position values, doing the same with "Position" or maybe separately "Position/X" and "Position/Y" should get the information.  But I have no idea how to get around the Failures.

Kent Cooper, AIA

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

Post to forums  

Autodesk Design & Make Report

”Boost