List of available blocks in a drawing using VBA

List of available blocks in a drawing using VBA

Anonymous
Not applicable
7,403 Views
6 Replies
Message 1 of 7

List of available blocks in a drawing using VBA

Anonymous
Not applicable
I need to populate a list box with a list of available blocks in my drawing, however it is listing every block in the drawing one entry for each instance of the block. example if block "A" is present 100 times I've got 100 "A"'s in my list. How can I correct this. Some of my code is attached below.

'collect up list of all acad objects
For Each ObjEnt In ThisDrawing.ModelSpace
'sort out blocks
If ObjEnt.ObjectName = "AcDbBlockReference" Then
Set ObjBRef = ObjEnt
CmbBx_Blk_Fnd_Nm.AddItem ObjBRef.EffectiveName
0 Likes
7,404 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
Hi Steve,

Read the help files till you understand the difference between

AcadBlock

and

AcadBlockReference

An AcadBlock cannot be found in model space

An AcadBlockReference cannot be found in the drawings Blocks collection.


Regards,


Laurie Comerford


steve030373 wrote:
> I need to populate a list box with a list of available blocks in my drawing, however it is listing every block in the drawing one entry for each instance of the block. example if block "A" is present 100 times I've got 100 "A"'s in my list. How can I correct this. Some of my code is attached below.
>
> 'collect up list of all acad objects
> For Each ObjEnt In ThisDrawing.ModelSpace
> 'sort out blocks
> If ObjEnt.ObjectName = "AcDbBlockReference" Then
> Set ObjBRef = ObjEnt
> CmbBx_Blk_Fnd_Nm.AddItem ObjBRef.EffectiveName
>
0 Likes
Message 3 of 7

Mario-Villada
Advocate
Advocate
Once you have followed Laurie's advice you may use this:

{code}
Private Sub CommandButton1_Click()

Dim B As AcadBlocks
Dim i As Integer
Set B = ThisDrawing.Blocks
For i = 0 To B.Count - 1
ListBox1.AddItem B(i).Name
Next i


End Sub
{code}

Regards,
Mario
0 Likes
Message 4 of 7

dm_salamania
Participant
Participant

Mr. steve

 

can i get you code in " list of available blocks in a drawing using VBA "

i have also problem in this situation..

0 Likes
Message 5 of 7

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

the last post abive yours show how to collect the block-definitions from the drawing, what do you need more than that (or other than that)?

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 6 of 7

dm_salamania
Participant
Participant

Sir Good day

 

    I'm new in vba. I want to make a VBA in Autocad that can make the simple LINE into a 3d I-BEAM in just a single click.

 

PLease see attached file.that is the form of my VBA.

 

Please help me Sir.

 

 

 

0 Likes
Message 7 of 7

sanganaksakha
Advocate
Advocate

dm_salamania,

 

This seems interesting.

 

Can you post a drawing that shows the original line and then the 3d I-BEAM AFTER conversion?

0 Likes