How to get anonymous blocks' name?

How to get anonymous blocks' name?

Anonymous
Not applicable
1,389 Views
12 Replies
Message 1 of 13

How to get anonymous blocks' name?

Anonymous
Not applicable
Hi all,
I am writing some code to solve this:

I have a drawing containing simple blocks and "compound" blocks (blocks composed by smaller blocks). I prompt the user to select a block. If the block is a simple one, I simply show its name. Otherwise, I have to get the names of its sub-blocks and show them to the user.

When I thought I got it, I saw that when exploding some compound blocks (using AcDbEntity::explode()), some of the entities returned are anonymous blocks (*U80, *U67, ...). I tried to get its name reading BlockTableRecord, but I get the anonymous autogenerated name. I checked if the blocks are dynamic (so as to take its name from DynamicBlockTableRecord), but they aren't.

Can anybody help me?

P.S.: I am using AutoCAD 2006 and ObjectARX 2006

Thanks in advance 🙂
0 Likes
1,390 Views
12 Replies
Replies (12)
Message 2 of 13

Anonymous
Not applicable
The name of an anonymous block?

What you refer to as the 'autogenerated name'
(the string starting with "*U", followed by an
ordinal number) is the only 'name' there is.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5445051@discussion.autodesk.com...
Hi all,
I am writing some code to solve this:

I have a drawing containing simple blocks and "compound" blocks (blocks composed by smaller blocks). I prompt the user to select a block. If the block is a simple one, I simply show its name. Otherwise, I have to get the names of its sub-blocks and show them to the user.

When I thought I got it, I saw that when exploding some compound blocks (using AcDbEntity::explode()), some of the entities returned are anonymous blocks (*U80, *U67, ...). I tried to get its name reading BlockTableRecord, but I get the anonymous autogenerated name. I checked if the blocks are dynamic (so as to take its name from DynamicBlockTableRecord), but they aren't.

Can anybody help me?

P.S.: I am using AutoCAD 2006 and ObjectARX 2006

Thanks in advance 🙂
0 Likes
Message 3 of 13

Anonymous
Not applicable
Hi Tony,
I am a little bit confused at this time... I am an AutoCAD newbie, and I still have a weak knowledge on this

When I take one of the 'compound' blocks in my drawing and I explode it using the XPLODE command, the resulting blocks are named blocks (I can see its name at the properties page). But if I try to access to the block components using AcDbEntity::explode, I get anonymous block references. What I need to do is to get the name I see using the XPLODE command.

At this moment I was trying to do this avoiding to explode the block at the drawing, because at last I would need to build again the original block... Anyway, if there is not another way to get what I need, I will implement this workaround...

I think the fact I still don't understand very well the 'anonymous block' concept does not help. I have been searching more information on this, but I haven't found much things...

Any kind of help with this will be welcome

Thank you very much 😉
0 Likes
Message 4 of 13

Anonymous
Not applicable
A block reference is basically a reference to a block definition plus a matrix to control it's movement/rotation etc. It has no name of its own.

A block definition is a named collection of entities. These entities may be block references which may yield many levels of nested blocks.

AFAIK, the only difference between a named and unnamed block is that the latter's name start with an '*'. There are some special blocks, model and paper spaces that also has names beginning with '*'.

Henrik Vallgren
0 Likes
Message 5 of 13

Anonymous
Not applicable
Hi Henry,
Thanks for your help. Now things seem a little more clearer.

I still don't know how AutoCAD does it to show a 'comprehensive' name (i.e. 'MYBLOCK1') after executing XPLODE, while I get an '*U..." name when I call AcDbEntity::explode

Anyway, thank you very much
0 Likes
Message 6 of 13

Anonymous
Not applicable
I'm having trouble believing that it would generate different names ... could there be multiple blocks? Then there are dimensions: those are sort of blocks.

There's an excellent sample, ARXDBG(samples/database/arxdbg), that will let you examine the dwg structure. Take a look at it. After building and loading the arx, right click and the added commands will show.
0 Likes
Message 7 of 13

Anonymous
Not applicable
Hi again,
Thank you so much for your help. But I still have another problem: I am working with VS 2005 and AutoCAD 2006, and VS 2005 is unable to compile the ARXDBG sample.

I also have ObjectARX 2007, and I compiled the 2007 ARXDBG sample, but it does not work with AutoCAD 2006. I think I will have to wait until I got a copy of VS 2003, unless you could kindly pack the build results and attach or email them (I used winrar to pack the ObjectARX2007 version, and the resulting file size is 8 Mb)

My email address is ruben[dot]dopico[at]gmail[dot]com

Anyway, don't worry If you could not do so. I think I can get a VS 2003 copy.

Thanks again

Rubén Dopico
0 Likes
Message 8 of 13

Anonymous
Not applicable
Hi (once again... :-D)
While I don't have installed the VS2003, I am trying to get more information from the blocks by other means.

This is the code I am using to get the entities contained by a block:

