I make advantage of this challenge to keep on learning C# (even it's a LISP forum, sorry CAB).
I tried a way using a selection set rather than scanning all database, it seems to be a little faster (0.5 on my system).
Thanks to Kerry for all the nice little tricks he shows me.
using System;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
namespace Point2Circle
{
public class MyClass
{
[CommandMethod("Test2")]
public void Test2()
{
DateTime start = DateTime.Now;
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Database db = HostApplicationServices.WorkingDatabase;
TypedValue[] tValues = { new TypedValue((int)DxfCode.Start, "POINT") };
SelectionFilter selFilter = new SelectionFilter(tValues);
PromptSelectionResult result = ed.SelectAll(selFilter);
if (result.Status == PromptStatus.OK)
{
ObjectId[] selSet = result.Value.GetObjectIds();
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
foreach (ObjectId objId in selSet)
{
DBPoint pt = tr.GetObject(objId, OpenMode.ForWrite) as DBPoint;
if (pt != null)
{
Circle c = new Circle(pt.Position, pt.Normal, 15.0);
pt.Erase();
btr.AppendEntity(c);
tr.AddNewlyCreatedDBObject(c, true);
}
}
tr.Commit();
TimeSpan time = (DateTime.Now - start);
ed.WriteMessage("Elapsed time: {0} seconds", (time.TotalSeconds));
}
}
}
}
}