1818- [ Toggle source visibility] ( #toggle-source-visibility )
1919- [ Set current scene] ( #set-current-scene )
2020- [ Get set order in scene] ( #get-set-order-in-scene )
21+ - [ Add scene with sources to current scene] ( #add-scene-with-sources-to-current-scene )
2122- [ Events] ( #events )
2223- [ Program state] ( #program-state )
2324- [ Timing (sequential primitives) ] ( #timing-sequential-primitives )
2425- [ Hotkeys] ( #hotkeys )
2526- [ Play sound] ( #play-sound )
27+ - [ Read and write private data from scripts or plugins] ( #read-and-write-private-data-from-scripts-or-plugins )
2628- [ Debug] ( #debug )
2729- [ Docs and code examples] ( #docs-and-code-examples )
2830- [ Links] ( #links )
@@ -96,13 +98,16 @@ eg.update_text = partial(eg.update_text,flag_func=flag)
9698## UI
9799| Preview|
98100| --- |
99- | ` obs.obs_properties_add_button(props, "button1", "Refresh1:",callback) ` ![ img] ( src/button.png ) |
100- | ` obs.obs_properties_add_bool(props,"_bool","_bool:") ` ![ img] ( src/bool.png ) |
101- | ` obs.obs_properties_add_int(props,"_int","_int:",1,100,1) ` ![ img] ( src/int.png ) |
102- | ` obs.obs_properties_add_int_slider(props,"_slider","_slider:",1,100,1) ` ![ img] ( src/slider.png ) |
103- | ` obs.obs_properties_add_text(props, "_text", "_text:", obs.OBS_TEXT_DEFAULT) ` ![ img] ( src/text.png ) |
104- | ` obs.obs_properties_add_color(props,"_color","_color:") ` ![ img] ( src/color.png ) |
105- | ` obs.obs_properties_add_font(props,"_font","_font:") ` ![ img] ( src/font.png ) |
101+ | ` obs.obs_properties_add_button(props, "button1", "Refresh1:",callback) ` ![ img] ( src/assets/button.png ) |
102+ | ` obs.obs_properties_add_bool(props,"_bool","_bool:") ` ![ img] ( src/assets/bool.png ) |
103+ | ` obs.obs_properties_add_int(props,"_int","_int:",1,100,1) ` ![ img] ( src/assets/int.png ) |
104+ | ` obs.obs_properties_add_int_slider(props,"_slider","_slider:",1,100,1) ` ![ img] ( src/assets/slider.png ) |
105+ | ` obs.obs_properties_add_text(props, "_text", "_text:", obs.OBS_TEXT_DEFAULT) ` ![ img] ( src/assets/text.png ) |
106+ | ` obs.obs_properties_add_color(props,"_color","_color:") ` ![ img] ( src/assets/color.png ) |
107+ | ` obs.obs_properties_add_font(props,"_font","_font:") ` ![ img] ( src/assets/font.png ) |
108+ | ` obs.obs_properties_add_font(props,"_font","_font:") ` ![ img] ( src/assets/font.png ) |
109+ | ` bool_p = obs.obs_properties_add_bool(props, "_obs_bool", "Yes/No"); obs.obs_property_set_long_description(bool_p, "Check if yes,else uncheck") ` ![ img] ( src/assets/description.gif ) |
110+
106111
107112See also :
108113https://obsproject.com/docs/reference-properties.html#property-object-functions
@@ -325,6 +330,37 @@ def reorder():
325330```
326331[ Full example] ( src/change_order.py )
327332
333+ # Add scene with sources to current scene
334+ ``` python
335+ def add_random_text_source (scene ):
336+ r = " random text # " + str (randint(0 , 10 ))
337+ with data_ar() as settings:
338+ obs.obs_data_set_string(settings, " text" , f " random text value { r} " )
339+ with source_create_ar(" text_ft2_source" , f " random text { r} " , settings) as source:
340+ pos = obs.vec2()
341+ pos.x = randint(0 , 1920 )
342+ pos.y = randint(0 , 1080 )
343+ scene_item = obs.obs_scene_add(scene, source)
344+ obs.obs_sceneitem_set_pos(scene_item, pos)
345+
346+ def add_scene_with_sources ():
347+ current_scene_source = obs.obs_frontend_get_current_scene()
348+ with scene_from_source_ar(current_scene_source) as scene_source:
349+ with scene_create_ar(" _nested_scene" ) as _scene:
350+ py_scene_source = obs.obs_scene_get_source(_scene)
351+
352+ with scene_from_source_ar(py_scene_source) as scene:
353+ add_random_text_source(scene)
354+ add_random_text_source(scene)
355+ add_random_text_source(scene)
356+
357+ # add created scene to current scene ( nested scene)
358+ _scene_source = obs.obs_scene_get_source(scene)
359+ obs.obs_scene_add(scene_source, _scene_source)
360+ ```
361+ Note: sometimes OBS crashes if one of such scenes has been deleted.
362+ - [ Full example] ( src/add_nested.py )
363+
328364# Events
329365``` python
330366def on_event (event ):
@@ -409,12 +445,33 @@ def script_load(settings):
409445 h = obs.obs_hotkey_register_frontend(ID , ID , on_obs_key_1)
410446 obs.obs_hotkey_load(h, a)
411447```
448+ Here is how send hotkey to OBS
449+
450+ ``` python
451+ def send_hotkey (obs_htk_id , key_modifiers = None ):
452+ if key_modifiers:
453+ shift = key_modifiers.get(" shift" )
454+ control = key_modifiers.get(" control" )
455+ alt = key_modifiers.get(" alt" )
456+ command = key_modifiers.get(" command" )
457+ ...
458+ combo = obs.obs_key_combination()
459+ combo.modifiers = modifiers
460+ combo.key = obs.obs_key_from_name(obs_htk_id)
461+ ...
462+ obs.obs_hotkey_inject_event(combo, False )
463+ obs.obs_hotkey_inject_event(combo, True )
464+ obs.obs_hotkey_inject_event(combo, False )
465+ ```
466+
412467- [ Full example] ( src/obs_httkeys.py )
413468- [ Example with global ] ( src/hotkey_exmpl.py )
414469- [ Full example with json] ( src/hotkey_json.py )
470+ - [ Full example with send hotkey] ( src/send_hotkey.py )
415471
416472See also:
417473https://github.com/obsproject/obs-studio/blob/master/libobs/obs-hotkeys.h
474+ https://github.com/Palakis/obs-websocket/pull/595
418475
419476# Play sound
420477``` python
@@ -433,6 +490,48 @@ def play_sound():
433490```
434491- [ Full example] ( src/play_sound_globally.py )
435492
493+ # Read and write private data from scripts or plugins
494+ Write in one script
495+ ``` python
496+ def send_to_private_data (data_type , field , result ):
497+ settings = obs.obs_data_create()
498+ set = getattr (obs, f " obs_data_set_ { data_type} " )
499+ set (settings, field, result)
500+ obs.obs_apply_private_data(settings)
501+ obs.obs_data_release(settings)
502+
503+ def write_private_data ():
504+ result = " private value from " + str (__file__ ) + " " + str (randint(1 , 10 ))
505+ send_to_private_data(" string" , " __private__" , result)
506+ ```
507+ Read from another
508+ ``` python
509+ @contextmanager
510+ def p_data_ar (data_type , field ):
511+ settings = obs.obs_get_private_data()
512+ get = getattr (obs, f " obs_data_get_ { data_type} " )
513+ try :
514+ yield get(settings, field)
515+ finally :
516+ obs.obs_data_release(settings)
517+
518+ def print_private_data ():
519+ with p_data_ar(" string" , " __private__" ) as value:
520+ print (value)
521+ ```
522+ Lua is also supported
523+ ``` lua
524+ local obs = obslua
525+ local settings = obs .obs_data_create ()
526+ obs .obs_data_set_int (settings ," __private__" , 7 )
527+ obs .obs_apply_private_data (settings )
528+ obs .obs_data_release (settings )
529+ ```
530+
531+ - [ Full example read] ( src/read_private_data.py )
532+ - [ Full example write] ( src/write_private_data.py )
533+
534+
436535# Debug
437536There is no stdin therefore you can't use pdb , options are:
438537- using ` print `
@@ -445,7 +544,7 @@ There is no stdin therefore you can't use pdb , options are:
445544 - View select Debug Console (ctrl+shift+y)
446545- [ Example debugpy obs ] ( src/debug_exmpl.py )
447546
448- ![ screenshot] ( src/debug.png )
547+ ![ screenshot] ( src/assets/ debug.png )
449548
450549# Docs and code examples
451550
0 commit comments