I was able to track this down and fix it. The problem is with the call to ‘doc.InstanceDefinitions.Compact’ which was deleting instance definition geometry but accidentally clearing the definitions’ IsDeleted flag. The BlockManager was reporting exactly what was happening, there was an instance definition in the table with no geometry.
The following code works around the issue.
from scriptcontext import doc
doc.InstanceDefinitions.Delete(0,True,False)
doc.InstanceDefinitions.Compact(True)
doc.InstanceDefinitions.Delete(0,True,False)
doc.Views.Redraw()
This issue was reported as RH-64200 and there is a fix pending for Rhino 7.6.