0
$\begingroup$

I have many nested collections with some suffixes as below

[Main Collection 1]

-[Sub Collection 1]

--[Sub Collection 1 ON]

--[Sub Collection 1 OFF]

-[Sub Collection 2]

--[Sub Collection 2 ON]

--[Sub Collection 2 OFF]

I need a script that finds all the collections that are ending with -ON- and turn their render visibility off, and then finds all the collections that are ending with -OFF- and turn their visibility on.

$\endgroup$

1 Answer 1

2
$\begingroup$

You can use the collection's property hide_render to toggle render visibility

enter image description here

import bpy

OFF = False

def contains_word(s, w):
    return (' ' + w + ' ') in (' ' + s + ' ')

for c in bpy.data.collections:
    if contains_word(c.name, "ON"):
        c.hide_render = OFF
    elif contains_word(c.name, "OFF"):
        c.hide_render = not OFF
$\endgroup$
2
  • $\begingroup$ i updated the answer can you check if that works for you? there is also an approach using regular expressions. but this should do for now :) $\endgroup$
    – Harry McKenzie
    Commented Jul 28, 2022 at 2:25
  • 1
    $\begingroup$ or c.name.endswith("ON") $\endgroup$
    – Gorgious
    Commented Jul 28, 2022 at 6:52

You must log in to answer this question.

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