Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counting blocks in autocad files

Status
Not open for further replies.

shkim2000

Electrical
Oct 12, 2004
59
I am using several blocks in auocad environments and need to count those blocks into excel spreadsheet.
Can anyone to know source code for utility made by VBA or LISP ?
 
Replies continue below

Recommended for you

Code:
Private Sub GetBlockCnt()
    Dim Sheet As Worksheet
    Dim ACad As Object
    Dim ACadDwg As Object
    Dim sPath As String
    Dim ssetObj As Object
    Dim mode As Integer
    Dim gpCode(0) As Integer
    Dim dataValue(0) As Variant
    Dim I As Integer
    Dim groupCode As Variant, dataCode As Variant
    Const SELSET = "SSblockCnt"
    Const acSelectionSetAll = 5
    
    sPath = "c:\block_cnt.dwg"
    
    Set ACad = GetObject(, "AutoCAD.Application")
    If Err <> 0 Then
        MsgBox "Please open a drawing file and then restart this macro."
        Exit Sub
    End If
    Set ACadDwg = ACad.Application.Documents.Open(sPath)
        
    For I = 0 To ACadDwg.SelectionSets.Count - 1
        If ACadDwg.SelectionSets.Item(I).Name = SELSET Then
            ACadDwg.SelectionSets.Item(I).Delete
        End If
    Next
    Set ssetObj = ACadDwg.SelectionSets.Add(SELSET)
    mode = acSelectionSetAll
    
    gpCode(0) = 0
    dataValue(0) = "INSERT"
    groupCode = gpCode
    dataCode = dataValue
    ssetObj.Select mode, , , groupCode, dataCode
    
    Set Sheet = ThisWorkbook.Sheets(1)
    Sheet.Cells(1, 1) = sPath
    Sheet.Cells(1, 2) = ssetObj.Count
    
    
    ssetObj.Delete
    ACadDwg.Close False
    
    Set ssetObj = Nothing
    Set ACadDwg = Nothing
    Set ACad = Nothing

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor