Python Scripting: Add New Scene to Scene Collection

Mermaldad

New Member
Hello all,

I'm brand new to OBS python scripting, and relatively new to the forum, so apologies if this is misplaced or any other faux pas. I have been using the OBS-Studio-Python-Scripting-Cheatsheet-obspython-Examples-of-API collection on GitHub to learn how to manipulate scenes with the intent of creating a script to populate a scene collection with a series of scenes. I have figured out how to add a variety of sources to an existing scene, but I can't find any reference to how to add a new scene to an existing scene collection. Figuring that the process probably parallels the adding of sources to a scene, I created the following code. However even if this is the right approach, I can't find a call to add the created scene to the scene collection, nor how to release the scene collection when I'm done. Can someone point me in the right direction?

Python:
class Example:
    def create_new_scene(self):
        scene_collection = current_scene = obs.obs_frontend_get_current_scene_collection()
        settings = obs.obs_data_create()

        obs.obs_data_set_bool(
            settings, "custom_size",
            False
        )
        source = obs.obs_source_create_private("scene",
                                               "Scene 3",
                                               settings)

        # obs.obs_scene_add(scene, source) # Need to modify this to add the scene to the current scene collection
        
        # obs.obs_scene_release(scene) # Need to modify this to release the scene collection
        obs.obs_data_release(settings)
        obs.obs_source_release(source)
 
Top