@ActivistInvestor
So far this is what I have. When a drawing is loading I initialize this class, which finds all the existing blocks and adds the event handler. It also adds the event handler to the Database.ObjectAppended event. Then when I copy the block that is already in model space, and paste it, the event triggers.
When the ObjectAppended event triggers, I check if the item is a block, and if that block is an instance of the one I care about. If it is then I attached the event watcher.
Weird thing is, the appended triggers two times. I remove the event watcher before adding, which I would think makes sure there is only ever one copy.
The weird thing is that the new block seems to only have one instance of the event watcher attached. But the original one in the drawing that I copied from, after pasting seems to have two?
Is it something to do with it being a dynamic block? It only has a visibility with two states and one attribute. I'm at a loss.
public FloorInfoEvent()
{
var allBlock = Active.Editor.SelectAllBlock("FloorInfo");
if (allBlock.Status != PromptStatus.OK) return;
ObjectIdCollection ids = new ObjectIdCollection(allBlock.Value.GetObjectIds());
if(ids.Count < 1) return;
ids.TryForEachRead<BlockReference>(block =>
{
block.Modified -= BlockOnModified;
block.Modified += BlockOnModified;
});
Active.Database.ObjectAppended += DatabaseOnObjectAppended;
}
private void DatabaseOnObjectAppended(object sender, ObjectEventArgs e)
{
BlockReference block = e.DBObject as BlockReference;
if (block == null || !block.IsInstanceOf("FloorInfo")) return;
block.Modified -= BlockOnModified;
block.Modified += BlockOnModified;
}