.NET

Reply
Member
ScottSpringfield
Posts: 4
Registered: ‎07-23-2008
Message 1 of 7 (495 Views)

Keeping track of Dynamic Blocks

495 Views, 6 Replies
07-24-2008 07:46 AM
I am trying to write a program in VB.NET in which I search for a specific dynamic block in an already existing drawing. The problem I'm having is that when I search for the block name I get the Anonymous name (ie *Uxx). How can i find the reference to the original block name of the dynamic blocks?
*Tony Tanzillo
Message 2 of 7 (495 Views)

Re: Keeping track of Dynamic Blocks

07-24-2008 02:16 PM in reply to: ScottSpringfield
You need to be more specific as to what you mean by 'search for'

Do you mean selection set filtering, or manually examining every block reference?

One way to find all references to a dynamic block, is to examine all anonymous block references, and compare the DynamicBlockTableRecord property of each to the ObjectId of the dynamic block definition.

Another way is to open the dynamic block (BlockTableRecord) and call its GetAnonymousBlockIds() function. Then, loop through the result and open each anonymous block table record and call its GetBlockReferenceIds() method to get the references to each anonymous block, like this:

[code]

public static class BlockHelper
{

/// Pass ObjectId of a block (BlockTableRecord), and this
/// returns the ObjectIds of all references to the block,
/// including all dynamic block references. This method
/// provides a uniform way to get the ids of all blockrefs,
/// regardless of whether the block is dynamic or not.

static ObjectIdCollection GetBlockReferenceIds( ObjectId btrId )
{
if( btrId.IsNull )
throw new ArgumentException( "null object id" );
ObjectIdCollection result = new ObjectIdCollection();
using( Transaction trans = btrId.Database.TransactionManager.StartTransaction() )
{
try
{
/// open the BlockTableRecord:

BlockTableRecord btr = trans.GetObject( btrId, OpenMode.ForRead ) as BlockTableRecord;
if( btr != null )
{
// Add the ids of all references to the BTR. Some dynamic blocks may
// reference the dynamic block directly rather than an anonymous block,
// so this will get those as well:

ObjectIdCollection blockRefIds = btr.GetBlockReferenceIds( true, false );
if( blockRefIds != null )
{
foreach( ObjectId id in blockRefIds )
result.Add( id );
}

// if this is not a dynamic block, we're done:

if( !btr.IsDynamicBlock )
return result;

// Get the ids of all anonymous block table records for the dynamic block

ObjectIdCollection anonBtrIds = btr.GetAnonymousBlockIds();
if( anonBtrIds != null )
{
foreach( ObjectId anonBtrId in anonBtrIds )
{
// get all references to each anonymous block:

BlockTableRecord rec = trans.GetObject( anonBtrId, OpenMode.ForRead ) as BlockTableRecord;
if( rec != null )
{
blockRefIds = rec.GetBlockReferenceIds( false, true );
if( blockRefIds != null )
{
foreach( ObjectId id in blockRefIds )
result.Add( id );
}
}
}
}
}
}
finally
{
trans.Commit();
}
}
return result;
}

}

[/code]

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

wrote in message news:5989553@discussion.autodesk.com...
I am trying to write a program in VB.NET in which I search for a specific dynamic block in an already existing drawing. The problem I'm having is that when I search for the block name I get the Anonymous name (ie *Uxx). How can i find the reference to the original block name of the dynamic blocks?
*Roland Feletic
Message 3 of 7 (495 Views)

Re: Keeping track of Dynamic Blocks

07-25-2008 12:39 AM in reply to: ScottSpringfield
Thank you, Tony.
*Roland Feletic
Message 4 of 7 (495 Views)

Re: Keeping track of Dynamic Blocks

07-25-2008 12:50 AM in reply to: ScottSpringfield
Hi Tony,
I get this error when I try to compyle this code.

'Autodesk.AutoCAD.DatabaseServices.BlockTableRecord' does not contain a
definition for 'GetAnonymousBlockIds' and no extension method
'GetAnonymousBlockIds' accepting a first argument of type
'Autodesk.AutoCAD.DatabaseServices.BlockTableRecord' could be found (are you
missing a using directive or an assembly reference?)

Do you have any idea?

Roland
Distinguished Contributor
fixo
Posts: 116
Registered: ‎05-27-2007
Message 5 of 7 (495 Views)

Re: Keeping track of Dynamic Blocks

07-25-2008 01:37 AM in reply to: ScottSpringfield
I have a got the same exeption with
'GetAnonymousBlockIds' :smileysad:

~'J'~
*Tony Tanzillo
Message 6 of 7 (495 Views)

Re: Keeping track of Dynamic Blocks

07-25-2008 01:28 PM in reply to: ScottSpringfield
Oops.

Looks like GetAnonymousBlockIds() is new to AutoCAD 2009, which you're obviously not using.

You have to take the other route, gathering all block references, and then looking each one's DynamicBlockTableRecord property.


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

"Roland Feletic" wrote in message news:5990363@discussion.autodesk.com...
Hi Tony,
I get this error when I try to compyle this code.

'Autodesk.AutoCAD.DatabaseServices.BlockTableRecord' does not contain a
definition for 'GetAnonymousBlockIds' and no extension method
'GetAnonymousBlockIds' accepting a first argument of type
'Autodesk.AutoCAD.DatabaseServices.BlockTableRecord' could be found (are you
missing a using directive or an assembly reference?)

Do you have any idea?

Roland
*Roland Feletic
Message 7 of 7 (495 Views)

Re: Keeping track of Dynamic Blocks

07-28-2008 12:25 AM in reply to: ScottSpringfield
Sorry, it was my fault. Now I've seen that i had the wrong acdbmgd.dll and
acmgd.dll. Changed it to 2009 and now it works. Thank you again.

"Tony Tanzillo" schrieb im Newsbeitrag
news:5991086@discussion.autodesk.com...
Oops.

Looks like GetAnonymousBlockIds() is new to AutoCAD 2009, which you're
obviously not using.

You have to take the other route, gathering all block references, and then
looking each one's DynamicBlockTableRecord property.


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

"Roland Feletic" wrote in message
news:5990363@discussion.autodesk.com...
Hi Tony,
I get this error when I try to compyle this code.

'Autodesk.AutoCAD.DatabaseServices.BlockTableRecord' does not contain a
definition for 'GetAnonymousBlockIds' and no extension method
'GetAnonymousBlockIds' accepting a first argument of type
'Autodesk.AutoCAD.DatabaseServices.BlockTableRecord' could be found (are you
missing a using directive or an assembly reference?)

Do you have any idea?

Roland
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.