Replacing Car Number with Picture

Posts: 72
Want to replace my car number data with pictures of the number but keep the data there if the picture is not found. Any way to do this?
Posts: 287
If your piture is bigger than your number you can put picture over number and if not picture you see number ... it is easy than do a control of your list of picture
Posts: 785
Probably the easiest way is indeed to have your pictures contain a solid background that will cover over the actual numbers. Although that will only work if your graphic is non-transparent.

The better way that supports any kind of look is probably to use a script that checks if the dynamic image is found, and then hide/show the appropriate label. You can probably do that best as a Converter script for the dynamic image. That way the script should run only when the data for the dynamic image changes, and then it can take appropriate action to hide/show the correct labels.

Not tested, but something close to this may work:

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;

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

// Get the 'default carnumber' label to show instead
var index = 3; // The index (0-based) of your label in the template subwidget's list of labels
var subwidget = label.Parent;
var defaultLabel = subwidget.Labels[index];

// Check if the dynamic image was found
var path = label.DynamicBackground.GetAbsolutePath(item.Theme);
if (System.IO.File.Exists(path))
{
// Show dynamic image label
defaultLabel.IsVisible = false;
label.IsVisible = true;
}
else
{
// Show regular label
defaultLabel.IsVisible = true;
label.IsVisible = false;
}

return null;
}
}
}
Posts: 72
Tested out the script and looks like it's always thinking a dynamic image is there and hiding the label - but it's also not showing the dynamic image either. I tried to take a crack at fixing it but I'm lost passed the if/else statements
Posts: 81
I'm having issues getting this to work as well. Do you attach this as a converter script to the dynamic background like so?

Posts: 287
I use an external path for this, but I don't use any script, if there is no image corresponding to number nothing is showing.

Edited (1 time)
Posts: 38
Nick,

I tried this script and noticed first the return is null which whould explain why the Dynamic Image never shows. You would need to grab the Data Binding and return that for the Dynamic Image to display.

I removed the if and manipulated the IsVisible to true and false I could not get the CARNUM default label to hide.

Thanks,
Harold
Posts: 38
I was able to fix the Dynamic Image file by replacing return null with return value.

However, I cannot hide the CARNUM label.

Posts: 38
I have found a solution of sorts but I am trying to figure a way to grab a cell associated with a DriverID from a .csv file within the script. Has anyone tried that?

Thanks,
Harold
Posts: 785
Harold Darner wrote:
I was able to fix the Dynamic Image file by replacing return null with return value.

However, I cannot hide the CARNUM label.
I think it works when running in ATVO, but not in the editor. For the editor you also need to set "IsVisibleInEditor" separately.

Also, I noticed that the index of the label is not necessary the same as the index in which it's displayed in the list (Z-index). It is probably just the index in whatever order you added the labels to the subwidget, which is difficult to find back. I modified the script to look for the matching Z-index instead. Under Layout category for the label you can see the ZIndex of each label. Make sure to select the Zindex of the label with the normal carnum binding (not the dynamic image binding).

using System;
using ATVO.ThemesSDK;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Scripting.DotNET;
using System.Linq;

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

// Get the 'default carnumber' label to show instead
var index = 0; // The index (0-based) of your label in the template subwidget's list of labels
var subwidget = label.Parent;
var defaultLabel = subwidget.Labels.FirstOrDefault(l => l.ZIndex == index);

// Check if the dynamic image was found
var path = label.DynamicBackground.GetAbsolutePath(item.Theme);
if (System.IO.File.Exists(path))
{
// Show dynamic image label
defaultLabel.IsVisible = false;
defaultLabel.IsVisibleInEditor = false;
}
else
{
// Show regular label
defaultLabel.IsVisible = true;
defaultLabel.IsVisibleInEditor = true;
}

return value;
}
}
}


This seems to work fine for me.
Posts: 785
Harold Darner wrote:
I have found a solution of sorts but I am trying to figure a way to grab a cell associated with a DriverID from a .csv file within the script. Has anyone tried that?
Grabbing data from a spreadsheet is easy, especially if your spreadsheet has a clear unique identifier column and you can grab the data via that identifier. For example if DriverID (customer ID) is your identifier in the first column of the spreadsheet you can simply call "FindRow" on the spreadsheet and get the data in each column in an array:
var id = "123456"; 			// Must be a string
id = entity.Id.ToString(); // Or convert the Id from an IEntity

// Find spreadsheet by name
var s = item.Theme.Spreadsheets.Find("test.csv");

// Get row data
var row = s.FindRow(id);

// 'row' is an array of objects, one per column
var col1 = row[0].ToString();
var col2 = row[1].ToString();
var col3 = row[2].ToString();

// You can also find rows by data in other columns (not the first, identifier column)
var otherId = "Driver name which is in the third column"
var otherRow = s.FindRow(otherId, 2); // Look in the 3rd column (zero-based)
Posts: 38
Nick,

Thanks that script does work however it shows the default CARNUM label for a brief second.

Harold