I have a VBA routine which strips all of the attributes from all of the blocks in a drawing, see following code:
This part works fine, but when I run a further routine in which I select a single block on screen, I test to see if the block has any attributes and depending on the result I display the appropriate form. At this point none of the blocks have any attribute references or definitions and I have confirmed this by checking the properties panel after selecting a block and by using the block editor. I have used the following code to check for any attributes:
Dim oEnt As AcadEntity
Dim i As Integer
' get all blocks in drawing
Set colBlocks = ThisDrawing.Blocks
' iterate each block and remove all of the attribute definitions
For Each objBlock In colBlocks
For Each oEnt In objBlock
If oEnt.ObjectName = "AcDbAttributeDefinition" Then
ThisDrawing.SendCommand "_ATTSYNC" & vbCr & "NAME" & vbCr & objBlock.Name & vbCr
' iterate each block reference and remove its attribute references
For Each oEnt In ThisDrawing.ModelSpace
If TypeOf oEnt Is AcadBlockReference Then
Set objBlockRef = oEnt
If objBlockRef.HasAttributes Then
varAttribs = objBlockRef.GetAttributes
For i = LBound(varAttribs) To UBound(varAttribs)
After executing the line in red it always evaluates to True even though there are no attributes.
' check if block already has some attributes
' and then show the appropriate form
If objBlockRef.HasAttributes = True Then
Even if I quit the macro, do something else and then restart the macro, it still always evaluates to True.
What am I doing wrong?
If I save the drawing nothing changes, but if I close and reopen the drawing the test for arributes evaluates as False, as it should.