Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am using the following code to calculate the dimensions of a block definition, but 'bounds' is always null. What could be the issue?
The blockReference object is obtained through Editor.GetSelection()
double width = 0;
double height = 0;
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockReference blockRef = blockReference.ObjectId.GetObject(AcDb.OpenMode.ForRead) as BlockReference;
if (blockRef != null)
{
string blockName = blockRef.Name;
BlockTable blockTable = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
if (blockTable.Has(blockName))
{
ObjectId blockDefId = blockTable[blockName];
BlockTableRecord blockDef = tr.GetObject(blockDefId, OpenMode.ForRead) as BlockTableRecord;
if (blockDef != null)
{
Extents3d? bounds = blockDef.Bounds;
if (bounds != null)
{
width = bounds.Value.MaxPoint.X - bounds.Value.MinPoint.X;
height = bounds.Value.MaxPoint.Y - bounds.Value.MinPoint.Y;
}
else
{
AcAp.ShowAlertDialog("Block Bounds is null.\n");
}
}
}
tr.Commit();
}
}
Solved! Go to Solution.