AutoCAD Newbie - AcadBlockReference vs AcadBlock vs etc...

AutoCAD Newbie - AcadBlockReference vs AcadBlock vs etc...

Anonymous
Not applicable
4,564 Views
11 Replies
Message 1 of 12

AutoCAD Newbie - AcadBlockReference vs AcadBlock vs etc...

Anonymous
Not applicable
Hi everyone

I was hoping someone could shed some light for me on what exactly constitutes the various Acad objects... for instance, what is an AcadBlock vs an AcadBlockReference vs etc?

I'm trying to read the attributes off of a block I inserted using this code

'Process EACH AutoCAD Block INCLUDING ModelSpace/PaperSpace
For Each AutoCAD_Block As AcadBlock In AutoCAD_CurrentDwg_Blocks

Try

'Process each REFERENCED AutoCAD Block
For Each AutoCAD_Block_Reference As AcadBlockReference In AutoCAD_Block

Dim strAutoCAD_Block_ReferenceAttributeValue As String = ""

'Console.WriteLine(AutoCAD_Block.Name)

'Console.WriteLine(AutoCAD_Block_Reference.Name)

If (AutoCAD_Block_Reference.HasAttributes) Then

but a block I know has attributes isn't an AcadBlockReference... how do I handle this?

Many thanks!

-Justin
0 Likes
4,565 Views
11 Replies
Replies (11)
Message 2 of 12

Anonymous
Not applicable
Here's a little more information... I've 'inserted' a block via the 'Insert' menu pick...when I try process that block with the above code, I get an 'InvalidCastException' exception on the "For each AutoCADBlockReference..."

Any thoughts on what I'm doing wrong?
0 Likes
Message 3 of 12

Anonymous
Not applicable
A Block is the Block definition in the Blocks Table, the definition can hold
any number, and any type, of Acad Entities.
A BlockReference as an Inserted Block.

Stepping through a Block Definition will likely have objects other than just
inserts, this is why your code fails when trying to set an object to a
BlockReference type.

This would be more like what you want:

For Each AutoCAD_Entity As AcadEntity In AutoCAD_Block
If AutoCAD_Entity.ObjectName = "AcDbBlockReference" Then
AutoCAD_Block_Reference As AcadBlockReference = AutoCAD_Entity


"jsurpless" wrote in message news:[email protected]...
Here's a little more information... I've 'inserted' a block via the 'Insert'
menu pick...when I try process that block with the above code, I get an
'InvalidCastException' exception on the "For each AutoCADBlockReference..."

Any thoughts on what I'm doing wrong?
0 Likes
Message 4 of 12

Anonymous
Not applicable
Hi Jeff

Thanks for the information... could you elaborate on what other 'entities' might be?
0 Likes
Message 5 of 12

Anonymous
Not applicable
Hi Jeff

I am finding that this is taking considerable time as all the lines, rectangles, etc are being looped through... and I have a relatively simple drawing...

Am I doing something wrong?
0 Likes
Message 6 of 12

Anonymous
Not applicable
if you're working in the editor and not dbx you can use filtered selection
sets
hth
mark

wrote in message news:[email protected]...
Hi Jeff

I am finding that this is taking considerable time as all the lines,
rectangles, etc are being looped through... and I have a relatively simple
drawing...

Am I doing something wrong?

we're supposed to guess what you're doing?
:-)
0 Likes
Message 7 of 12

Anonymous
Not applicable
On large drawings this method would take a while. On relatively small
drawings it should still be rather quick.

In addition to the code you are trying to get to work, how about a brief
description of what it is you want your program to do.

As Mark said, if you are working in the drawing itself (i.e. it is loaded in
Acad) you can use Filtered Selection Sets to get just those object types you
want...but ONLY those in Model & Paper space (no objects in Blocks, those
you still have to step thru each item).


"jsurpless" wrote in message news:[email protected]...
Hi Jeff

I am finding that this is taking considerable time as all the lines,
rectangles, etc are being looped through... and I have a relatively simple
drawing...

Am I doing something wrong?
0 Likes
Message 8 of 12

Anonymous
Not applicable
Here's a brief summary of my project's goal...

I have individual drawings with blocks in Model Space that has been 'tagged' with a reference attribute that corresponds to the primary key of a database... these blocks have various additional attributes that correspond to additional fields of the database... the program is to loop through the blocks of each drawing, locate the relevant record and import the attribute information...

----

Yeah, might have been useful to provide code example... just so I have it straight in my mind... every line, circle, rectangle, etc on the drawing is a block, correct?

