The default value for an attribute is stored in the block definition.
Below is some code that will allow the user to create a selection set of blocks.
The routine will look at each block instance and find its block definition and create a list of sublists including the
tagstring and default textstring for each attribute.
Then it will check to see if the length of attributes in the block instance and the length of that list of sublists are equal.
It then checks to see if the tagstrings are the same.
If they are... it changes the textstring in each of the attributes to the default te.
It will not work if you have modified the attributes (number or order) after the creation of the block.
I believe that is what you asked for, or is it opposite?
P=
Code:
;___________________________________________________________________________________________________________
;
; Function for returning block attributes to default values
; Written By: Peter Jamtgaard copyright 2014 all rights reserved
;
;___________________________________________________________________________________________________________
(defun C:Default (/ intCount entSelection lstAttributes lstDefaults objSelection ssSelections )
(if (setq ssSelections (ssget (list (cons 0 "insert"))))
(repeat (setq intCount (sslength ssSelections))
(and
(setq intCount (1- intCount))
(setq entSelection (ssname ssSelections intCOunt))
(setq objSelection (vlax-ename->vla-object entSelection))
(= (vla-get-hasattributes objSelection) :vlax-true)
(setq lstAttributes (vlax-invoke objSelection "getattributes"))
(setq lstDefaults (attributedefaults objSelection))
(defaultset objSelection)
)
)
)
(princ)
)
;___________________________________________________________________________________________________________
;
; Function for checking the tagstring and number of attributes and changing them to default values
;___________________________________________________________________________________________________________
(defun DefaultSet (objSelection)
(or
(and
(= (length lstAttributes) (length lstDefaults))
(equal (mapcar 'vla-get-tagstring lstAttributes)
(mapcar 'car lstDefaults)
)
(mapcar 'vla-put-textstring lstAttributes (mapcar 'cadr lstDefaults))
)
(princ "\nError: The attributes have changed from the definition.")
)
)
;___________________________________________________________________________________________________________
;
; Function for getting the tagstring and default values from a block definition
;___________________________________________________________________________________________________________
(defun AttributeDefaults (objSelection / lstOfSublists)
(vlax-for objItem (blockdefinition objSelection)
(and
(wcmatch (vla-get-objectname objItem) "AcDbAttributeDefinition")
(setq lstOfSublists (cons (list (vla-get-tagstring objItem)(vla-get-textstring objItem)) lstOfSublists))
)
)
(reverse lstOfSublists)
)
;___________________________________________________________________________________________________________
;
; Function for getting a block definition object from the block object.
;___________________________________________________________________________________________________________
(defun BlockDefinition (objSelection / objReturn)
(if (and (wcmatch (vla-get-objectname objSelection)
"AcDbBlockReference,AcDbMInsertBlock")
(setq objReturn (vla-item (vla-get-blocks
(vla-get-document objSelection))
(vla-get-name objSelection)
)
)
)
objReturn
)
)
(prin1)