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?