Jump to content

AutoCAD Block List Extract


CaveMan

Recommended Posts

Good Day

 

Have a Drawing that has symbol blocks in it.

Blocks are not inserted into drawing - so no instances.

 

How does one view the list of blocks in the current drawing.

 

Any assistance welcome

"This is probably a basic routine"

 

Thanks in Advance

Link to comment
Share on other sites

Try this function

You can put DataSource property of ListBox

as result of this function:

 
      Public Function ListBlocks() As List(Of String)
           Dim db As Database = HostApplicationServices.WorkingDatabase
           Dim blocks As New List(Of String)
           Try
               Dim tr As Transaction = db.TransactionManager.StartTransaction()
               Using tr
                   Dim bt As BlockTable = DirectCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
                   For Each id As ObjectId In bt
                       Dim btr As BlockTableRecord = DirectCast(tr.GetObject(id, OpenMode.ForRead), BlockTableRecord)
                       If Not btr.IsAnonymous And Not btr.IsLayout Then
                           blocks.Add(btr.Name)
                       End If
                   Next
               End Using
           Catch ex As System.Exception
               Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(ex.Message & vbCr & ex.StackTrace)
               Return Nothing
           End Try
           Return blocks
       End Function

On load in your form:

 
ListBox1.DataSource=ListBlocks

Not tested

 

~'J'~

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...