1
$\begingroup$

I'm using blender 2.93 so not sure if that changes anything but i'm trying a simple script as found here

import bpy

for o in ("Cube", "Camera", "Light"):
  obj = bpy.context.scene.objects.get(o)
  #if obj: obj.hide_viewport = False
  if obj: obj.hide_set(False)

I have made a simple scene with cubes, point lights and cameras, some hidden, but if I run the script, nothing happens. It doesn't give any errors either so im not sure what I'm doing wrong. I'm so stupid I guess. Any ideas?

Files here Script file Scene

$\endgroup$

1 Answer 1

2
$\begingroup$

The function bpy.context.scene.objects.get() will get an object matching the name of the parameter passed to it, or return nothing if there isn't an object with that name. The line for o in ("Cube", "Camera", "Light"): iterates over the strings "Cube", "Camera", and "Light", which are the names of the default three objects when a new .blend file is created, so only those objects will get unhidden.

To iterate over all objects, use bpy.context.scene.objects as shown below:

import bpy

for obj in bpy.context.scene.objects:
    obj.hide_set(False)
$\endgroup$
3
  • $\begingroup$ Ohh shoot, I thought the script I used was iterating over classes, not object names. Now I get it. (your script works perfectly). I'm coming from maxscript so its a little confusing, But how if I f.e. want to hide only all lights. How would I go about doing that? $\endgroup$ Sep 3, 2021 at 6:37
  • 2
    $\begingroup$ for obj in (o for o in bpy.context.scene.objects if o.type == 'LIGHT'): Here are all the possible object types : docs.blender.org/api/current/… (Make sure you use all caps) $\endgroup$
    – Gorgious
    Sep 3, 2021 at 7:46
  • $\begingroup$ Sorry for the late reply, thank you for that. $\endgroup$ Oct 21, 2021 at 7:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.