Author Topic: vlax-dump-object->List  (Read 1250 times)

0 Members and 1 Guest are viewing this topic.

Andrea

  • Water Moccasin
  • Posts: 2307
vlax-dump-object->List
« on: December 15, 2016, 03:40:58 pm »
Hi all,.

I'm looking to get a list of dump object..

something like:
Code: [Select]
(("Application (RO) =" #<VLA-OBJECT IAcadApplication 00007ff796ce44f8>)
  ("Area =" 4807.45)
  ("Center =" (2831.45 1200.59 0.0))
  ("Circumference =" 245.789)
  ("Diameter =" 78.2371)
  ....
  ....
  )

or even Text can be useful..
something like
Code: [Select]
(vl-princ-to-string (vlax-dump-object (vlax-ename->vla-object (car (entsel))) t))

Maybe anything simple to do that I don't know ? or any suggestion ?
Thank you
Keep smile...

Lee Mac

  • Seagull
  • Posts: 11836
  • AutoCAD 2015 Windows 7 London, England
Re: vlax-dump-object->List
« Reply #1 on: December 15, 2016, 03:57:47 pm »
The following is built on code I developed in conjunction with MP during a conversation a few years ago, it may prove useful:

Code: [Select]
(defun vlax-dump-object->list ( obj mth )
    (append
        (list
            (mapcar
                (function
                    (lambda ( prp )
                        (list prp (vlax-get obj prp))
                    )
                )
                (_GetObjectProperties obj)
            )
        )
        (if mth (list (_GetObjectMethods obj)))
    )
)

(defun _GetObjectProperties ( obj )
    (vl-remove-if-not
        (function
            (lambda ( prp )
                (vlax-property-available-p obj prp)
            )
        )
        (_GetVlaProperties)
    )
)

(defun _GetObjectMethods ( obj )
    (vl-remove-if-not
        (function
            (lambda ( mth )
                (vlax-method-applicable-p obj mth)
            )
        )
        (_GetVlaMethods)
    )
)

(defun _GetVlaAtoms ( )
    (eval
        (list 'defun '_GetVlaAtoms '( )
            (list 'quote
                (vl-sort
                    (vl-remove-if-not
                        (function
                            (lambda ( sym )
                                (wcmatch (vl-symbol-name sym) "vla`-*")
                            )
                        )
                        (atoms-family 0)
                    )
                    (function
                        (lambda ( a b )
                            (<
                                (vl-symbol-name a)
                                (vl-symbol-name b)
                            )
                        )
                    )
                )
            )
        )
    )
    (_GetVlaAtoms)
)

(defun _GetVlaProperties ( )
    (eval
        (list 'defun '_GetVlaProperties '( )
            (list 'quote
                (mapcar
                    (function
                        (lambda ( sym )
                            (substr (vl-symbol-name sym) 9)
                        )
                    )
                    (vl-remove-if-not
                        (function
                            (lambda ( sym )
                                (wcmatch (strcase (vl-symbol-name sym)) "VLA`-GET`-*")
                            )
                        )
                        (_GetVlaAtoms)
                    )
                )
            )
        )
    )
    (_GetVlaProperties)
)

(defun _GetVlaMethods ( )
    (eval
        (list 'defun '_GetVlaMethods '( )
            (list 'quote
                (mapcar
                    (function
                        (lambda ( sym )
                            (substr (vl-symbol-name sym) 5)
                        )
                    )
                    (vl-remove-if
                        (function
                            (lambda ( sym )
                                (wcmatch (strcase (vl-symbol-name sym)) "VLA`-GET`-*,VLA`-PUT`-*")
                            )
                        )
                        (_GetVlaAtoms)
                    )
                )
            )
        )
    )
    (_GetVlaMethods)
)

(vl-load-com) (princ)

Andrea

  • Water Moccasin
  • Posts: 2307
Re: vlax-dump-object->List
« Reply #2 on: December 15, 2016, 04:36:11 pm »
Wow !....amazing...  :smitten:

Thank you very much Lee..
I was thinking differently..

I'm on my way to create a quick tool helping me to have fast information when selecting an object .... :)

Keep smile...

MP

  • Seagull
  • Posts: 17003
  • brevity != aggression
Re: vlax-dump-object->List
« Reply #3 on: December 15, 2016, 04:37:54 pm »
Here's the original code posted about 11 years ago: link.
\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

Grrr1337

  • Bull Frog
  • Posts: 417
Re: vlax-dump-object->List
« Reply #4 on: December 15, 2016, 04:38:05 pm »
From my stash (studied from hmsilva):
Heres the original thread
Code: [Select]
(defun C:test ( / e o StrMark opn row LstRows rest n itm str LstDump newf newopn a )

(while (not (setq e (car (entsel "\nSelect object to dump to file: ")))) e)
(if (setq o (vlax-ename->vla-object e))
(progn
(SetVarP SysVars2 'cmdecho 0)
(setq StrMark (rtos (rem (getvar 'date) 1) 2 10))
(setvar 'LOGFILEMODE 1)
(princ (strcat "\n" StrMark "\n"))
(princ)
(foreach x (entget e) (print x)(princ "\n"))
(princ "\n;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n")
(princ)
(vlax-dump-object o T)
(princ)
(setvar 'LOGFILEMODE 0)

(if (setq opn (open (getvar 'LOGFILENAME) "r"))
(progn (while (setq row (read-line opn)) (if (> (strlen row) 0) (setq LstRows (cons row LstRows)))) (close opn))
      )
(if LstRows (progn (setq LstRows (reverse LstRows)) (setq LstRows (cdr (member StrMark LstRows)))))
(ListAlertEach LstRows)

(if
        (and
          LstRows
          (setq newf (getfiled "Create New TXT File" "" "txt" 1))
          (setq newopn (open newf "w"))
        )
        (progn
          (foreach x LstRows (write-line x newopn))
          (close newopn)
          (or a (setq a "Yes")) (initget "Yes No Y N")
          (setq a (cond ((getkword (strcat "\nDo you want to open the TXT file? [Yes/No] <" a ">: "))) ( a )))
          (if (member (strcase a) '("Y" "YES")) (startapp "explorer" newf))
        ); progn
      ); if

    ); progn
  ); if o

(princ)
);| defun |; (vl-load-com) (princ)

(defun SetVarP ( SysVarLst VarName Val ); <- UNTESTED !
(and
(= 'LIST (type SysVarLst))
(if (not (zerop (length SysVarLst))) (apply 'and (mapcar '(lambda (x) (= (length x) 3)) SysVarLst)))
(member VarName (mapcar 'car SysVarLst))
(not (vl-catch-all-error-p (vl-catch-all-apply 'setvar (list VarName Val))))
  )
);| defun SetVarP |; (vl-load-com) (princ)

(defun ListPrintEach ( Lst ) (if (listp Lst) (foreach x Lst (princ "\n") (print x))) (princ))
(defun ListAlertEach ( Lst ) (if (listp Lst) (alert (apply 'strcat (mapcar '(lambda (x) (strcat "\n" (vl-princ-to-string x))) Lst)))) (princ))
Entget, and Dump with option to save as TXT file, the only problem is that the List is contained entirely of strings.
Figured out to put the StrMark variable, so everytime the log file can be re-readen 8)

Andrea

  • Water Moccasin
  • Posts: 2307
Re: vlax-dump-object->List
« Reply #5 on: December 15, 2016, 04:43:51 pm »
Thank you Guys..  8-)
Keep smile...

Grrr1337

  • Bull Frog
  • Posts: 417
Re: vlax-dump-object->List
« Reply #6 on: December 15, 2016, 04:53:26 pm »
Thanks for sharing this, Lee!
Its not very friendly to LWpolylines:
Code: [Select]
_$ (vlax-dump-object->list (vlax-ename->vla-object (car (entsel))) nil)
Error: Invalid number of parameters
_1$

Here's the original code posted about 11 years ago: link.
WTH MP?!
 That thread is insane!!!  :uglystupid2:  :uglystupid2:  :angel:
After seeing this, now I'm subscribed to T.Willey's ideas!  :idea:

MP

  • Seagull
  • Posts: 17003
  • brevity != aggression
Re: vlax-dump-object->List
« Reply #7 on: December 15, 2016, 04:58:48 pm »
Tim is an awesome programmer and artist.
\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

Grrr1337

  • Bull Frog
  • Posts: 417
Re: vlax-dump-object->List
« Reply #8 on: December 15, 2016, 05:24:23 pm »
By the way Andrea, I had a similar idea. However I'm a "hobby programmer" so wrote only this (BrowseThruDictionaries - starting from the namedobjdict):

I used LM:ListBox to achieve this, but its actually unfinished, because wanted to include "back" button.
One day I might get it done  :cry2:

MP

  • Seagull
  • Posts: 17003
  • brevity != aggression
Re: vlax-dump-object->List
« Reply #9 on: December 15, 2016, 05:33:40 pm »
In before the deluge.

Wrote this back in 2010, first incarnation originated about 6 years prior.
\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

MP

  • Seagull
  • Posts: 17003
  • brevity != aggression
Re: vlax-dump-object->List
« Reply #10 on: December 15, 2016, 05:38:30 pm »
Also does the dxf data and yes -- everything is live linked -- can dance about the object model at will (sorry, no vid available):
\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

Grrr1337

  • Bull Frog
  • Posts: 417
Re: vlax-dump-object->List
« Reply #11 on: December 15, 2016, 05:43:58 pm »
In before the deluge.

Wrote this back in 2010, first incarnation originated about 6 years prior.

The conclusion is that this applies to you also mr.Puckett !   :grinwink:
Tim is an awesome programmer and artist.

MP

  • Seagull
  • Posts: 17003
  • brevity != aggression
Re: vlax-dump-object->List
« Reply #12 on: December 15, 2016, 05:54:34 pm »
Don't know about awesome but I'm stubborn and determined. The original was actually a dll I wrote using Visual Studio 6 enterprise. Mid 90's. It was slick and very graphical (icons for each data type) using a listview widget and was good for a couple versions, then knackered by Autodesk. Rewrote it in lisp exploiting a std type library dll. Worked for years then knackered again. Rewrote again in 2010 pure lisp. Fingers crossed its not knackered for awhile.
\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

kdub

  • SuperMod
  • Swamp Rat
  • Posts: 982
  • class keyThumper<T>:ILazy<T>
Re: vlax-dump-object->List
« Reply #13 on: December 15, 2016, 06:06:19 pm »
< ... >  (sorry, no vid available):

I remember a time when a whiff of a hint was appreciated.

don't get me started ....
called Kerry in my other life

Sometimes the question is more important than the answer.

Andrea

  • Water Moccasin
  • Posts: 2307
Re: vlax-dump-object->List
« Reply #14 on: December 15, 2016, 06:08:05 pm »
I knew that you guru did something like that...
awesome ! :)

but to be honest...I was thinking creating something like that since 2001,..:)
never had time.. haha :oops:

...you did very nice tools guys...congrats. :)
Keep smile...