Delete Block


#1

Hi,

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)
               deleteId.Add(idef.Index);
       
 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?

 Rhino.RhinoApp.WriteLine(Rhino.RhinoDoc.ActiveDoc.InstanceDefinitions.Count.ToString());

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.


(Dale Fugier) #2

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?


#3

I count total number of objects by this:

Rhino.RhinoDoc.ActiveDoc.InstanceDefinitions.Count


#4

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…


#5

More info:


#6

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.


(Dale Fugier) #7

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)
    idef_count++;
}

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.

Thanks,

– Dale


#8

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


(Dale Fugier) #9

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


#10

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


(Nathan 'jesterKing' Letwory) #11

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?