'-------------------------------------------------------------------------------

Dim subBlocks As New DBObjectCollection()

' br is a BlockReference object
br.Explode(subBlocks)

For Each subBlock As DBObject In subBlocks

Dim subBlockName As String = ""
If (TypeOf subBlock Is BlockReference) Then
' Gets name from BlockTableRecord
' BlockUtils is a custom class
subBlockName = BlockUtils.GetBlockName(CType(subBloque, BlockReference))

Else
subBlockName = subBlock.GetType().Name
End If

Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(subBlockName & vbCrLf)

Next subBlock

'-------------------------------------------------------------------------------

When I select one of the blocks which seem to contain anonymous objects, this is what I get:

*U78
*U80
MYBLOCK1
MYBLOCK2
Line
Line
Line
Line
Line
Line
Line
Line
Line
Line
Line
DBText

If I use de XPLODE command, I get also four blocks. Looking at the properties panel, I can see that blocks I suppossed anonymous, have a name which does not start with *U...

I don't know if this is enough to check that my *U... are not dimensions, or any other kind of blocks...

I will keep investigating... If I discover something more, I will come back

Thanks again 🙂
0 Likes
Message 9 of 13

Anonymous
Not applicable
VS 2003 won't help
You need 2002 for Acad2006

/matt

wrote in message news:5454230@discussion.autodesk.com...
Hi again,
Thank you so much for your help. But I still have another problem: I am
working with VS 2005 and AutoCAD 2006, and VS 2005 is unable to compile the
ARXDBG sample.

I also have ObjectARX 2007, and I compiled the 2007 ARXDBG sample, but it
does not work with AutoCAD 2006. I think I will have to wait until I got a
copy of VS 2003, unless you could kindly pack the build results and attach
or email them (I used winrar to pack the ObjectARX2007 version, and the
resulting file size is 8 Mb)

My email address is ruben[dot]dopico[at]gmail[dot]com

Anyway, don't worry If you could not do so. I think I can get a VS 2003
copy.

Thanks again

Rubén Dopico
0 Likes
Message 10 of 13

Anonymous
Not applicable
Hi Matt,
Thank you very much for your advice 😉

Regards
0 Likes
Message 11 of 13

Anonymous
Not applicable
Hi all,
I think I have to reformulate my question...

I exploded the block using the AcDbBlockReference::ExplodeToOwnerSpace() method, and then I used my code to get the name of the resulting blocks. The result was the same than using AcDbBlockReference::Explode(). It is OK, because as expected, the behaviour of both functions is coherent. But it is very very frustrating because when I look at the AutoCAD properties panel, I still see a name which does not start with *U (i.e. MYBLOCK3)

So, the question is now the following:

What does AutoCAD do to show a name at the properties panel which is not an anonymous block name?

Thanks a lot for your help and patience 🙂

Regards
0 Likes
Message 12 of 13

Anonymous
Not applicable
Here I am once again, assuming the risk of turning this thread in a monologue (just a joke, thanks to all for your help)...

Well, I read at a forum thread (http://discussion.autodesk.com/adskcsp/thread.jspa?threadID=475274) that "REFEDIT"ing a dynamic block, it will lose its dynamicness and become an unnamed block.

Well, just for experimenting, I did it with my compound block: I called REFEDIT, selected the subblocks my app showed as anonymous (*U...), and without modifying them I saved the changes. Then I executed again my app, and surprisingly, the app showed the name AutoCAD was showing for them at the properties panel (MYBLOCK3 and MYBLOCK4).

Does anybody know what is happening with this blocks? Why (after executing REFEDIT) can I see its name looking at BlockTableRecord.Name property?

I have been experimenting a little more with those blocks:
- Although BlockReference.IsAnonymous() returns TRUE, they haven't a valid AnonymousBlockTableReference.
- I tried to convert them to static blocks using BlockReference.ConvertToStaticBlock(), but the result was the ACad:eNoDatabase error
- Also, this blocks are no external references (BlockReference.IsFromExternalReference returns FALSE)

Any ideas?

Thanks again 😉
0 Likes
Message 13 of 13

Anonymous
Not applicable
Hi all,
Thank God, I found a solution to my problem... I found the answer in this "Visual Basic Customization" thread:

http://discussion.autodesk.com/thread.jspa?messageID=5240184

After exploring the values contained in the XData property of my blocks, I found the anonymous ones has a value named 'AcDbBlockRepBTag'. Fortunately, this lead me to the cited thread. There, I discovered that the typed value with the group code 1005 contained the handle to the 'real' BlockTableReference for the anonymous blocks in HEX format

Anyway, I don't know why it happens this way... I mean: why this blocks are stored this way? How can I replicate this situation? Is it due to a wrong use of AutoCAD, dynamic blocks or else?

It would be fantastic if at last I could understand why is it happening.

Anyway, I want to thank you all for the given help (including the people who write the thread cited at this post)

Regards

Rubén Dopico
0 Likes