jdubs edited this page Oct 21, 2016 · 1 revision

Table of Contents


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".

Source Code

public static void SelectImage(object ImageElement, object Case, object SourceArray, object ErrorMessage)
		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);

Referenced Methods

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.