# Cannot Purge missing ghost Blocks

**URL:** <https://discourse.mcneel.com/t/cannot-purge-missing-ghost-blocks/141858>\
**Category:** Rhino for Windows\
**Tags:** windows, purge, blocks\
**Created:** [April 29, 2022, 3:57pm UTC](https://discourse.mcneel.com/t/cannot-purge-missing-ghost-blocks/141858 "2022-04-29T15:57:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pitti](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/pitti/32/658526_2.png) [@Pitti](https://discourse.mcneel.com/u/Pitti)\
**Post date:** [April 29, 2022, 3:57pm UTC](https://discourse.mcneel.com/t/cannot-purge-missing-ghost-blocks/141858/1 "2022-04-29T15:57:54Z")

</div>

HI All!

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

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/0/3/f/03fb9cded39ed9587776464b3210f9f7c8203e90.jpeg)

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!

---

<div class="post-metadata">

**Author:** ![pascal](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/pascal/32/479395_2.png) [@pascal](https://discourse.mcneel.com/u/pascal)\
**Post date:** [April 29, 2022, 4:00pm UTC](https://discourse.mcneel.com/t/cannot-purge-missing-ghost-blocks/141858/2 "2022-04-29T16:00:25Z")

</div>

> [@Pitti](#):
>
> Is there a safe way to get rid of them via python script without deleting also the Blocks instaces in the scene?

I’m not sure what you mean - can you send the file to [tech@mcneel.com](mailto:tech@mcneel.com), to my attention, with a link back here in your comments?

-Pascal

---

<div class="post-metadata">

**Author:** ![Pitti](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/pitti/32/658526_2.png) [@Pitti](https://discourse.mcneel.com/u/Pitti)\
**Post date:** [May 2, 2022, 9:12am UTC](https://discourse.mcneel.com/t/cannot-purge-missing-ghost-blocks/141858/3 "2022-05-02T09:12:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pascal](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/pascal/32/479395_2.png) [@pascal](https://discourse.mcneel.com/u/pascal)\
**Post date:** [May 2, 2022, 3:14pm UTC](https://discourse.mcneel.com/t/cannot-purge-missing-ghost-blocks/141858/4 "2022-05-02T15:14:07Z")

</div>

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

-Pascal

---

<div class="post-metadata">

**Author:** ![Pitti](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/pitti/32/658526_2.png) [@Pitti](https://discourse.mcneel.com/u/Pitti)\
**Post date:** [May 3, 2022, 8:50am UTC](https://discourse.mcneel.com/t/cannot-purge-missing-ghost-blocks/141858/5 "2022-05-03T08:50:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pascal](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/pascal/32/479395_2.png) [@pascal](https://discourse.mcneel.com/u/pascal)\
**Post date:** [May 3, 2022, 2:34pm UTC](https://discourse.mcneel.com/t/cannot-purge-missing-ghost-blocks/141858/6 "2022-05-03T14:34:28Z")

</div>

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.

-Pascal

---

<div class="post-metadata">

**Author:** ![Pitti](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/pitti/32/658526_2.png) [@Pitti](https://discourse.mcneel.com/u/Pitti)\
**Post date:** [May 26, 2022, 9:03am UTC](https://discourse.mcneel.com/t/cannot-purge-missing-ghost-blocks/141858/7 "2022-05-26T09:03:04Z")

</div>

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 ✌

```auto
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):
    rs.Command("_SelBlockInstance")
    li1 = rs.ObjectsByType(4096)
    li2 = rs.SelectedObjects()
    li3 = Diff(li1, li2)
    rs.DeleteObjects(li3)
    rs.Command("_-Purge _BlockDefinitions=_Yes _AnnotationStyles=_No _Groups=_No _HatchPatterns=_No _Layers=_No _Linetypes=_No _Materials=_No _Enter") 

```
