1

How can I remove any mesh, texture, material and others from a Blend file? Now I have a single scene with one object that has no material, nothing is hidden, I am not in local mode, I tried every File/Clean Up/... commands, but yet there are a lot of previously used textures, meshes and other stuffs in the Blend file. Is there a way to get rid of them without manually hunting them one by one?

I wonder if Blender has a one click solutin for efficient clean up/purge functionality.

An example file: https://easyupload.io/7f3e2c

Denatural
  • 358
  • 3
  • 11
  • Have you tried to switch to Orphan Data in the Outliner then click on the Purge button? – moonboots Aug 13 '21 at 08:01
  • Yes, but I found only factory brushes there, none of my own orphan data. Hard to believe, that no way to solve such a simple and every day task. For an average programmer this is a 1 hour project. A simple tree traversal. Why Blender developers don't take care for it? – Denatural Aug 13 '21 at 08:35
  • it means that all other datas than brushes are used by at least one object – moonboots Aug 13 '21 at 08:38
  • No. As I wrote, I have one scene, one object in that. Tha object has no material. It is default white. There are no hidden objects in the scene.

    I just read about it, and found this post: https://blenderartists.org/t/how-do-you-actually-purge-unused-data/1280518/8

    – Denatural Aug 13 '21 at 08:42
  • yes that's weird, the other possibility is that you've pressed on the Fake User button for some textures, but could you please share your object (at least a part of it)? https://pasteall.org/blend/ – moonboots Aug 13 '21 at 08:44
  • This is very unusual to the point that I think you may have done something you have thought was normal but is actually quite odd and would (to fresh eyes) obviously cause this. Since this behavior is definitely not supposed to happen if everything else is normal, it is either a bug or the above described. I’m not sure we can help you here, at least without a file. blend-exchange.com if you can share. – TheLabCat Aug 13 '21 at 08:54
  • Please [edit] any extra detail into your question Edit script here https://blender.stackexchange.com/questions/230383/how-to-find-out-what-is-using-an-image-in-a-blend-file/230425#230425 with for example to display users of a texture named "Foo" --> img = bpy.data.textures['Foo'] and run script. If there is 2 users it will not be in orphans. – batFINGER Aug 13 '21 at 10:08
  • I uploaded it for you. Deleted all materials, joined objects into one, no other stuffs in the scene, no fake usered resources, and see, there is a lot of unused things in the file. Old objects, textures, etc... – Denatural Aug 13 '21 at 10:10
  • batFinger: I wrote it to moonboots. Now I linked it in the question too. – Denatural Aug 13 '21 at 10:26
  • None of the remaining objects in your file are orphans. A user can be a relation (parent) a modifier, constraint or driver target (to name but a few) For example bpy.data.objects['tümpanon blokk'] has 16 users. Running a script to clear objects that are not the single scene linked object clears most. – batFINGER Aug 13 '21 at 13:03

2 Answers2

1

I'm pretty sure that you use some specific add-on like kitops, because the objects that you are talking about used somehow. You can see this by number of users, that currently is one:

enter image description here

but should be zero to be removed by Blender's clear purge data command. In this case, I belive the best way to remove it is to open the Outliner in Blender File mode:

enter image description here

Select objects that you want to remove using Shift (objects that are not presented in the scene marked by gray color, so it is easy to select right ones) then press X to remove (or from context menu):

enter image description here

Then you can use File -> Clean Up -> Recursive unused data-blocks for removing all related data like Meshes, materials ant textures.

Crantisz
  • 35,244
  • 2
  • 37
  • 89
1

Not unused, rather not linked to scene.

There are no orphans in the blend file. For example running script here details this object has 16 users, and "who" they are

---------------------------------
bpy.data.objects['tümpanon blokk']
Users: 16
("bpy.data.objects['Ablak4_Ablak4.057']", "bpy.data.objects['Ablak4_Ablak4.058']", "bpy.data.objects['Ablak4_Ablak4.059']", "bpy.data.objects['Ablak4_Ablak4.060']", "bpy.data.objects['Cimer_Circle']", "bpy.data.objects['Cimer_Circle.002']", "bpy.data.objects['Proba_Cube.001']", "bpy.data.objects['Proba_Cube.003']")

and as mentioned by Cranzitz likely these objects are linked together via pointers used by an addon, perhaps these custom properties give a clue...

>>> C.object['
              bc']
              graswald']
              hops']
              kitops']
              lod_original']

To deal with these can remove all objects not linked to the scene. Here is a script to do much the same as select all but one object in outliner data API UI as suggested. In this case select all objects not used by a scene

import bpy

obs = [o for o in bpy.data.objects if not o.users_scene]

bpy.data.batch_remove(obs)

after which any meshes etc left over will be mostly orphaned and can be dealt with accordingly.

enter image description here

Removing kitops.

Further to the reasons this happens, an addon like kitops associates objects via pointers to other objects, effectively upping the user count and leading to

Object referenced by PointerProperty in Python can not be deleted properly

Not deleting objects with users is a safety feature. IMO perhaps the makers of the addons could add an operator to remove those dependencies.

For example this script will remove the custom property added by kitops

import bpy

for o in bpy.data.objects: del(o["kitops"])

leading to a number of objects appearing as orphans.

batFINGER
  • 84,216
  • 10
  • 108
  • 233
  • Wow! Cool!

    Your 3 line script solved the problem! Now the clean up found every unused stuffs, the file size dropped from 11 MB to 3 MB and the inner structure is nice clean, not a huge trash can. I don't understand, why isn't this part of the default clean up function.

    I will create a menu item from this script.

    – Denatural Aug 13 '21 at 15:47
  • THanks. Added an edit to explain somewhat. – batFINGER Aug 13 '21 at 16:26
  • I don't think Blender should rely on third party addon developers. There are a lot of addon with many-many bugs, the most addon developer is not even professional coder, or has not enough knowledge of Blender API. So Blender has to provide a robust framework, and if user want to clean everything that is not effect the actual scene, it shoud delete it mercylessly. Or ask user, what to do if pointers found referenced to unknown sources. – Denatural Aug 13 '21 at 17:00