×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Counting blocks in autocad files

Counting blocks in autocad files

Counting blocks in autocad files

(OP)
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 ?

RE: Counting blocks in autocad files

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources