1

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

Gorgious
  • 30,723
  • 2
  • 44
  • 101
JeeperCreeper
  • 388
  • 2
  • 9

1 Answers1

2

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)

BlenderUser123
  • 905
  • 2
  • 9
  • 20
  • 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? – JeeperCreeper Sep 03 '21 at 06:37
  • 2
    for obj in (o for o in bpy.context.scene.objects if o.type == 'LIGHT'): Here are all the possible object types : https://docs.blender.org/api/current/bpy.types.Object.html#bpy.types.Object.type (Make sure you use all caps) – Gorgious Sep 03 '21 at 07:46
  • Sorry for the late reply, thank you for that. – JeeperCreeper Oct 21 '21 at 07:01