.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to use GetBoundingBox ?

2 REPLIES 2
Reply
Message 1 of 3
JanneTS
3033 Views, 2 Replies

How to use GetBoundingBox ?

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?

2 REPLIES 2
Message 2 of 3
norman.yuan
in reply to: JanneTS

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();
            }
        }
    }
Message 3 of 3
JanneTS
in reply to: norman.yuan

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?

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost