I think this will do for you what you want (get the attribute value from the first instance of the block in a drawing or you can change it to the layout)
P=
Code:
;___________________________________________________________________________________________________________|
;
; Written By: Peter Jamtgaard copyright 2017 All Rights Reserved
;___________________________________________________________________________________________________________|
;
; Abstract: This set of functions are designed to get an attribute textstring from REVISION tagstring in first instance of block
; with a tagstring REVISION in a drawing.
;___________________________________________________________________________________________________________|
;
; Command Line Function Header List
;___________________________________________________________________________________________________________|
;* C:TitleBlockValues
;* Command Line Function to get a value from a blocks in paperspace(s) and a "REVISION" tagstring
;___________________________________________________________________________________________________________|
;
; General Function Header List
;___________________________________________________________________________________________________________|
; Function, Arguments and Description
;* (AttributeSublists objBlockReference)
;* Function to create a list of sublists from a block reference of its attribute tagstring, textstring and handle
;* (AttributeTextString objSelection strTagString)
;* Function to get a textstring value from a block reference and a tagstring
;* (SelectionSetToList ssSelections)
;* Function to convert a lisp selectionset to a list of objects
;* (TitleBlockValue strBlockname strTagString)
;* Function to get a value from the first instance of a block reference
;$ End HEader
;___________________________________________________________________________________________________________|
;
; Command line Function to get an attribute value from a selected block and REVISION tagstring.
;___________________________________________________________________________________________________________|
(defun C:TitleBlockValues (/ lstReturn lstSelections objSelection ssSelections strTextString )
(if (and ;(setq ssSelections (ssget "X" (list (cons 410 (getvar "ctab")) (cons 66 1)(cons 0 "INSERT"))))
(setq ssSelections (ssget "X" (cons 66 1)(cons 0 "INSERT"))))
(setq lstSelections (selectionsettolist ssSelections))
)
(foreach objSelection lstSelections
(if (setq strTextString (AttributeTextString objSelection "REVISION"))
(setq lstReturn (cons strTextString
lstReturn
)
)
)
)
)
(car (reverse lstReturn))
)
;___________________________________________________________________________________________________________|
;
; Function to create a list of sublists from a block reference of its attribute tagstring, textstring and handle
;___________________________________________________________________________________________________________|
(defun AttributeSublists (objBlockReference / lstAttributes objAttribute)
(if (and (vlax-method-applicable-p objBlockReference "getattributes")
(setq lstAttributes (vlax-invoke objBlockReference "getattributes"))
)
(setq lstOfSublists (mapcar '(lambda (objAttribute)(list (strcase (vla-get-tagstring objAttribute))
(vla-get-textstring objAttribute)
(vla-get-handle objAttribute)
)
)
lstAttributes
)
)
)
)
;___________________________________________________________________________________________________________|
;
; Function to get a textstring value from a block reference and a tagstring
;___________________________________________________________________________________________________________|
(defun AttributeTextString (objSelection strTagString)
(if (setq lstOfSublists (AttributeSublists objSelection))
(cadr (assoc (strcase strTagString) lstOfSublists))
)
)
;___________________________________________________________________________________________________________|
;
; Function to convert a lisp selectionset to a list of objects
;___________________________________________________________________________________________________________|
(defun SelectionSetToList (ssSelections / entSelection intCount lstObjects objSelection )
(repeat (setq intCount (sslength ssSelections))
(and
(setq intCount (1- intCount))
(setq entSelection (ssname ssSelections intCount))
(setq objSelection (vlax-ename->vla-object entSelection))
(setq lstObjects (cons objSelection lstObjects))
)
)
lstObjects
)
;___________________________________________________________________________________________________________|
;
; Function to get a value from the first instance of a block reference
;___________________________________________________________________________________________________________|
(defun TitleBlockValue (strBlockname strTagString / entSelection objSelection ssSelections)
(if (and (setq ssSelections (ssget "x" (list (cons 2 strBlockName)(cons 66 1))))
(setq entSelection (ssname ssSelections 0))
(setq objSelection (vlax-ename->vla-object entSelection))
)
(AttributeTextString objSelection strTagString)
)
)
(princ "!")
(vl-load-com)