I have a C# Navisworks 2016 plugin that uses Autocad 2016 automation. I read a handle string of an entity from Navisworks and get the corresponding object in autocad with
Autodesk.AutoCAD.Interop.Common.AcadObject ThePart = TheDoc.HandleToObject(HandleToZoom);
then I try to get the bounding box of the entity with
Autodesk.AutoCAD.Interop.Common.AcadEntity TheEnt = (Autodesk.AutoCAD.Interop.Common.AcadEntity)ThePart;
object a;
object b;
TheEnt.GetBoundingBox(out a, out b);
but the GetBoundinBox throws an exception 8020001C
Late binding doesn’t work either,
double[] aMinPoint = new double[3], aMaxPoint = new double[3];
object[] Params = new object[] { aMinPoint, aMaxPoint };
TheEnt.GetType().InvokeMember("GetBoundingBox", System.Reflection.BindingFlags.InvokeMethod, null, TheEnt, Params);
throws an exception too.
How to use the GetBoundingBox correctly?
Following code, using COM API in a .NET add-in command method, works OK with my AutoCAD2015/2016:
public class Commands { [CommandMethod("BBox")] public static void DoDocumentCommand() { Document dwg = CadApp.DocumentManager.MdiActiveDocument; Editor ed = dwg.Editor; try { //Get COM object: AcadDocument AcadDocument doc = (AcadDocument)Autodesk.AutoCAD.ApplicationServices.DocumentExtension.GetAcadDocument(dwg); //Select an entity object ent; object point; doc.Utility.GetEntity(out ent, out point, "\nSelect an entity:"); ed.WriteMessage("\nSelected entity is: {0}", (ent as AcadEntity).EntityName); //Get AcadEntity's bounding box object minPt; object maxPt; (ent as AcadEntity).GetBoundingBox(out minPt, out maxPt); ed.WriteMessage("\nMin point: {0}, {1}", (minPt as double[])[0], (minPt as double[])[1]); ed.WriteMessage("\nMax point: {0}, {1}", (maxPt as double[])[0], (maxPt as double[])[1]); } catch (Autodesk.AutoCAD.Runtime.Exception aex) { ed.WriteMessage("\nError: {0}", aex.Message); ed.WriteMessage("\n*Cancel*"); } catch (System.Exception ex) { ed.WriteMessage("\nError: {0}", ex.Message); ed.WriteMessage("\n*Cancel*"); } finally { Autodesk.AutoCAD.Internal.Utils.PostCommandPrompt(); } } }
Thanks. My problem still remains though. Now I have noticed that the exception happens only in case of 3rd party custom objects. I wonder if it's a bug or a feature that GetBoundingBox fails with custom objects?
However, I don't really need the bounding box after all, I need the part location in WCS. How to get the location of an entity via COM API, if I know it's handle?