Dynamic blocks with VB

Dynamic blocks with VB

farzanjazil
Participant Participant
1,398 Views
2 Replies
Message 1 of 3

Dynamic blocks with VB

farzanjazil
Participant
Participant

Hi everyone,

 

Is it possible to get all attributes from de Dynamic block and menwhile counting the block and put the information in Excel with VB ?

 

thanks alot

0 Likes
Accepted solutions (2)
1,399 Views
2 Replies
Replies (2)
Message 2 of 3

miguelmachadoecosta
Advocate
Advocate
Accepted solution

Yes, it is possible. Here is an example:

 

Sub PutAttributesInExcel()
    Dim oApp_Excel As Excel.Application
    Dim oBook As Excel.workbook
    Set oApp_Excel = CreateObject("EXCEL.APPLICATION")
    Set oBook = oApp_Excel.workbooks.Add
    
    AppActivate ThisDrawing.Application.Caption
    Dim ssetObj As AcadSelectionSet
    
    'Select blocks onscreen
    Set ssetObj = ThisDrawing.SelectionSets.Add("seleccaoTemp")
    ssetObj.SelectOnScreen
    
    Dim blockRefObj As AcadBlockReference
    Dim varAttributes As Variant
    
    Dim cnt As Integer, j As Integer, k As Integer
    cnt = 0
    
    If ssetObj.Count = 0 Then
        MsgBox "No objects selected."
    Else
        For j = 0 To ssetObj.Count - 1
            If ssetObj.Item(j).ObjectName = "AcDbBlockReference" Then
                Set blockRefObj = ssetObj.Item(j)
                varAttributes = blockRefObj.GetAttributes
                
                ' Put attributes in Excel
                For k = LBound(varAttributes) To UBound(varAttributes)
                    oBook.Worksheets(1).Cells(k + 1, j + 1).Value = varAttributes(k).TextString
                Next k
                cnt = cnt + 1
            End If
        Next j
        If cnt = 0 Then
            MsgBox "No blocks selected."
        Else
            MsgBox "The number of blocks is " & cnt
        End If
    End If
    
    ssetObj.Delete
    oBook.SaveAs ("C:\temp\myfile.xlsx")
    oBook.Close
    oApp_Excel.Quit
    Set oBook = Nothing
End Sub

 

Don't forget to add the Excel Object Library in the References.

Message 3 of 3

farzanjazil
Participant
Participant
Accepted solution

thank u very much Miguel Costa

0 Likes