I always wondered why there wasn't a native LISP function to find the properties of an object
and return a list of sublists with the property name and the property value.
Here is the lisp version.
Maybe this will help you or others who wondered the same thing.
P=
Code:
;___________________________________________________________________________________________________________|
;
; Written By: Peter Jamtgaard C.E., P.E., S.E. copyright 2018 All Rights Reserved
;___________________________________________________________________________________________________________|
;
; Any use by unauthorized person or business is strictly prohibited.
;___________________________________________________________________________________________________________|
;___________________________________________________________________________________________________________|
;
; Comand line function list
;___________________________________________________________________________________________________________|
;* C:PropertyDump
;* Command line function to dump a list of property names and values of a selected object to a list
;___________________________________________________________________________________________________________|
;
; General Function Header List
;___________________________________________________________________________________________________________|
; Function List Argument1 Argument2 Arguement3
;* (PropertyList objSelection)
;* Function to create a list of sublists of property names and values of an object argument
;* (PropertyNames objSelection)
;* Function to create a list of property names that available to an object
;* (PropertyValue objSelection strProperty)
;* Function to get a property value from an object (neglecting COORDINATE because it has more than one arg.)
;$ End Header
;___________________________________________________________________________________________________________|
;
; Command line function to dump a list of property names and values of a selected object to a list
;___________________________________________________________________________________________________________|
(defun C:PropertyDump (/ entSelection lstSelection objSelection)
(if (and (setq lstSelection (entsel "\nSelect Object: "))
(setq entSelection (car lstSelection))
(setq objSelection (vlax-ename->vla-object entSelection))
)
(PropertyList objSelection)
)
)
;___________________________________________________________________________________________________________|
;
; Function to create a list of sublists of property names and values of an object argument
;___________________________________________________________________________________________________________|
(defun PropertyList (objSelection / lstProperties strProperty)
(if (and (setq lstProperties (PropertyNames objSelection))
(setq lstProperties (acad_strlsort lstProperties))
)
(mapcar '(lambda (strProperty)(list strProperty (propertyvalue objSelection strProperty))) lstProperties)
)
)
;___________________________________________________________________________________________________________|
;
; Function to create a list of property names that available to an object
;___________________________________________________________________________________________________________|
(defun PropertyNames (objSelection / lstProperties strFunctionName)
(foreach strFunctionName (atoms-family 1)
(if (= (strcase (substr strFunctionName 1 7) T) "vla-get")
(if (vlax-property-available-p objSelection (substr strFunctionName 9))
(setq lstProperties (cons (substr strFunctionName 9) lstProperties))
)
)
)
(reverse lstProperties)
)
;___________________________________________________________________________________________________________|
;
; Function to get a property value from an object (neglecting COORDINATE because it has more than one arg.)
;___________________________________________________________________________________________________________|
(defun PropertyValue (objSelection strProperty)
(if (= (type objSelection) 'ENAME)
(setq objSelection (vlax-ename->vla-object objSelection)))
(if (= strProperty "COORDINATE")
T
(vlax-get objSelection strProperty)
)
)
(vl-load-com)