0
$\begingroup$

I wrote a small script that should:

  1. unhide
  2. enable in viewport
  3. enable in render
  4. enable selectable

for ALL objects in the scene

import bpy
from bpy import context
from bpy import data

# all objects
all_objects = data.objects

for ob in data.objects:
    ob.select_set(True)
    ob.hide_set(False)
    ob.hide_render = False
    ob.hide_select = False

However it wont toggle everything on, there are still objects or collections turned off.

Before:

enter image description here

After:

enter image description here

Is it perhaps not selecting everything with data.objects? Maybe i'm misunderstanding it.

Update:

I updated my script to include collections but it gives me an error

import bpy
from bpy import context
from bpy import data

for collection in bpy.data.collections:
    collections.hide_viewport = False
   
    for obj in collection.all_objects:
       obj.select_set(True)
       obj.hide_set(False)
       obj.hide_render = False
       obj.hide_select = False

Error: AttributeError: 'list' object has no attribute 'hide_viewport'

$\endgroup$
2
  • 1
    $\begingroup$ It is not selecting the nested collections. You need to iterate over scene collections as well. $\endgroup$ Commented May 26, 2022 at 23:34
  • $\begingroup$ @MartyFouts thanks, ive updated my initial message with an updated script but its giving me an error. $\endgroup$ Commented May 27, 2022 at 0:33

1 Answer 1

0
$\begingroup$

Not all collection properties are in collection itself. hide_viewport for example depends on view layer, so it located in the view layer. You can find it like this (for the first collection):

 bpy.context.view_layer.layer_collection.children[0].hide_viewport
 bpy.context.view_layer.layer_collection.children[0].exclude

For nested list like this, you have to write recursion, there is no complite list of it

$\endgroup$
1
  • $\begingroup$ Sorry, this goes way above my head. I think I understand it partially because there is the [scenes] and the [view layer] so i would have to iterate over both layers? Could I perhaps get an ELI5? $\endgroup$ Commented May 30, 2022 at 5:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .