.NET

.NET

Reply
Member
rjhinton
Posts: 5
Registered: ‎01-29-2010
Message 1 of 5 (128 Views)

My MinBoundBox class not longer works in 2015

128 Views, 4 Replies
05-06-2014 12:57 PM

The follow class has worked flawlessly in the last several versions of AutoCAD. But something seems to have change with version 2015 and I can't figure out how fix it. Any help would very much be appreciated.

 

    public class MinBoundBox
    {
        public double[] GetMinBoundBox(ObjectId orgSolidId)
        {
            double[] Size = new double[3];
            bool Changed;
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                Solid3d orgSolid = tr.GetObject(orgSolidId, OpenMode.ForRead) as Solid3d;
                Solid3d newSolid = orgSolid.Clone() as Solid3d;
                tr.Dispose();
                do
                {
                    newSolid = minvolume(newSolid, true, new Vector3d(1, 0, 0), out Changed);
                    newSolid = minvolume(newSolid, false, new Vector3d(1, 0, 0), out Changed);
                    newSolid = minvolume(newSolid, true, new Vector3d(0, 1, 0), out Changed);
                    newSolid = minvolume(newSolid, false, new Vector3d(0, 1, 0), out Changed);
                    newSolid = minvolume(newSolid, true, new Vector3d(0, 0, 1), out Changed);
                    newSolid = minvolume(newSolid, false, new Vector3d(0, 0, 1), out Changed);
                } while (Changed);
                Size[0] = newSolid.MassProperties.Extents.MaxPoint.X - newSolid.MassProperties.Extents.MinPoint.X;
                Size[1] = newSolid.MassProperties.Extents.MaxPoint.Y - newSolid.MassProperties.Extents.MinPoint.Y;
                Size[2] = newSolid.MassProperties.Extents.MaxPoint.Z - newSolid.MassProperties.Extents.MinPoint.Z;
                Array.Sort(Size);
                return Size;
            }
        }

        private Solid3d minvolume(Solid3d tmpSolid, bool PosRot, Vector3d Vector, out bool Changed)
        {
            Point3d Centriod = tmpSolid.MassProperties.Centroid;
            double Volume = getVolume(tmpSolid.MassProperties.Extents);
            Changed = false;
            Matrix3d mat = new Matrix3d();
            double RotAng = 0.0;
            bool flag = false;
            if (PosRot)
                RotAng = 1.0;
            else
                RotAng = -1.0;
            do
            {
                mat = Matrix3d.Rotation(RotAng, Vector, Centriod);
                tmpSolid.TransformBy(mat);
                if (Volume < getVolume(tmpSolid.MassProperties.Extents))
                {
                    mat = Matrix3d.Rotation(-RotAng, Vector, Centriod);
                    tmpSolid.TransformBy(mat);
                    flag = false;
                }
                else
                {
                    Volume = getVolume(tmpSolid.MassProperties.Extents);
                    flag = true;
                    Changed = true;
                }
            } while (flag);
            if (PosRot)
                RotAng = 0.1;
            else
                RotAng = -0.1;
            do
            {
                mat = Matrix3d.Rotation(RotAng, Vector, Centriod);
                tmpSolid.TransformBy(mat);
                if (Volume < getVolume(tmpSolid.MassProperties.Extents))
                {
                    mat = Matrix3d.Rotation(-RotAng, Vector, Centriod);
                    tmpSolid.TransformBy(mat);
                    flag = false;
                }
                else
                {
                    Volume = getVolume(tmpSolid.MassProperties.Extents);
                    flag = true;
                    Changed = true;
                }
            } while (flag);
            if (PosRot)
                RotAng = 0.01;
            else
                RotAng = -0.01;
            do
            {
                mat = Matrix3d.Rotation(RotAng, Vector, Centriod);
                tmpSolid.TransformBy(mat);
                if (Volume < getVolume(tmpSolid.MassProperties.Extents))
                {
                    mat = Matrix3d.Rotation(-RotAng, Vector, Centriod);
                    tmpSolid.TransformBy(mat);
                    flag = false;
                }
                else
                {
                    Volume = getVolume(tmpSolid.MassProperties.Extents);
                    flag = true;
                    Changed = true;
                }
            } while (flag);
            if (PosRot)
                RotAng = 0.001;
            else
                RotAng = -0.001;
            do
            {
                mat = Matrix3d.Rotation(RotAng, Vector, Centriod);
                tmpSolid.TransformBy(mat);
                if (Volume < getVolume(tmpSolid.MassProperties.Extents))
                {
                    mat = Matrix3d.Rotation(-RotAng, Vector, Centriod);
                    tmpSolid.TransformBy(mat);
                    flag = false;
                }
                else
                {
                    Volume = getVolume(tmpSolid.MassProperties.Extents);
                    flag = true;
                    Changed = true;
                }
            } while (flag);
            return tmpSolid;
        }


        private double getVolume(Extents3d Value)
        {
            double w = Value.MaxPoint.X - Value.MinPoint.X;
            double d = Value.MaxPoint.Y - Value.MinPoint.Y;
            double l = Value.MaxPoint.Z - Value.MinPoint.Z;
            return w * d * l;
        }
    }

 

 

 

ADN Support Specialist
madhukar.moogala
Posts: 67
Registered: ‎01-28-2014
Message 2 of 5 (105 Views)

Re: My MinBoundBox class not longer works in 2015

05-08-2014 02:17 AM in reply to: rjhinton

Hi ,

 Can you please share DWG file on which you can reproduce the behavior, I have intergated your code and compiled compiled for ACAD2015 and tested on basic solids like Extrusion ,Sweep ,Box etc. I didnt find any problem.
  "My MinBoundBox class not longer works in 2015" ? Do you mean to say you are encountering application exceptions or crash.

 

Thanks.

 

ADN Support Specialist
Member
rjhinton
Posts: 5
Registered: ‎01-29-2010
Message 3 of 5 (96 Views)

Re: My MinBoundBox class not longer works in 2015

05-08-2014 05:12 AM in reply to: madhukar.moogala

It appears to me that GeometricExtents and MassProperties.Extents are not returning the correct Exetent3d data. The solid in the included drawing file was create by drawing line to form a closed shape then using pedit to create a closed polyline and then extruded to create a solid. I noticed that MassProperties.Extents.MinPoint returns 0,0,0 no matter how far the solid is from origin. GeometricExtents does not return the correct extents after cloning.

 

Thank you for your assistance with this issue,

Robert

Member
rjhinton
Posts: 5
Registered: ‎01-29-2010
Message 4 of 5 (93 Views)

Re: My MinBoundBox class not longer works in 2015

05-08-2014 06:12 AM in reply to: madhukar.moogala

I've attached an additional drawing showing the bounding box return by GeometricExtents before and after TransformBy operation.

ADN Support Specialist
madhukar.moogala
Posts: 67
Registered: ‎01-28-2014
Message 5 of 5 (70 Views)

Re: My MinBoundBox class not longer works in 2015

05-09-2014 02:46 AM in reply to: rjhinton

Thanks for DWG files, I have understood your problem,will get back to you once I'm done analysing.

ADN Support Specialist
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.