Options and Action Settings

Functional Actions

Progress Steps

Undo and Redo

Secondary Actions

Visibility

Hotkeys

optionsForm.Options gives access to how we can get data from inputs in the actions form. optionsForm.Options.AddX where X is the type of data will allow you to access the different forms.

customDesignAction.Options = () =>  	
{ 
  //create the options form
  var optionForm = OptionsForm.Create("My Custom Design Action");
  
  //example check box
  var useToleranceCheckEdit = optionsForm.Options.AddCheckBox("Use Tolerance");
  //example layer selection where true/false represent if the user can select multiple layers
  var exampleLayer = optionsForm.Options.AddLayerSelect("Output Layer", false);
  //example file read
  var exampleFile = optionsForm.Options.AddOpenFile("Data File")
 
  //return the options form
  return optionsForm;
}

All .AddX commands can be followed with a .RestoreValue command to remember the setting the last time it was run.

 var useToleranceCheckEdit = optionsForm.Options.AddCheckBox("Use Tolerance").RestoreValue("IntersectPolygonsDesignActionUseTolerance", true, true);
 //note this is slightly different for layers
 var outputLayerSelect = optionsForm.Options.AddLayerSelect("Output Layer", false).RestoreValue<string>("IntersectPolygonsDesignActionOutputLayerSelect", (l) => l.FullName, (s) => Project.ActiveProject.Design.LayerData.GetLayer(s), true, true);

Validators can be used in some cases to display a warning or not let the user continue unless a requirement has been met, i.e. setting a layer as the output layer.

outputLayerSelect.Validators.Add(x => x == null? "Please select a layer." : null);

Action Settings

Functional Actions

The ApplyAction is what will happen when the Apply button is pressed. Due to the nature of having undo/redo functionality in the design space this will mostly be calculations/saving settings and won’t create/move points etc. If the action is meant to exit the CDA then it will return True, if the code is meant to be repeatable (you can hit Apply multiple times) return False.

customDesignAction.ApplyAction = () => 
{
	var inputShapes = customDesignAction.ActionInputs.Shapes;
	var settings = customDesignAction.ActionSettings;	
	return true;		
}

The CancelAction is what will happen if the script is action is cancelled while it is still running by pressing the Cancel button:

customDesignAction.CancelAction = () => 
{
		//any actions that might need to be undone on hitting cancel
}

The SetupAction can be used to set the initial selection method:

customDesignAction.SetupAction = () => customDesignAction.Selection.SelectionMode = SelectMode.SelectElements;

Progress Steps

Progress steps are the steps the user can follow to complete the action once it is selected. Below is an example of what appears when creating a shape:

The SelectAction can be used to define what happens when something is selected that matches the current SelectMode and will move to the next progress step:

customDesignAction.SelectAction = () =>
{
	var shape = customDesignAction.Selection.SelectedDesignElement as Shape;
}

The BackAction is what will happen if the user goes backwards in the progress steps, i.e. right-clicking:

customDesignAction.BackAction = () => 
{
    customDesignAction.Selection.SelectionMode = SelectMode.SelectPoint;
}

ProgressSteps are the text steps that will be displayed once the button is clicked:

customDesignAction.ProgressSteps = () => new List<string>() { "Select first point.", "Continue adding points, Right click when finished." };

ProgressStep can be used to determine which step the user is in. This can be helpful to activate different select methods within the SelectAction, i.e. Select a string → Select a point on the string:

customDesignAction.SelectAction = () =>
{
    if (customDesignAction.ProgressStep == 0)
    {
		customDesignAction.Selection.SelectionMode =  SelectMode.SelectShape;
		customDesignAction.ProgressStep = 1;
    }
    else if (customDesignAction.ProgressStep == 1)
    {
		customDesignAction.Selection.SelectionMode =  SelectMode.SelectPoint;
		customDesignAction.ProgressStep = 2;
    }
}

Undo and Redo

The RedoAction is where most of the results are written. If the custom design action is writing shapes to a layer, they will be written here. This action is called if the user presses CTRL + Y after undoing it with CTRL + Z. Most Undo and Redo actions should be contained within the ApplyAction so that any static variables can be stored correctly for undo actions if the action is called more than once.

customDesignAction.RedoAction = () => 
{
	var layer = (Layer) customDesignAction.ActionSettings[0].Value;
	var output =  customDesignAction.ActionOutputs.Shapes;
			
	foreach (var shape in output)
		layer.Shapes.Add(shape);
};

The UndoAction is where anything that is done in the RedoAction is undone. This action is called if the user presses CTRL + Z.

customDesignAction.UndoAction = () => 
{
	var layer = (Layer) customDesignAction.ActionSettings[0].Value;
	var output =  customDesignAction.ActionOutputs.Shapes;

	foreach (var shape in output)
		layer.Shapes.Remove((Shape) shape);
};

Secondary Actions

Assign to Option Button

The GetVectorAction secondary action can be used to save the bearing/grade of a vector. This has similar functionality to the 3 dots visible in other places in the application.

var directionSelect = optionsForm.Options.AddVector3DEdit("Direction");
var buttonGetDirection = optionsForm.Options.AddButtonEdit("Set Direction");
buttonGetDirection.ClickAction = (o) => customDesignAction.SecondaryActions.GetVectorAction((complete, vector) => {
	if (complete)
		directionSelect.Value = vector;
});

GetPointAction

var buttonSelect = optionsForm.Options.AddPoint3DEdit("Point");
var buttonGetDirection = optionsForm.Options.AddButtonEdit("Set Point");
buttonGetDirection.ClickAction = (o) => customDesignAction.SecondaryActions.GetPointAction((complete, point) => {
	if (complete)
		buttonSelect.Value = point;
});

Visibility

Shows whether the action will be visible or not.

customDesignAction.Visible = () => true; //visible
	customDesignAction.Visible = () => false; //invisible
	customDesignAction.Visible = () => customDesignAction.ActiveCase != null; //visible only if there is an active case (ie. in the animation, not in design)

Hotkeys

The hotkeys that can be pressed to launch the design action.

new Keys[] { Keys.Control | Keys.O, Keys.D }

Custom Design Actions