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

Next available block in sequence

6 REPLIES 6
Reply
Message 1 of 7
Anonymous
209 Views, 6 Replies

Next available block in sequence

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.
6 REPLIES 6
Message 2 of 7
McSwiller
in reply to: Anonymous

Using a snippet like this:


Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager = sourceDb.TransactionManager
Dim blT As Transaction = tm.StartTransaction
Dim dbt As BlockTable = CType(blT.GetObject(sourceDb.BlockTableId, OpenMode.ForRead, True), BlockTable) 'destination block table (this current drawing's block table) Dim btr As BlockTableRecord

Try
Dim boId As ObjectId 'block record Id holder
boId = dbt(blkTblRecName) 'this is where you grab a block table record id by name....
Dim btr As BlockTableRecord = CType(tm.GetObject(boId, OpenMode.ForRead, False), BlockTableRecord)


btr.Dispose()

dbt.Dispose()
' No need to commit
blT.Dispose()
tm.Dispose()

Catch ex As Exception

End Try

-You can find a block table record id by name; looping though incrementally, and not finding one by its name could be caught in the Catch area of the Try block - at least then you'd have the current number to use next.

Cheers.
Message 3 of 7
Anonymous
in reply to: Anonymous

try this idea.

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.
Message 4 of 7
Anonymous
in reply to: Anonymous

Not need to have opened the block for write, I should have
just opened for read.

"Paul Richardson" wrote in message
news:5437646@discussion.autodesk.com...
try this idea.

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.
Message 5 of 7
Anonymous
in reply to: Anonymous

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.
Message 6 of 7
Anonymous
in reply to: Anonymous

BTW, the name I gave to that method ("GetBlockName"), is
a bit misleading, as it works for any kind of symbol table.

--
http://www.caddzone.com

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

"Tony Tanzillo" wrote

>> public static string GetBlockName( ObjectId tableId, string prefix )
Message 7 of 7
Anonymous
in reply to: Anonymous

Nice... Thanks.
"Tony Tanzillo" wrote in message
news:5437715@discussion.autodesk.com...
BTW, the name I gave to that method ("GetBlockName"), is
a bit misleading, as it works for any kind of symbol table.

--
http://www.caddzone.com

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

"Tony Tanzillo" wrote

>> public static string GetBlockName( ObjectId tableId, string prefix )

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