Entity.GeometricExtents throws an exception (eNullExtents)

By Marat Mirgaleev

Issue

When I calculate the extents of entities in a drawing, for some entities an exception is thrown with the "eNullExtents" message. What is wrong?

Solution

This exception occurs for an insert of an empty block or for an empty block attribute. It is "as designed", it’s just a notification to the developer about an empty object. An easy solution is to add a separate catch block for this particular exception:

Extents3d extents;          try          {            extents = pEntity.GeometricExtents;          }          catch (Autodesk.AutoCAD.Runtime.Exception ex)          {            if (ex.Message == "eNullExtents")            // The entity is empty and has no extents            {              // TODO. We can simply skip this entity...            }            else            //  something is wrong ...              TODO!          }

Comments

2 responses to “Entity.GeometricExtents throws an exception (eNullExtents)”

  1. Hi, Marat
    I think we may use this way as well:
    if(pEntity.Bounds.HasValue)
    {
    extents = pEntity.GeometricExtents;
    }
    else
    {
    ed.WrieMessage(“\nNo chance, sorry…\n”);
    return;
    }

  2. Not only an empty block will throw the “eNullExtents” exception, but the ProfileView.GeometricExtents also throws.

Leave a Reply to OlegCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading