Sorry, I have not had time to get back to this. Last week was a little busy at work, as one co-worker was at Autodesk University, and the other was doing project work, so I was the Helpdesk for design technology issues last week.
Here is what I have so far, in case others care to extend it before I have a chance to revisit this:
The last three lines in the formula property definition are just testing what was assigned to various values. Starting a line with an apostrophe (') makes that line a comment, and it is not executed. In the image above, you can see that when I test whether attArray is an array, the value is -1, or True. (A value of 0 would mean False.) In other tests not shown here, the LBound and UBound functions, which give the lower and upper boundaries of an array, respectively, work on attArray and return values of 0 and 2. The selected block on which this property is working has three attributes, so that would be consistent with an array of attribute objects for this block.
When testing the contents of attRef, which I hoped would contain the first attribute object, it turns out that this variable is uninitialized, so the attRef = attArray(0) line is not working.
Given that attRef is Empty, it is not surprising that strTag is also empty.
The attached TestAttributeData.lsp file contains five AutoLISP statements that I used to check what sort of data was available from an attributed block. Below are the results of running those statements, one at a time, on the Visual LISP Console, so you can see the results of each line. It also includes a vlax-dump-object on the objB1 block object. The GetAttributes method returns an array containing the attribute objects attached to the block object, as a safearray. That is likely the reason why trying to get one of the attribute objects using a "regular" array method attRef = attArray(0) in the formula property failed. AutoLISP has a function to convert a safearray into a list, which is what I used to verify that the contents of the array were in fact three attribute references. Dumping the properties of one of the attribute references reveals that the TextString property contains the attribute value assigned in the drawing.
_$ (setq b1 (ssget))
<Selection set: 10>
_$ (setq objB1 (vlax-ename->vla-object (ssname b1 0)))
#<VLA-OBJECT IAcadBlockReference 000001f09eedca08>
_$ (vlax-dump-object objB1)
; IAcadBlockReference: AutoCAD Block Reference Interface
; Property values:
; Application (RO) = #<VLA-OBJECT IAcadApplication 00007ff6b10470d8>
; Document (RO) = #<VLA-OBJECT IAcadDocument 000001f0f9777b88>
; EffectiveName (RO) = "TestBlock01"
; EntityTransparency = "ByLayer"
; Handle (RO) = "3671"
; HasAttributes (RO) = -1
; HasExtensionDictionary (RO) = -1
; Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 000001f09f82afc8>
; InsertionPoint = (0.0 0.0 0.0)
; InsUnits (RO) = "Inches"
; InsUnitsFactor (RO) = 1.0
; IsDynamicBlock (RO) = 0
; Layer = "0"
; Linetype = "ByLayer"
; LinetypeScale = 1.0
; Lineweight = -1
; Material = "ByLayer"
; Name = "TestBlock01"
; Normal = (0.0 0.0 1.0)
; ObjectID (RO) = 42
; ObjectName (RO) = "AcDbBlockReference"
; OwnerID (RO) = 43
; PlotStyleName = "ByLayer"
; Rotation = 0.0
; TrueColor = #<VLA-OBJECT IAcadAcCmColor 000001f09f82b1a0>
; Visible = -1
; XEffectiveScaleFactor = 1.0
; XScaleFactor = 1.0
; YEffectiveScaleFactor = 1.0
; YScaleFactor = 1.0
; ZEffectiveScaleFactor = 1.0
; ZScaleFactor = 1.0
T
_$ (setq arr1 (vlax-invoke-method objB1 'GetAttributes))
#<variant 8201 ...>
_$ (setq attList (vlax-safearray->list (vlax-variant-value arr1)))
(#<VLA-OBJECT IAcadAttributeReference 000001f09453f608> #<VLA-OBJECT IAcadAttributeReference 000001f09453f728> #<VLA-OBJECT IAcadAttributeReference 000001f09453fcc8>)
_$ (vlax-dump-object (nth 0 attList))
; IAcadAttributeReference: AutoCAD Attribute Reference Interface
; Property values:
; Alignment = 10
; Application (RO) = #<VLA-OBJECT IAcadApplication 00007ff6b10470d8>
; Backward = 0
; Constant (RO) = 0
; Document (RO) = #<VLA-OBJECT IAcadDocument 000001f0f9777b88>
; EntityTransparency = "ByLayer"
; FieldLength = 0
; Handle (RO) = "3673"
; HasExtensionDictionary (RO) = 0
; Height = 1.0
; Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 000001f0b17d8e58>
; InsertionPoint = (-1.4352 -0.5 0.0)
; Invisible = 0
; Layer = "0"
; Linetype = "ByLayer"
; LinetypeScale = 1.0
; Lineweight = -1
; LockPosition (RO) = -1
; Material = "ByLayer"
; MTextAttribute = 0
; MTextAttributeContent = ""
; MTextBoundaryWidth = 0.0
; MTextDrawingDirection = 5
; Normal = (0.0 0.0 1.0)
; ObjectID (RO) = 44
; ObjectName (RO) = "AcDbAttribute"
; ObliqueAngle = 0.0
; OwnerID (RO) = 42
; PlotStyleName = "ByLayer"
; Rotation = 0.0
; ScaleFactor = 1.0
; StyleName = "Arial Non-Annotative"
; TagString = "TAG01"
; TextAlignmentPoint = (0.0 0.0 0.0)
; TextGenerationFlag = 0
; TextString = "ABC"
; Thickness = 0.0
; TrueColor = #<VLA-OBJECT IAcadAcCmColor 000001f0b17d91b0>
; UpsideDown = 0
; Visible = -1
T
_$
So, the challenge remains figuring out a way, if it is possible, to extract the value of a safearray in VBScript.
David Koch
AutoCAD Architecture and Revit User
Blog | LinkedIn
