I got it to work by iterating through the blocks inserted into model space. For our use, I don't need anything from paper space. Each block in model space is checked for a nested block with the "END-NODE" name, if it has the "END-NODE" nested block, the position of the "END-NODE" is checked to see if it is the same as the end of the polyline. If it matches, the ObjectID of the block is returned.
The code is a little rough right now and needs to be cleaned up, but it works the way I need it to. Some of the code is modified code found elsewhere.
public static ObjectId FindEndNodeParent(string sEndNodeName, Point3d pntEndNodeLocation)
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
using (Transaction trans = doc.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord ms = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace],OpenMode.ForRead);
BlockTableRecordEnumerator it = ms.GetEnumerator();
while (it.MoveNext())
{
Entity ent = (Entity)trans.GetObject(it.Current, OpenMode.ForRead);
if (ent.GetType() == typeof(BlockReference))
{
BlockReference blkRef = (BlockReference)ent;
//MessageBox.Show(blkRef.Name);
if (IsNodeParent(blkRef, sEndNodeName, pntEndNodeLocation) == true)
{
return blkRef.ObjectId;
}
if (blkRef.IsDynamicBlock)
{
// Here you have a DynamicBlock reference.
}
}
}
it.Dispose();
trans.Commit();
}
return ObjectId.Null;
}
private static Boolean IsNodeParent(BlockReference parentBlockRef, string sEndNodeName, Point3d pntEndNodeLocation)
{
var trans = parentBlockRef.Database.TransactionManager.TopTransaction;
var btr = (BlockTableRecord)trans.GetObject(parentBlockRef.BlockTableRecord, OpenMode.ForRead);
foreach (ObjectId id in btr)
{
if (id.ObjectClass.Name == "AcDbBlockReference")
{
var nestedBlockRef = (BlockReference)trans.GetObject(id, OpenMode.ForRead);
if (nestedBlockRef.Name == sEndNodeName & nestedBlockRef.Position == pntEndNodeLocation)
{
return true;
}
else
{
return false;
}
}
}
return false;
}