All entities have at least one coordinate, but each class elaborates them differently, so approaching the problem using coordinates is difficult as it requires you to deal with each type of entity using a different code path.
Here is a much simpler way to do it:
using Autodesk.AutoCAD.Geometry;
using AcRx = Autodesk.AutoCAD.Runtime;
namespace Autodesk.AutoCAD.DatabaseServices.MyEntityExtensions;
public static class EntityExtensions
{
public static bool TranslateToXYPlane(this Entity entity)
{
if(entity == null)
throw new ArgumentNullException(nameof(entity));
double z = entity.GetBoundingBox().MinPoint.Z;
if(Math.Abs(z) > 1.0e-5)
{
if(!entity.IsWriteEnabled)
entity.UpgradeOpen();
entity.TransformBy(Matrix3d.Displacement(new Vector3d(0, 0, z).Negate()));
return true;
}
return false;
}
/// <comments>
/// We can't universally use GeometryExtentsBestFit() on any
/// block reference without risking an exception, which happens
/// with non uniformly-scaled block references. This code tries
/// to work around it, but falls-back with non uniformly-scaled
/// block references, resulting in a possibly-erroneous result.
/// </comments>
public static Extents3d GetBoundingBox(this Entity entity)
{
if(entity is BlockReference br)
{
try
{
return br.GeometryExtentsBestFit(Matrix3d.Identity);
}
catch(AcRx.Exception ex)
{
if(ex.ErrorStatus != AcRx.ErrorStatus.InvalidInput) // NUS blockref
throw ex;
}
}
return entity.GeometricExtents;
}
}
Open each each entity, and invoke the TranslateToXYPlane() extension method on it.