How to get entity from block after it was modified inside block AutoCAD C#

Viewed 17

I am working on AutoCAD plugin and at some point I need to get Entity which has been modified inside block. Block contains only one entity. I made event handler for appropriate BlockTableRecord which responces to 'Modified' event. I want to get single entity that has been modified, but all I get through this method, is Entity from model space which is previous version of needed entity. This is how I planned to get my Entity:

public static Entity GetEntityFromBlock(HooverSpace.Map.WorkSpace ws, BlockReference br, ObjectId entId)
        {
            Entity ent = null;

            ObjectId blockId;

            if (ws.acBlkTbl.Has(br.Name))
                blockId = ws.acBlkTbl[br.Name];
            else
                return null;

            Entity searchEnt = (Entity)entId.GetObject(OpenMode.ForRead);

            BlockTableRecord btr = (BlockTableRecord)ws.acTrans.GetObject(blockId, OpenMode.ForRead);

            foreach (ObjectId blkEntId in btr)
            {
                Entity blockEnt = (Entity)ws.acTrans.GetObject(blkEntId, OpenMode.ForWrite);
                if (blockEnt.BlockName == btr.Name && blockEnt.Layer == searchEnt.Layer)
                {
                    ent = blockEnt.Clone() as Entity;
                    break;
                }
                    
            }

            ent.TransformBy(br.BlockTransform);
            return ent;
        }

I am stuck on this issue and would be very glad if someone will help me.

Edit: I resolved this issue by getting BlockTableRecord from br.BlockTableRecord id. Thanks everyone!

0 Answers
Related