public static class MyClass
{
public static string GetBlockName( ObjectId tableId, string prefix )
{
ArrayList names = new ArrayList();
using( Transaction tr = tableId.Database.TransactionManager.StartTransaction() )
{
SymbolTable table = (SymbolTable) tr.GetObject( TableId, OpenMode.ForRead );
foreach(ObjectId id in table)
{
if( ! id.IsErased )
{
SymbolTableRecord rec = (SymbolTableRecord) tr.GetObject( id, OpenMode.ForRead );
if( rec.Name.StartsWith( prefix, StringComparison.InvariantCultureIgnoreCase ) )
names.Add( rec.Name );
}
}
}
names.Sort();
int n = 0;
while( names.BinarySearch( string.Format( "{0}{1}", prefix, n)) > -1 )
{
++n;
}
return string.Format( "{0}{1}", prefix, n );
}
}
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com
wrote in message news:5437283@discussion.autodesk.com...
Does someone have a sample of, or can point in the right direction for searching through blocks in the current file to determine the most recent one.
For example. The current document has blocks called Base1, Base2, Base3, Wall1, Wall2, Wall3 and I want to find out what the last Base# is so that I can create the next in the sequence?
VB code would great but I could probably pick through C# as well. Thanks.