Hi, here below a simple way to catch block and related attributes from drawing, and transfer to excel.
What you have to pay attention inside this procedure is
qq = BlkRef.GetAttributes
For X = LBound(qq) To UBound(qq)
In this way you got block attributes which will be store in the array qq.
If you want to be sure that the block has attributes you can add
If BlkRef.HasAttributes=true then
...
end if
Later you can check the attribute you want to check with TAGSTRING and TEXTSTRING, respectively the Attribute Name and Value.
The attribute sequence in the array from 0 to N attribute it's the same of what you are viewing when you modify the attributes locally with form which appear double clicking on block.
For X = LBound(qq) To UBound(qq)
ObjExcel.ActiveSheet.Cells(1, X + 1).Value = X
ObjExcel.ActiveSheet.Cells(2, X + 1).Value = qq(X).TagString
ObjExcel.ActiveSheet.Cells(3, X + 1).Value = qq(X).TextString
Next
Private Sub TemplateExcel()
Dim ObjExcel As Object
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set ObjExcel = CreateObject("Excel.Application")
Set xlBook = ObjExcel.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
ObjExcel.Visible = True
ObjExcel.Workbooks(ObjExcel.ActiveWorkbook.Name).Activate
For Each Object In ThisDrawing.ModelSpace
If TypeOf Object Is AcadBlockReference Or TypeOf Object Is AcadBlock Then
Set BlkRef = Object
If BlkRef.HasAttributes = True Then
Nome = BlkRef.EffectiveName
If Nome = "BLOCK NAME" Then
BlkRef.layer="NAME OF LAYER"
End If
For Each MySheet In ObjExcel.Sheets
If MySheet.Name = Nome Then
GoTo Qui:
End If
Next MySheet
ObjExcel.ActiveSheet.Name = Nome
qq = BlkRef.GetAttributes
For X = LBound(qq) To UBound(qq)
ObjExcel.ActiveSheet.Cells(1, X + 1).Value = X
ObjExcel.ActiveSheet.Cells(2, X + 1).Value = qq(X).TagString
ObjExcel.ActiveSheet.Cells(3, X + 1).Value = qq(X).TextString
Next
ObjExcel.Sheets.Add
End If
End If
Qui:
Next
End Sub