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; } }
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.
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
I've attached an additional drawing showing the bounding box return by GeometricExtents before and after TransformBy operation.
Thanks for DWG files, I have understood your problem,will get back to you once I'm done analysing.