VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

List of available blocks in a drawing using VBA

6 REPLIES 6
Reply
Message 1 of 7
Anonymous
6635 Views, 6 Replies

List of available blocks in a drawing using VBA

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
6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: Anonymous

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
>
Message 3 of 7
Mario-Villada
in reply to: Anonymous

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
Message 4 of 7
dm_salamania
in reply to: Anonymous

Mr. steve

 

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

i have also problem in this situation..

Message 5 of 7

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 2024
------------------------------------------------------------------------------------

(not an Autodesk consultant)
Message 6 of 7
dm_salamania
in reply to: Anonymous

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.

 

 

 

Message 7 of 7

dm_salamania,

 

This seems interesting.

 

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report