Delete Block


I have issue with blocks.

I delete blocks like this:

//Find block with similar name and delete them all

List<int> deleteId = new List<int>();

 foreach (Rhino.DocObjects.InstanceDefinition idef in Rhino.RhinoDoc.ActiveDoc.InstanceDefinitions)
       if (idef.Name.Length > blockName.Length)
           if (idef.Name.Substring(0, blockName.Length) == blockName)
 foreach (int i in deleteId)
       Rhino.RhinoDoc.ActiveDoc.InstanceDefinitions.Delete(i, true, true);

They do not appear on the screen anymore but when I count total instance of the objects they are somewhere in the document as this number is increasing. I do not see any blocks on block manager, but guids of them appears.

How to delete blocks correctly?


I tried manually purge all objects. But still the number is increasing. Let say I have totally 30 intances in doucument.
First time there are 30 , I delete them nothing on the screen but counter says there is 60 after I place new blocks, then 90 , 120 … to whatever big number.

I don’t understand what this means? How are you determining this? Can you provide a test command that we can run here that repeats what you are seeing?

I count total number of objects by this:


Here I am printing number of instance in command line and it is increasing and increasing each step I delete those block and replace with new ones…

More info:

Physically there are only blocks that I replaced for instance the same 30 I wrote before. But the number of all instances keep accumulating, they are not in block manager, they are not selectable. What this count function represent?

Manually I tried to purge all objects, delete history, but total number of instances is increasing.

Hi Tom,

I am unable to repeat what you are reporting. Keep in mind that Rhino never deletes anything - it simply tags things as deleted. Items tagged as deleted are not saved to the document.

To count the number of active (e.g. not deleted) instance definitions, do something like this:

var idef_count = 0;
foreach (var idef in doc.InstanceDefinitions)
  if (!idef.IsDeleted)

But if you think there is a problem, please provide me a sample command, that I can run here, that repeats what you are seeing.


– Dale

And there is no possibility to delete those marked as delete objects in rhino?

Hi @Tom_Holt,

Like I said, Rhino does not delete anything. Rather, it marks things as deleted.

InstanceDefinitionTable.Count returns the total number of instance definitions, both active and deleted. This is because this is the true number of items in the instance definition table.

If you don’t want the total number of instance definitions, then you will need to implement your own counter, as I have described in my prior sample.

– Dale

And there is no possibility to delete those marked as delete objects in rhino?

That would be a save and reopen… Dale has repeatedly mentioned that deleting data doesn’t actively delete, but only tag that so it doesn’t get saved in the document. Does that help?