Are you sure you want to report the post shown below? This will send an email to the ATVO administrators.
Please include a short reason for reporting.
Users reporting for no reason may be locked out.
Post
Posted by Nick Thissen
on
It is no longer possible to create C# themes yourself. We can create these custom themes but it is reserved for professional customers. If you are interested to have one made you can contact us by mail.
It sounds like you want to build a dropdown that dynamically loads a list of images from some known location, and allows you to change the displayed image based on what you select in the dropdown.
This can be achieved with a bit of scripting. I should note up front that this will only work while you have an active iRacing connection established, otherwise the data updater will not run and scripts / event triggers will not fire.
First, create the items you need:
A Script 'LoadImages.cs' which will load the images on theme load.
A Script 'ConvertImage.cs' which will take the selected dropdown item and convert it to an image path.
A Dropdown 'Dropdown1' for the list of images. Leave it empty.
A Widget 'Widget1' which will display the image.
Under Background - Dynamic Background, select the ConvertImage.cs as the Converter Script, and select any data binding (it does not matter which one, we just need one otherwise the converter script will not trigger).
An EventTrigger to run the LoadImages script once on theme load. Select ThemeLoaded as the event type, and put a Script - Execute action to execute the LoadImages script.
The scripts are hopefully mostly self-explanatory.
LoadImages will look for all PNG files in a specific folder. For each file, it will add a new item to Dropdown1 and use the filename as the text.
using System; using System.IO; using ATVO.ThemesSDK; using ATVO.ThemeEditor.ThemeModels; using ATVO.ThemeEditor.Scripting.DotNET;
namespace Scripts { public class LoadImages : IScript { public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim) { // Find the dropdown var dropdown = (Dropdown) item.Theme.Dropdowns.Find("Dropdown1");
// Find all png files var path = @"C:\Your\Path\To\Your\Images"; foreach (var file in Directory.GetFiles(path,"*.png")) { Console.WriteLine(file);
// Add a new dropdown item for each file var ddItem = new DropdownItem(dropdown); ddItem.Text = Path.GetFileName(file); dropdown.Items.Add(ddItem); }
return null; } } }
ConvertImage will trigger on each data update. We'll ignore the data binding value but instead get the text of the selected dropdown item, which was the filename of the image you want to show. We add that name to the folder path to create the full filepath, and return that as the path of the Dynamic Image background.
using System; using System.IO; using ATVO.ThemesSDK; using ATVO.ThemeEditor.ThemeModels; using ATVO.ThemeEditor.Scripting.DotNET;
namespace Scripts { public class ConvertImage : IScript { public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim) { var path = @"C:\Your\Path\To\Your\Images";
// Find the dropdown var dropdown = item.Theme.Dropdowns.Find("Dropdown1");
// Find the selected item if (dropdown.SelectedItem != null) { // Return the full path of the selected image var fileName = dropdown.SelectedItem.Text; var filePath = Path.Combine(path, fileName);
Console.WriteLine(filePath);
return filePath; } return null; } } }
This seems to work fine in my quick test. It should be cleaned up a bit, for example the ConvertImage script runs every data update (30 times per second) but should really check if the selected item has actually changed, and not do anything if it hasn't. It's a small optimization but it may add up in large themes.