[CommandMethod("TestGetObjects1")]
public void get1()
{
GC.Collect();
GC.Collect();
GC.Collect();
System.Diagnostics.Stopwatch timer
= new System.Diagnostics.Stopwatch(); timer.Start();
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Database db = Application.DocumentManager.MdiActiveDocument.Database;
List
<PileTuple
> piles
= new List
<PileTuple
>(); RXClass rxc
= RXClass
.GetClass(typeof(Line
)); using (Transaction tr = db.TransactionManager.StartTransaction())
{
try
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
foreach (ObjectId BTRid in bt)
{
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(BTRid, OpenMode.ForRead);
foreach (var id in btr)
{
if (id.ObjectClass != rxc) continue;
Entity ent = (Entity)tr.GetObject(id, OpenMode.ForRead);
ResultBuffer rb = ent.GetXDataForApplication(AppName);
if (rb == null) continue;
TypedValue[] tvs = rb.AsArray();
if (tvs[1].Value.ToString() != "508") continue;
Point3d pt = (Point3d)tvs[60].Value;
piles
.Add(new PileTuple
() { id
= id, Location
= new Point2d
(pt
.X, pt
.Y), Xdata
= tvs
}); }
}
int n = 100;
foreach (var pile in piles.OrderBy(a=>a.Location.X).OrderBy(a=>a.Location.Y))
{
Entity ent = (Entity)tr.GetObject(pile.id, OpenMode.ForWrite);
pile
.Xdata[42] = new TypedValue
(pile
.Xdata[42].TypeCode, n
++.ToString()); ent
.XData = new ResultBuffer
(pile
.Xdata); }
}
catch (System.Exception e)
{
ed.WriteMessage(e.ToString());
}
tr.Commit();
}
GC.Collect();
timer.Stop();
ed.WriteMessage("\n{0}", timer.ElapsedTicks);
}
[CommandMethod("TestGetObjects2")]
public void get2()
{
GC.Collect();
GC.Collect();
GC.Collect();
System.Diagnostics.Stopwatch timer
= new System.Diagnostics.Stopwatch(); timer.Start();
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
using (Database db = Application.DocumentManager.MdiActiveDocument.Database)
{
List
<PileTuple
> piles
= new List
<PileTuple
>(); using (RXClass rxc
= RXClass
.GetClass(typeof(Line
))) {
using (Transaction tr = db.TransactionManager.StartTransaction())
{
try
{
using (BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead))
{
foreach (ObjectId BTRid in bt)
{
using (BlockTableRecord btr = (BlockTableRecord)tr.GetObject(BTRid, OpenMode.ForRead))
{
foreach (var id in btr)
{
if (id.ObjectClass != rxc) continue;
Entity ent = (Entity)tr.GetObject(id, OpenMode.ForRead);
ResultBuffer rb = ent.GetXDataForApplication(AppName);
ent.Dispose();
if (rb == null) continue;
TypedValue[] tvs = rb.AsArray();
if (tvs[1].Value.ToString() != "508") continue;
Point3d pt = (Point3d)tvs[60].Value;
piles
.Add(new PileTuple
() { id
= id, Location
= new Point2d
(pt
.X, pt
.Y), Xdata
= tvs
}); }
}
}
}
int n = 100;
foreach (var pile in piles.OrderBy(a => a.Location.X).OrderBy(a => a.Location.Y))
{
Entity ent = (Entity)tr.GetObject(pile.id, OpenMode.ForWrite);
pile
.Xdata[42] = new TypedValue
(pile
.Xdata[42].TypeCode, n
++.ToString()); ent
.XData = new ResultBuffer
(pile
.Xdata); ent.Dispose();
}
}
catch (System.Exception e)
{
ed.WriteMessage(e.ToString());
}
tr.Commit();
}
}
}
GC.Collect();
timer.Stop();
ed.WriteMessage("\n{0}", timer.ElapsedTicks);
}