How to get AutoCAD Civil3D drawing extents from API like Civil3D does?

243 views Asked by At

I want to extract drawing extents from Civil3D dwg's using Design Automation.

If I use the code below:

static public Extents3d GetExtents(Database db) {
  try {
    //db.UpdateExt(true);

    return new Extents3d(db.Extmin, db.Extmax);
  } catch {
    return new Extents3d();
  }
}

Then I get the following result which is correct:

Min: [2538909.32, 330601.59, 0.00]
Max: [2540326.77, 331107.96, 0.00]

However, if I call db.UpdateExt(true) before or if I simply iterate all entities in model space with the code below, I get a min bound that is at origin:

static public Extents3d GetExtents(Database db) {
  try {
    var TxMng = db.TransactionManager;

    using(var Tx = TxMng.StartTransaction()) {
      var btr = Tx.GetObject(
        db.CurrentSpaceId, OpenMode.ForRead)
      as BlockTableRecord;

      foreach(var id in btr) {
        var entity = Tx.GetObject(id, OpenMode.ForRead)
        as Entity;

        extents.AddExtents(entity.GeometricExtents);
      }

      Tx.Commit();
    }

    return extents;
  } catch {
    return new Extents3d();
  }
}

Outputs:

Min: [0.00, 0.00, 0.00]
Max: [2540326.77, 331107.96, 0.00]

Also opening the dwg in AutoCAD vanilla and doing a zoom extents will use this huge/invalid extents. So I think Civil knows that some entities should not be included when computing extents or is it something else?

I would like to be able to compute extents using the second approach (at least a modified working version of it) as it offers more granularity over what entities we want to consider if later on we have some more advanced requirements.

1

There are 1 answers

0
Augusto Goncalves On BEST ANSWER

When iterating the entities to compute the extends, it is OK we do not include the entity AeccDbNetworkPartConnector. You can use the API entity.GetRXClass().Name to get the name AeccDbNetworkPartConnector, which can help filter out these entities.