Object Properties

Object Properties

john.uhden
Mentor Mentor
661 Views
8 Replies
Message 1 of 9

Object Properties

john.uhden
Mentor
Mentor

Is there a way to obtain the list of properties for any selected object using VLisp?
And also whether each property is read-only?

Or must I dump the object and gather the properties from the text screen?

John F. Uhden

0 Likes
Accepted solutions (1)
662 Views
8 Replies
Replies (8)
Message 2 of 9

Kent1Cooper
Consultant
Consultant

I'm wondering what you mean by "obtain," if viewing them on or gathering them from the text screen is not what you mean.  Save them to variables?  Put them into an external text or spreadsheet file, perhaps?  Something else?  [Not that I have any idea how to do either of those, anyway, but still....]

Kent Cooper, AIA
0 Likes
Message 3 of 9

paullimapa
Mentor
Mentor

try this modified code from @Kent1Cooper 

; LGDO log of vl dump data modified from:
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/exracting-list-properties-of-objects-into-txt-file/m-p/9501656#M399570
; by Kent1Cooper https://forums.autodesk.com/t5/user/viewprofilepage/user-id/69526
(defun C:LGDO (/ *error* source data txtline) ; = Log of Geometric Data Only
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg))
    ); if
    (setvar 'qaflags 0); reset
    (princ)
  ); defun -- *error*
  (if (findfile (getvar 'logfilename)); log file already exists
    (progn ; then
      (setvar 'logfilemode 0); in case currently on
      (setq source (open (getvar 'logfilename) "w")); empty any current content
      (close source)
    ); progn
  ); if
  (prompt "\nTo Export their Properties,")
  
;  (if (setq ss (ssget '((0 . "*LINE,ARC,CIRCLE,ELLIPSE"))))
    (if (setq ss(ssget "_+.:E:S"))
    ; [will provide its own "Select objects:" prompt]
    ; *LINE covers Line/Polyline/Spline/Xline/Mline
    (progn ; then
      (setvar 'qaflags 2)
      (setvar 'logfilemode 1); turn on log file recording
;      (command "_.list" ss "")
      (vlax-dump-object (vlax-ename->vla-object (ssname ss 0)))
      (setvar 'logfilemode 0); turn off
      (setvar 'qaflags 0)
    ); progn
  ); if
;  (setq
;    source (open (getvar 'logfilename) "r"); log file just created
;    data (open "X:/Your/File/Path/YourFilename.txt" "w"); reduced-content file <-- EDIT this
;    data (getfiled "Select a Text File" (getvar"dwgprefix") "txt" 1)
;  ); setq
;  (while (setq txtline (read-line source)); step through lines in file
;    (if
;      (not
;        (wcmatch
;          (vl-string-left-trim " " txtline); remove leading spaces
;          "`[ A*,_.li*,Sel*,Spa*,Col*,Line*,Tra*,Thi*,Han*,Pre*,Ent*,Com*"
;            ;; beginnings of unwanted-line content [could be more]
;        ); wcmatch
;      ); not
;      (write-line txtline data); then -- put line into geometric data file
;    ); if
;  ); while
;  (close source)
;  (close data)
  (startapp "Notepad" (findfile (getvar 'logfilename)))
  (princ)
); defun

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 4 of 9

john.uhden
Mentor
Mentor

@paullimapa ,

Well if @Kent1Cooper wrote that then why does he not remember that?
Anyway, I can't seem to be able to read the log file, I think because AutoCAD has it open for write.

Can you explain what QAFLAGS does in this example?  Is that the difference?

John F. Uhden

0 Likes
Message 5 of 9

Kent1Cooper
Consultant
Consultant

@john.uhden wrote:

Well if @Kent1Cooper wrote that then why does he not remember that? ....


[Even if I recalled that routine, I would have needed to have an answer to Message 2 before considering whether that was even relevant to what you want to "obtain."]

Kent Cooper, AIA
0 Likes
Message 6 of 9

paullimapa
Mentor
Mentor

since @Kent1Cooper has written so much code answering so many questions, it's no surprise if he doesn't remember them all.

read up on qaflags on this link

but basically when set to 2 the text screen listings won't pause

the code should take care of activating your logfile with this line:

(setvar 'logfilemode 1); turn on log file recording

and at the end I just added a line to launch notepad so you can see what's in the log:

(startapp "Notepad" (findfile (getvar 'logfilename)))

does the code not do that for you?

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 7 of 9

john.uhden
Mentor
Mentor

@paullimapa ,

Since I couldn't open the logfile for read, I decided to vla-copy it and open the copy, but it wouldn't open for read either.  I haven't tried it, but it would sure be nice if you could (setq data (vlax-dump-object object)).  I really don't care what format it would return because I'm sure I could deal with it.

I guess it's a wish-list item.

John F. Uhden

0 Likes
Message 8 of 9

Sea-Haven
Mentor
Mentor
0 Likes
Message 9 of 9

john.uhden
Mentor
Mentor
Accepted solution

@Sea-Haven , @paullimapa , @Kent1Cooper ,

I think that may have helped a little.

This appears to work the way I wanted...

(defun @getprops (e / mode old new file copy fp line lines prop props)
  ;; v1.0 (6-21-2023) John F. Uhden
  ;; function to return a list of all of an object's exposed properties.
  ;; in the format '(("prop1" 0)("prop2" 1) etc.)
  ;;   where e is an EName
  ;;         0 means Read-Only
  ;;         1 means modifiable
  ;; NOTE that you will not find 'Color as a property, but it is.
  (and  ;; This is in the Kosterian style
    (setq mode (getvar "logfilemode"))
    (setq old (getvar "logfilepath"))
    (setq new (setvar "logfilepath" "C:\\Temp"))
    (setvar "logfilemode" 1)
    (setvar "qaflags" 2)
    (princ "GETPROPS")
    (vlax-dump-object (vlax-ename->vla-object e))
    (PRINC)(PRINC)
    (setvar "logfilemode" mode)
    (setvar "logfilepath" old)
    (setvar "logfilemode" 0)
    (setq file (getvar "logfilename"))
    (or 
      (setq fp (open file "r"))
      (and
        (setq copy (strcat new "\\Copy.log"))
        (vl-file-copy file copy)
        (setq copy (findfile copy))
        (setq fp (open copy "r"))
      )
      (prompt "\nCan't open file for read.")
    )
    (while (setq line (read-line fp))
      (setq lines (cons line lines)) ; reverse order
    )
    (or (close fp) 1)
    (setvar "qaflags" 0)
    (setvar "logfilemode" mode)
    (or (not copy)(vl-file-delete copy) 1)
    (while (/= (setq line (car lines)) "; Property values:")
      (and
        (= (substr line 1 2) "; ")
        (setq prop (vl-string-trim "; " line))
        (setq prop (substr prop 1 (vl-string-search " " prop)))
        (if (vl-string-search "(RO)" line)
          (setq prop (list prop 0))
          (setq prop (list prop 1))
        )
      ) ; and
      (setq lines (cdr lines))
      (setq props (cons prop props)) ;; which also reverses the list
    ) ; while
  ) ; and
  props ;; return the list of properties
)

 

John F. Uhden

0 Likes