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
Solved! Go to Solution.
Solved by hmsilva. Go to Solution.
@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")) )
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
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
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
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"))
@john.uhden probably the log file was left open for editing.
Try to restart AutoCAD.
Hope this helps,
Henrique
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
Yep (dumpallproperties (car (entsel "\nPick object "))) have a look at file. Interesting for pline no co-ordinates ?
@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.