-
Notifications
You must be signed in to change notification settings - Fork 1
SelectImage
Performs a traditional select or switch statement and returns the image resource from the evaluation.
ElementName (constant) The variable for assignment of the evaluated value. Variable must be an Image type.
Case (multiple) The object of comparison for the CaseArray parameter.
SourceArray (multiple) The key value pairs for comparison. Syntax is: {key=value}
ErrorMessage (multiple | optional) The error message to return when any error occurs.
This method programmatically mimics a select or switch statement. Essentially it replaces a long if statement. The method loops through the SourceArray attempting to find the matching key, and when found assigns the resource image to the SpecName variable. For example a Case of "balloon" and a CaseArray of {balloon=balloons.jpg}{car=car.eps}{ball=balls.pdf} will return "balloons.jpg".
public static void SelectImage(object ImageElement, object Case, object SourceArray, object ErrorMessage)
{
Break();
try
{
string result = (string)ErrorMessage;
foreach (String m in SelectCaseMatches(SourceArray))
{
string[] keypair = m.Split(new string[] { "=" }, StringSplitOptions.None);
if (keypair[0] == (string)Case)
{
result = keypair[1];
}
}
Image img = (Image)Application.CurrentDocument.FindElement((string)ImageElement);
img.Source = result;
if (img.SourceResolved == null)
throw new Exception("Image resource not found.");
}
catch (Exception ex)
{
throw new Four51ActionsException(ex.Message, (string)ErrorMessage);
}
}