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

0 Members and 1 Guest are viewing this topic.

Andrea

  • Water Moccasin
  • Posts: 2372
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: 12905
  • 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: 2372
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: 17750
  • Have thousands of dwgs to process? Contact me.
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.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Grrr1337

  • Swamp Rat
  • Posts: 812
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)
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Andrea

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

Grrr1337

  • Swamp Rat
  • Posts: 812
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:
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: vlax-dump-object->List
« Reply #7 on: December 15, 2016, 04:58:48 PM »
Tim is an awesome programmer and artist.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Grrr1337

  • Swamp Rat
  • Posts: 812
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:
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
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.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
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):
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Grrr1337

  • Swamp Rat
  • Posts: 812
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.
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
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.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2120
  • 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
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

Andrea

  • Water Moccasin
  • Posts: 2372
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...