I wonder if it is possible to get the correct GeometricExtents or boundingBox of a 3Dobject no matter its orientation, with .NET. I tried so many times to do this with lisp but failed. My goal was to find the width, length, height of a 3D object based off its bounding box.
Using Kerry’s code
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.ApplicationServices;
[assembly: CommandClass(typeof(aClassLibrary.CRPClass))]
namespace aClassLibrary
{
public class CRPClass
{
public CRPClass()
{
}
[CommandMethod("test")]
static public void test()
{
Extents3d extents3D;
TypedValue[] values = new TypedValue[]
{
new TypedValue((short)DxfCode.Start, "3DSOLID") ,
};
SelectionFilter filter = new SelectionFilter(values);
PromptSelectionOptions selopts = new PromptSelectionOptions();
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
selopts.MessageForAdding = "Select";
selopts.AllowDuplicates = false;
PromptSelectionResult result = ed.GetSelection(selopts, filter);
if (result.Status == PromptStatus.OK)
{
ObjectId[] idarray = result.Value.GetObjectIds();
Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager;
Transaction tr = tm.StartTransaction();
try
{
foreach (ObjectId id1 in idarray)
{
Entity entity1 = (Entity)tm.GetObject(id1, OpenMode.ForRead, true);
extents3D = entity1.GeometricExtents;
ed.WriteMessage("\n extents3D.LLPoint : " + extents3D.MinPoint.ToString());
ed.WriteMessage("\n extents3D.URPoint : " + extents3D.MaxPoint.ToString());
}
}
finally
{
tr.Dispose();
}
}
}
}
}