[LispFunction("Blkbox")]
public static ResultBuffer Blkbox(ResultBuffer rb)
{
Document curDoc = Application.DocumentManager.MdiActiveDocument;
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
if (rb == null) return null;
TypedValue[] tvValues = rb.AsArray();
using (Transaction trans = db.TransactionManager.StartTransaction())
{
ResultBuffer result
= new ResultBuffer
(); BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
Entity ent = (Entity)trans.GetObject((ObjectId)tvValues[0].Value, OpenMode.ForRead);
if (ent
!= null && ent
.GetType() == typeof(BlockReference
)) {
BlockReference br = (BlockReference)trans.GetObject((ObjectId)tvValues[0].Value, OpenMode.ForRead);
string blkname = br.Name;
ed.WriteMessage("\nBlock Name: (" + blkname + ").");
ObjectId blockRecordId = bt[blkname];
BlockTableRecord blockRecord = (BlockTableRecord)blockRecordId.GetObject(OpenMode.ForRead);
Extents3d tmpExtents3D
= new Extents3d
(); int num = 0;
foreach (ObjectId entID in blockRecord)
{
Entity entity = (Entity)trans.GetObject(entID, OpenMode.ForRead);
// string str = entity.GetType().Name;
// get "Polyline" or "Line"
if (entity.GetType().Name == "Polyline" || entity.GetType().Name == "Line")
{
Extents3d tmp = entity.GeometricExtents;
tmpExtents3D.AddExtents(tmp);
num = num + 1;
}
}
if (num > 0)
{
Point3d maxpt = tmpExtents3D.MaxPoint;
Point3d minpt = tmpExtents3D.MinPoint;
// Translate the OCS to WCS
Matrix3d mt = br.BlockTransform;
Point3d ptmax = maxpt.TransformBy(mt);
Point3d ptmin = minpt.TransformBy(mt);
result
.Add(new TypedValue
((int)LispDataType
.Point3d, ptmax
)); result
.Add(new TypedValue
((int)LispDataType
.Point3d, ptmin
)); }
else
{
return null;
}
}
trans.Commit();
return result;
}
}