Skip to content
AppgineeringAppgineering
Shop
Read-only4 posts · 3,621 views · Started 01 Oct 2021, 00:01

Get Script to Read from Folder in Theme Images

Archived: discussion moved to DiscordDiscord
Josh L.Original poster
#1

So I want a script to read from a CarNum folder in my theme. It's a script to hide the carnum data binding if a dynamic image is found. I cannot for the life of me figure out how to get it to read that the path exists.

Here's the code:

using System;
using ATVO.ThemesSDK;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Scripting.DotNET;
using ATVO.ThemesSDK.Data.Results;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Media;

namespace Scripts
{
    public class CarNumScript : IScript
    {
        public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
        {
            if (value == null)
                return null;
            // Get the label running this converter script
            // This label is showing the dynamic image
            var label = item as Label;
            if (label == null)
                return null;

            string path = @"assets/CarNum" + value + ".png";

            if (System.IO.File.Exists(path))
            {
               // Send transparent as output
                return Colors.Transparent;
            }

            else 
            {
                if (parameter == "font")
                    return Colors.White;
                return Colors.Black;
            }
        }
    }
}

Any help is appreciated!

#2

Bumping this, really important for us to get this working so we can have more freedom when configuring our overlay for new customers.

Nick ThissenAppgineering
#3

You can use the GetAbsolutePath on the DynamicBackground, assuming you configured your label to show the right dynamic image:

var path = label.DynamicBackground.GetAbsolutePath(item.Theme);

This path would resolve to the full path of the file. You can then check if it exists like you are already doing.

This thread is archived.

New replies have moved to Discord.

Continue on Discord