Cannot Purge missing ghost Blocks

HI All!

I Have this file we received from a client and I can’t get rid of these blocks:

Is there a safe way to get rid of them via python script without deleting also the Blocks instaces in the scene?

Thanks in advance!

I’m not sure what you mean - can you send the file to, to my attention, with a link back here in your comments?


File sent!
I’ll try to explain further:
In the file you will find only a few block instances.
If you open the block manager you will see that there are several blocks in addition to those present in the scene, and these blocks I can not delete them from the block manager with the classic purge.
I would like to delete all the blocks in the block manager list that are not present in the file.

Hi Andrea - in your file, delete the dwg file in BlockManager first, then the others can be deleted.


Hi Pascal, Good to know.

though, I would like to clean the file from unnecessary blocks via python because I have some errors in a script I am running automatically at startup.

Until now I used the purge command throught rs.command, but in this case it doesn’t work.

Hi Andrea - I guess one way would be to do this in stages in your script - make a pass (however you are doing that in the script0 , if any blocks are removed make another pass, etc. until none are removed… something like that.


Hey @pascal , sorry to go back to this after so long, But I could only get my hands on it now.

What I did in the end is Compare the list of selectable Blocks and the list of Block definition in the file, delete the resulting difference:

It seem to work on the files I tested so far :v:

def Diff(li1, li2):
    li_dif = [i for i in li1 + li2 if i not in li1 or i not in li2]
    return li_dif

if rs.ObjectsByType(4096):
    li1 = rs.ObjectsByType(4096)
    li2 = rs.SelectedObjects()
    li3 = Diff(li1, li2)
    rs.Command("_-Purge _BlockDefinitions=_Yes  _AnnotationStyles=_No  _Groups=_No  _HatchPatterns=_No  _Layers=_No  _Linetypes=_No _Materials=_No  _Enter")