.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Keeping track of Dynamic Blocks

6 REPLIES 6
Reply
Message 1 of 7
ScottSpringfield
980 Views, 6 Replies

Keeping track of Dynamic Blocks

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

Thank you, Tony.
Message 4 of 7
Anonymous
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
Message 5 of 7
fixo
in reply to: ScottSpringfield

I have a got the same exeption with
'GetAnonymousBlockIds' 😞

~'J'~
Message 6 of 7
Anonymous
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
Message 7 of 7
Anonymous
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

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost