-
Notifications
You must be signed in to change notification settings - Fork 36
[request] "Duplicate source" #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Does it duplicates scene item properties such crop and transform info? You might also check OBS Studio repo code This will copy selected source to selected scene if selected scene is not in focus def dup(self):
current_scene = obs.obs_scene_from_source(obs.obs_frontend_get_current_scene())
scene_item = obs.obs_scene_find_source(current_scene, self.source_name)
info = obs.obs_transform_info()
crop = obs.obs_sceneitem_crop()
obs.obs_sceneitem_get_info(scene_item,info)
obs.obs_sceneitem_get_crop(scene_item,crop)
duplicate = obs.obs_sceneitem_get_source(scene_item)
duplicated = obs.obs_source_duplicate(
duplicate, "duplicate" + self.source_name, False
)
scenes = obs.obs_frontend_get_scenes()
for scene in scenes:
name = obs.obs_source_get_name(scene)
if name == self.scene_name:
scene = obs.obs_scene_from_source(scene)
scene_item2 = obs.obs_scene_add(scene, duplicated)
obs.obs_sceneitem_set_info(scene_item2,info)
obs.obs_sceneitem_set_crop(scene_item2,crop)
obs.obs_scene_release(scene)
obs.obs_source_release(duplicated)
obs.source_list_release(scenes)
obs.obs_scene_release(current_scene) full sourceimport obspython as obs
class Example:
source_name = None
scene_name = None
def dup(self):
current_scene = obs.obs_scene_from_source(obs.obs_frontend_get_current_scene())
scene_item = obs.obs_scene_find_source(current_scene, self.source_name)
info = obs.obs_transform_info()
crop = obs.obs_sceneitem_crop()
obs.obs_sceneitem_get_info(scene_item,info)
obs.obs_sceneitem_get_crop(scene_item,crop)
duplicate = obs.obs_sceneitem_get_source(scene_item)
duplicated = obs.obs_source_duplicate(
duplicate, "duplicate" + self.source_name, False
)
scenes = obs.obs_frontend_get_scenes()
for scene in scenes:
name = obs.obs_source_get_name(scene)
if name == self.scene_name:
scene = obs.obs_scene_from_source(scene)
scene_item2 = obs.obs_scene_add(scene, duplicated)
obs.obs_sceneitem_set_info(scene_item2,info)
obs.obs_sceneitem_set_crop(scene_item2,crop)
obs.obs_scene_release(scene)
obs.obs_source_release(duplicated)
obs.source_list_release(scenes)
obs.obs_scene_release(current_scene)
eg = Example() # class created ,obs part starts
def button_pressed(props, prop):
eg.dup()
def script_update(settings):
eg.source_name = obs.obs_data_get_string(settings, "source")
eg.scene_name = obs.obs_data_get_string(settings, "scene")
def script_properties(): # ui
props = obs.obs_properties_create()
p = obs.obs_properties_add_list(
props,
"source",
"Text Source",
obs.OBS_COMBO_TYPE_EDITABLE,
obs.OBS_COMBO_FORMAT_STRING,
)
sources = obs.obs_enum_sources()
if sources is not None:
for source in sources:
source_id = obs.obs_source_get_unversioned_id(source)
name = obs.obs_source_get_name(source)
obs.obs_property_list_add_string(p, name, name)
obs.source_list_release(sources)
_p = obs.obs_properties_add_list(
props,
"scene",
"Scene",
obs.OBS_COMBO_TYPE_EDITABLE,
obs.OBS_COMBO_FORMAT_STRING,
)
scenes = obs.obs_frontend_get_scenes()
for scene in scenes:
name = obs.obs_source_get_name(scene)
obs.obs_property_list_add_string(_p, name, name)
obs.source_list_release(scenes)
obs.obs_properties_add_button(props, "button", "Duplicate", button_pressed)
return props |
Thank you very much! I use to duplicate items from/to scenes that are/aren't in focus. Why did you bold "if selected scene is not in focus"? What happens if I duplicate to current scene? Also, I make references much more than a duplicates. Sorry... my mistake in terminology. I thought that it was:
And it was:
How to make a reference? |
One more thing! By mistake, I use the (full) script and clicked twice in duplicate. When I enter in the scene where the duplicated sources would be... OBS crashed. Next time I run OBS, scene dissapears. I think this is because of the source name: code creates two different sources with the same name. It is not permitted, is it? If you will add this code to Wiki, maybe it would have to check if sources with same name are there. Or to create a random name as "image_duplicate_8239". |
I've used source from current scene which was not present in selected scene to "Duplicate source". If there is no source with name from script properties UI present in
In OBS Studio code linked above it's done doing this: obs_source_t *source = obs_get_source_by_name(name); You might try using |
Added this to examples |
I'm transporting my code that used obs-websockets-py to an OBS script. Now, every request that I did with websockets, I have to do it with Python. This cheatsheet is very usefull for me! Now, I have to transport this simple code:
ws.call(requests.DuplicateSceneItem(item, fromScene=fromScene, toScene=toScene))
But I think it is not that simple to do it as script. Can you give me a hand? Also, it would be great if there was both options: "Reference" and "Duplicate" 😁.
The text was updated successfully, but these errors were encountered: