You are probably already familiar with sending OBS Raw requests with Streamer.bot's OBS Raw Generator or the Raw subaction that you find under OBS -> Raw. Sending it vía the subaction then populates variables that you can further use in your action. Sending Raw requests in C# however works a little different.
CPH.SendObsRaw() request by hand, we can make use of the Copy CPH function of Streamer.Bot's OBS Raw Generator.
GetInputSettings request to get the text of a Text (GDI+) source called Bitrate Text. Copying the CPH method leaves us with this in our clipboard:CPH.ObsSendRaw("GetInputSettings", "{\"inputName\":\"Bitrate Text\"}", 0);
using System;
public class CPHInline
{
public bool Execute()
{
CPH.ObsSendRaw("GetInputSettings", "{\"inputName\":\"Bitrate Text\"}", 0);
return true;
}
}
using System;
public class CPHInline
{
public bool Execute()
{
string getInputSettingsResponse = CPH.ObsSendRaw("GetInputSettings", "{\"inputName\":\"Bitrate Text\"}", 0);
return true;
}
}
CPH.LogInfo(getInputSettingsResponse); or by using the OBS Raw Generator.{
"inputKind": "text_gdiplus_v3",
"inputSettings": {
"color": 8388437,
"font": {
"face": "Neue Haas Grotesk Text Pro Extr",
"flags": 0,
"size": 144,
"style": "ExtraLight"
},
"text": "Current bitrate: 7500"
}
}
text and fontsize properties from that entire request. To do that, we need to parse the string into a JObject first. So we add the namespace using Newtonsoft.Json.Linq; and use the JObject.Parse() method.using System;
using Newtonsoft.Json.Linq;
public class CPHInline
{
public bool Execute()
{
string getInputSettingsResponse = CPH.ObsSendRaw("GetInputSettings", "{\"inputName\":\"Bitrate Text\"}", 0);
JObject inputSettingsJObject = JObject.Parse(getInputSettingsResponse);
return true;
}
}
inputSettings and the properties text and font -> size.text property, we can just declare a string and parse that property:string gdiText = (string)inputSettingsJObject["inputSettings"]["text"];
size property is a number and also nested within the font property, so we need to adjust that:int fontSize = (int)inputSettingsJObject["inputSettings"]["font"]["size"];
using System;
using Newtonsoft.Json.Linq;
public class CPHInline
{
public bool Execute()
{
string getInputSettingsResponse = CPH.ObsSendRaw("GetInputSettings", "{\"inputName\":\"Bitrate Text\"}", 0);
JObject inputSettingsJObject = JObject.Parse(getInputSettingsResponse);
string gdiText = (string)inputSettingsJObject["inputSettings"]["text"];
int fontSize = (int)inputSettingsJObject["inputSettings"]["font"]["size"];
return true;
}
}
CPH.LogInfo($"GDI Text: {gdiText} // Font Size: {fontSize}");
[2024-08-11 19:13:48.297 INF] GDI Text: Current bitrate: 7500 // Font Size: 144
{
"font": {
"size": 144
},
"text": "7500"
}
CPH.ObsSendRaw("SetInputSettings", "{\"inputName\":\"Other Textsource\",\"inputSettings\":{\"font\":{\"size\":144},\"text\":\"7500\"},\"overlay\":true}", 0);
" + variableName + "using System;
using Newtonsoft.Json.Linq;
public class CPHInline
{
public bool Execute()
{
string getInputSettingsResponse = CPH.ObsSendRaw("GetInputSettings", "{\"inputName\":\"Bitrate Text\"}", 0);
JObject inputSettingsJObject = JObject.Parse(getInputSettingsResponse);
string gdiText = (string)inputSettingsJObject["inputSettings"]["text"];
int fontSize = (int)inputSettingsJObject["inputSettings"]["font"]["size"];
CPH.ObsSendRaw("SetInputSettings", "{\"inputName\":\"Other Textsource\",\"inputSettings\":{\"font\":{\"size\": " + fontSize + "},\"text\":\" " + gdiText + "\"},\"overlay\":true}", 0);
return true;
}
}
