Try this way, without any extension method.
// gets the polyline vertices
public static IEnumerable<Point3d> GetVertices(Polyline pline)
{
for (int i = 0; i < pline.NumberOfVertices; i++)
{
yield return pline.GetPoint3dAt(i);
}
}
[CommandMethod("GETCOORDINATESFROMBLOCK")]
public static void GetCoordinatesFromBlock()
{
var doc = AcAp.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
var options = new PromptEntityOptions("\nSelect block reference: ");
options.SetRejectMessage("\nSelected object is not a block reference.");
options.AddAllowedClass(typeof(BlockReference), true);
var result = ed.GetEntity(options);
if (result.Status != PromptStatus.OK)
return;
using (var tr = db.TransactionManager.StartTransaction())
{
// get the selected block reference
var blockReference = (BlockReference)tr.GetObject(result.ObjectId, OpenMode.ForRead);
// get the block definition
var blockDefinition = (BlockTableRecord)tr.GetObject(blockReference.BlockTableRecord, OpenMode.ForRead);
// collect the polyline vertices in the block definition and transform them as the block reference
var points =
blockDefinition // from the block definition
.Cast<ObjectId>() // get all polylines
.Where(id => id.ObjectClass.DxfName == "LWPOLYLINE")
.Select(id => (Polyline)tr.GetObject(id, OpenMode.ForRead))
.SelectMany(pl => GetVertices(pl)) // collect the polylines vertices
.Distinct() // remove duplicated points
.Select(p => p.TransformBy(blockReference.BlockTransform)) // transform each point as the block reference
.OrderByDescending(p => p.Y) // order points by Y descending
.ThenBy(p => p.X); // then by X
// print the points coordinates on the command line and add a red circle on each one
var space = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
foreach (var pt in points)
{
ed.WriteMessage($"\n{pt:0.00}");
var circle = new Circle() { Center = pt, Radius = 1.0, ColorIndex = 1 };
space.AppendEntity(circle);
tr.AddNewlyCreatedDBObject(circle, true);
}
tr.Commit();
}
}