Author Topic: GeometricExtents of a MPolygon  (Read 5153 times)

0 Members and 1 Guest are viewing this topic.

MaksimS

  • Guest
GeometricExtents of a MPolygon
« on: April 21, 2007, 06:28:06 AM »
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


MaksimS

  • Guest
Re: GeometricExtents of a MPolygon
« Reply #1 on: April 21, 2007, 06:52:58 AM »
Of course, you can always convert MPolygon to Polyline and extract GeometricExtents out of a Polyline, still sometimes this may not be straightforward thing to do as you need to take in account possible multiple outer (exterior) boundaries, etc.

Regards,
Maksim Sestic

MaksimS

  • Guest
Re: GeometricExtents of a MPolygon
« Reply #2 on: April 23, 2007, 07:31:17 AM »
Yap, it's definately a bug.

djonio

  • Guest
Re: GeometricExtents of a MPolygon
« Reply #3 on: April 23, 2007, 07:58:36 AM »
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



It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8797
  • AKA Daniel
Re: GeometricExtents of a MPolygon
« Reply #4 on: April 23, 2007, 09:41:22 AM »
Welcome djonio Nice Coding

MaksimS

  • Guest
Re: GeometricExtents of a MPolygon
« Reply #5 on: April 23, 2007, 10:44:48 AM »
Thanks for the tip, I've been collecting outer boundaries for the sake of speed but that's it.

Yes,
This is a known "issue". It has to do with initialization of the MPolygon.