Are you saying that
(LastId - FirstId) / 8 = Total number of objects
Since Int64 is 8 bytes and taking the difference between first and last would be the total number bytes and dividing by eight gives total number of objects.
[CommandMethod("FasterIteration")]
public void FasterIteration()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor; ;
long amount = 0;//common counter
Int64 firstId = db.BlockTableId.OldIdPtr.ToInt64();
Int64 lastId = Autodesk.AutoCAD.Internal.Utils.EntLast().OldIdPtr.ToInt64();
ed.WriteMessage("\n{0} {1}\n", firstId.ToString(), lastId.ToString());
amount = (long)((lastId - firstId) /;
ed.WriteMessage("\n{0}\n", amount.ToString());
}
but modifying Andreys code to output the difference between ObjectIds 98% are 8 but some will be 64, 16, 2400 etc.........
I guess the processor breaks it up into available areas?!???
[CommandMethod("SlowIteration", CommandFlags.Modal)]
public void SlowIteration()
{
Document dwg = Application.DocumentManager.MdiActiveDocument;
Database TargetDb = dwg.Database;
Editor ed = dwg.Editor;
DateTime start = DateTime.Now;
long amount = 0;//common counter
long exceptCount = 0;//exception counter
Int64 Current = 0;
Int64 previous = 0;
using (Transaction t = TargetDb.TransactionManager.StartTransaction())
{
for (long i = TargetDb.BlockTableId.Handle.Value; i < TargetDb.Handseed.Value; i )
{
amount;
ObjectId id = ObjectId.Null;
//Slow code begin:
try
{
id = TargetDb.GetObjectId(false, new Handle(i), 0);
previous = Current;
Current = id.OldIdPtr.ToInt64();
if (previous != 0)
{
ed.WriteMessage("\n{0}\n", (Current - previous) .ToString());
}
}
catch
{
exceptCount;
continue;
}
//Slow code end.
}
}
TimeSpan len = DateTime.Now - start;
ed.WriteMessage("\n{0}\n", exceptCount.ToString());
ed.WriteMessage(string.Format("Amount: {0}\nSlow iteration time: {1} min. {2} sec.\n",
amount, len.Minutes, len.Seconds));
}
If it is working you could do for or while loop going backwards from the Handseed property and the first one that does not throw error set to last then break out of the loop.