Yes,
This is a known "issue". It has to do with initialization of the MPolygon.
You could try this:
public void getboundingboxinfo(ObjectId[] objs, ref double[] box)
{
DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
try
{
using (Transaction t = db.TransactionManager.StartTransaction())
{
foreach (ObjectId obj in objs)
{
Entity ent = (Entity)t.GetObject(obj, OpenMode.ForRead);
MPolygon mpoly = ent as MPolygon;
if (mpoly != null)
{
//
// Extents3d e = mpoly.GeometricExtents;
// ... does not work ... known issue with Autodesk
//
// ................ so we extract the outer vertices
//
int loops = mpoly.NumMPolygonLoops;
for (int i = 0; i < loops; i++)
{
MPolygonLoop mPolygonLoop = mpoly.GetMPolygonLoopAt(i);
// the count of 2d points
int verts = mPolygonLoop.Count;
// the count of ordinates
foreach (BulgeVertex bv in mPolygonLoop)
{
Point2d a2dp = bv.Vertex;
if ((a2dp.X < box[0]) || (box[0] == 0.0)) box[0] = a2dp.X;
if ((a2dp.Y < box[1]) || (box[1] == 0.0)) box[1] = a2dp.Y;
box[2] = 0F;
if ((a2dp.X > box[3]) || (box[3] == 0.0)) box[3] = a2dp.X;
if ((a2dp.Y > box[4]) || (box[4] == 0.0)) box[4] = a2dp.Y;
box[5] = 0F;
}
}
}
}
t.Commit();
}
}
catch (Autodesk.AutoCAD.Runtime.Exception) { }
catch (System.Exception) { }
finally
{
docLock.Dispose();
}
}
AutoCAD 2007 / VS.NET 2005
Hi all,
I'm getting erroneous values for GeometricExtents.MinPoint of a database resident MPolygon entity. It always defaults to 0,0,0 neverthless of MPolygon's actual location in space. On the other hand, GeometricExtents.MaxPoint returns correct results.
Please find attached sample drawing.
Regards,
Maksim Sestic