Ok.
My code only went through the blocks collection, were the definitions of all blocks, inserted or not, resides in the dwg file. If you use the BATTMAN command in AutoCAD, youll see that the attributes in VT0011 actually is on layer 0. It seems like AutoCAD Electrical moves the attributereferences to the designated layers when the block is inserted into the drawing (hence the result you get when using EATTEDIT).
However.. I updated the code, to include the already inserted blockreferences also:
-----------------------------------------------------
Sub ListLayersUsedInBlocks()
Dim ssInsertedBlocks As AcadSelectionSet
Dim dxfCode(1) As Integer
Dim dxfData(1) As Variant
Dim blkBlock As AcadBlock
Dim blkRef As AcadBlockReference
Dim entAcad As AcadEntity
Dim colLayers As Collection
Dim intCounter As Integer
Dim blnLayerExistsInCollection As Boolean
Dim attAtts As Variant
Dim attAtt As AcadAttributeReference
Dim attCounter As Integer
For Each blkBlock In ThisDrawing.Blocks
Set colLayers = New Collection
ThisDrawing.Utility.Prompt vbCr & "Blockname: " & blkBlock.Name & vbCrLf
For Each entAcad In blkBlock
blnLayerExistsInCollection = False
For intCounter = 1 To colLayers.Count
If colLayers.Item(intCounter) = entAcad.Layer Then
blnLayerExistsInCollection = True
Exit For
End If
Next
If Not blnLayerExistsInCollection Then
colLayers.Add entAcad.Layer
End If
Next
ThisDrawing.Utility.Prompt vbCr & "Blockdefinition has entities on layer(s): "
For intCounter = 1 To colLayers.Count
ThisDrawing.Utility.Prompt colLayers.Item(intCounter) & IIf(intCounter colLayers.Count, " & ", vbCr)
Next
Set colLayers = Nothing
Set ssInsertedBlocks = ThisDrawing.SelectionSets.Add("InsertedBlocks")
dxfCode(0) = 0
dxfData(0) = "INSERT"
dxfCode(1) = 2
dxfData(1) = blkBlock.Name
ssInsertedBlocks.Select acSelectionSetAll, , , dxfCode, dxfData
Set colLayers = New Collection
For Each blkRef In ssInsertedBlocks
If blkRef.HasAttributes Then
attAtts = blkRef.GetAttributes
For attCounter = 0 To UBound(attAtts)
Set attAtt = attAtts(attCounter)
blnLayerExistsInCollection = False
For intCounter = 1 To colLayers.Count
If colLayers.Item(intCounter) = attAtt.Layer Then
blnLayerExistsInCollection = True
Exit For
End If
Next
If Not blnLayerExistsInCollection Then
colLayers.Add attAtt.Layer
End If
Set attAtt = Nothing
Next
End If
Next
ThisDrawing.Utility.Prompt vbCr & "Blockreferences (inserted blocks) has attriutes on layer(s): "
For intCounter = 1 To colLayers.Count
ThisDrawing.Utility.Prompt colLayers.Item(intCounter) & IIf(intCounter colLayers.Count, " & ", vbCrLf)
Next
ThisDrawing.Utility.Prompt vbCrLf & vbCrLf
Set colLayers = Nothing
ssInsertedBlocks.Delete
Set ssInsertedBlocks = Nothing
Next
End Sub
-----------------------------------------------------
You can also download the code on http://www.baremitt.com/ListLayersUsedInBlocks.dvb
Hope this is helpful.
THL
Trond Hasse LieAutoCAD Electrical and
EPLAN expert
Ctrl Alt ElPlease select "Accept Solution" if this post answers your question. 'Likes' won't hurt either.
😉