# Delete hidden object from commandline pythonscript

He guys,

I'm working on a commandline-based puthon-script that imports an IFC-file and cleans it up. So far i can import an IFC-file, do some clean-up and than save the file. The only thing that i cant get my head around is the deleting of hidden objects. These object are hidden in the 3D view and from the rendered view. From within blender you can simply unhide and delete them. Is there a way to delete thes objects from a commandline based python script.

You can use the command line to run blender and pass the below python script to it which will delete all unhidden objects:

import bpy
bpy.ops.object.select_all(action='DESELECT')
for obj in bpy.data.objects:
if obj.hide == True:
obj.hide = False
obj.select = True
bpy.ops.object.delete()

• This brings me closer to the solution, it works from the text editor and not from the commandline script. The only thing is that i dont know the name of the object, so i'll have to make a list of hidden object. Is there a way to do this? Maybe it's an idea to move the objects i want to keep to the next layer and then unhide all object in the first layer?? – Andre Bredeweg Feb 21 '17 at 10:55
• @AndreBredeweg what do you mean by you don't know the name of the object? so imagine you doing it manually which object you are going to delete? there should be a way to identify which object you want to delete. – Tak Feb 21 '17 at 10:59
• Do the objects that are hidden have somekind of attribute that say they are hidden? – Andre Bredeweg Feb 21 '17 at 11:01
• @AndreBredeweg yes, do you want to delete all hidden objects? – Tak Feb 21 '17 at 11:05
• Yes, that's the idea. IFC files tend to have lots of hidden objects (103 in this test-case). These hidden objects show up in Unity3D. – Andre Bredeweg Feb 21 '17 at 11:17