'Process EACH AutoCAD Block INCLUDING ModelSpace/PaperSpace
For Each AutoCAD_Block As AcadBlock In AutoCAD_CurrentDwg_Blocks

Try

For Each AutoCAD_Entity As AcadEntity In AutoCAD_Block

'Process each REFERENCED AutoCAD Block
'For Each AutoCAD_Block_Reference As AcadBlockReference In AutoCAD_Block
If (TypeOf AutoCAD_Entity Is AcadBlockReference) Then

-------

What is DBX? Is that the ObjectARX - the method where the drawing doesn't need to actually be opened? Actually, it seems like it's a .DLL similar to the .NET protocols?

Thanks!
0 Likes
Message 9 of 12

Anonymous
Not applicable
Hi jsurpless,

You are making it far too complex for yourself by confusing blocks with
blockreferences.

This is understandable because the programming terminology is different
from the every day AutoCAD terminology.

The blocks (with the exception of a few items like Modelspace and Layout
spaces which are technically blocks) are an invisible part of the
drawing database which can be called on to create a visible
blockreference in the drawing. The block contains a description of the
objects and any attributes to be drawn when the block is inserted to
create a blockreference

The only thing you need deal with are the blockreferences.

It is the blockreference which appears in the drawing and which holds
values for any attribute data.

So the code steps you need are:

make a collection of all the block references in the drawing - if the
ones you are interested in have known names, then filter the collection
by name as well as by blockreference when creating the collection

loop through your collection and for each block reference get its
attributes.
Use the value of the attribute with the database Key to query your
database for the relevant data
Assign the data to the attributes in the blockreference
loop to the next blockreference.


If you were coding in VBA (note you are in the VBA NG and displaying
code from .NET) you would find all the code you need in the code samples
supplied with AutoCAD. For .NET, I haven't looked, but no doubt there
are plenty of users around who could point you to sample code if you
cannot find it yourself.


Regards


Laurie Comerford

jsurpless wrote:
> Here's a brief summary of my project's goal...
>
> I have individual drawings with blocks in Model Space that has been 'tagged' with a reference attribute that corresponds to the primary key of a database... these blocks have various additional attributes that correspond to additional fields of the database... the program is to loop through the blocks of each drawing, locate the relevant record and import the attribute information...
>
> ----
>
> Yeah, might have been useful to provide code example... just so I have it straight in my mind... every line, circle, rectangle, etc on the drawing is a block, correct?
>
> 'Process EACH AutoCAD Block INCLUDING ModelSpace/PaperSpace
> For Each AutoCAD_Block As AcadBlock In AutoCAD_CurrentDwg_Blocks
>
> Try
>
> For Each AutoCAD_Entity As AcadEntity In AutoCAD_Block
>
> 'Process each REFERENCED AutoCAD Block
> 'For Each AutoCAD_Block_Reference As AcadBlockReference In AutoCAD_Block
> If (TypeOf AutoCAD_Entity Is AcadBlockReference) Then
>
> -------
>
> What is DBX? Is that the ObjectARX - the method where the drawing doesn't need to actually be opened? Actually, it seems like it's a .DLL similar to the .NET protocols?
>
> Thanks!
0 Likes
Message 10 of 12

Anonymous
Not applicable
wrote

>> could you elaborate on what other 'entities' might be?

Everything you need to know about the object model and all the entities it provides objects for, is right there in the VBA/ActiveX developers guide that comes with AutoCAD.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm
0 Likes
Message 11 of 12

Anonymous
Not applicable
Hi Laurie

I ended up making use of SelectionSets like this

Dim AutoCAD_CurrentDwg_SelectionSet As AcadSelectionSet = AutoCAD_CurrentDwg.SelectionSets.Add("Blocks_To_Modify")

Dim FilterType() As Int16 = {0}
Dim FilterData() As Object = {"Insert"}

AutoCAD_CurrentDwg_SelectionSet.Select(AcSelect.acSelectionSetAll, , , FilterType, FilterData)

For Each AutoCAD_Entity As AcadEntity In AutoCAD_CurrentDwg_SelectionSet

Try

If (TypeOf AutoCAD_Entity Is AcadBlockReference) Then

Seems to work a lot better...

Thanks!
0 Likes
Message 12 of 12

Anonymous
Not applicable
Hi Tony

I ended up finding this resource yesterday and as you said, it's most useful... I had just been looking in the wrong place (VS side, as I am used to)

Thanks!
0 Likes