Message 1 of 9
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Dear Autocad ActiveX Experts,
How to get a block object (AcadBlock) from its name?
Is the only way, iteration through all blocks in the current document, and then checking if any of their names is equal to required block name?
I have 900 "normal" blocks and dynamic blocks in my .dwg file.
Thus, to search for the their AcadBlock object, can be very time consuming with upper mentioned approach (I posted the code below).
Is there some faster approach for AutoCAD ActiveX API? Without the use of AutoCAD NET API?
I would be very grateful for any kind of help. As at the moment I am quite desperate.
Thank you in advance.
' Name of the block(s) you are looking for
Dim blockName As String
blockName = "Block1" ' Change this to the desired block name
' Get the active AutoCAD document
Dim acadApp As AcadApplication
Set acadApp = Application
' Get the active drawing
Dim acadDoc As AcadDocument
Set acadDoc = acadApp.ActiveDocument
' Get the Blocks collection
Dim blocks As AcadBlocks
Set blocks = acadDoc.Blocks
' Create a collection to store the found blocks
Dim foundBlocks As Collection
Set foundBlocks = New Collection
' Iterate through all the blocks in the drawing
Dim eachBlock As AcadBlock
For Each eachBlock In blocks
' Check if the current block's name matches the specified name
If UCase(eachBlock.Name) = UCase(blockName) Then
' Add the matching block to the foundBlocks collection
foundBlocks.Add eachBlock
End If
Solved! Go to Solution.