Sure, I would agree that this would be very useful, but not as en extension method to the Entity class.
Maybe adding methods to the DBObjectCollection might fit this case better ?
internal static class DBObjectCollectionExtension
{
internal static ObjectIdCollection AddToModelSpace(this DBObjectCollection ents)
{
Database Db = HostApplicationServices.WorkingDatabase;
return AddToModelSpace(ents, Db);
}
internal static ObjectIdCollection AddToModelSpace(this DBObjectCollection ents, Database Db)
{
ObjectIdCollection objIdCollection = new ObjectIdCollection();
if (ents == null)
{
throw new ArgumentNullException();
}
if (Db == null)
{
throw new ArgumentNullException();
}
AcDb.TransactionManager Tm = Db.TransactionManager;
using (Transaction tr = Tm.StartTransaction())
{
BlockTable tb = (BlockTable)Tm.GetObject
(Db.BlockTableId, OpenMode.ForRead, false);
BlockTableRecord btr = (BlockTableRecord)Tm.GetObject
(tb[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);
foreach (Entity e in ents)
{
objIdCollection.Add(btr.AppendEntity(e));
Tm.AddNewlyCreatedDBObject(e, true);
}
tr.Commit();
}
return objIdCollection;
}
}
example
[CommandMethod("test")]
static public void cmdtest()
{
DBObjectCollection DbObjCollection = new DBObjectCollection();
DbObjCollection.Add(new Line(new Point3d(0,0,0),new Point3d(100,0,0)));
DbObjCollection.Add(new Line(new Point3d(100, 0, 0), new Point3d(100, 100, 0)));
DbObjCollection.Add(new Line(new Point3d(100, 100, 0), new Point3d(0, 100, 0)));
DbObjCollection.Add(new Line(new Point3d(0, 100, 0), new Point3d(0, 0, 0)));
DbObjCollection.AddToModelSpace();
}