Return to the tutorials
Return to the scripting


HDR Shop Scripting - Simple Windows

In order to make more resusable batch processing scripts, you need to get some form of user-input. While there are many for options for this, one convenient way is through HDRShop window functions. In this tutorial we will extend the batch-processing script from the last tutorial to take a user-defined blur width. Here is the full modified batch script:
var dlg = new Dialog("Gaussian Blur", 500, 300);

dlg.AddInt("Blur Width", 4);

// display the dialog and wait for the user to press OK or Cancel
var result = dlg.DoModal();  

if(result == 1)	// if the user pressed OK
{
	var blur = dlg.GetInt(0);

	var img;

	for(i = 0; i < GetImageCount(); i++)
	{
		img = GetImage(i);
		img.GaussianBlur(blur)
	}
}
This should display a window with one integer parameter. Once the user presses OK the script retrieves the blur width, and batch processes all open images.

screenshot of user dialog

This script can be downloaded here: batchblur.js

So how does this work?


Basically HDRShop has a Dialog object that represents a generic dialog box. The constructor takes a name, width and height.
var dlg = new Dialog("Gaussian Blur", 500, 300);
We can then add interface components to the dialog. There are two types of components: Parameters and Behavoirs. Each parameter has one or more corresponding values that the user can set and which you can later retrieve such as a number or string. Each parameter is assigned an identifying index based on the order they are added (the first parameter is zero, the second one, and so on), there are used whenever you want to reference a given parameter. The current available parameter types are static text, check Bow, floating point number, integer, string, choice menu, panoramic format menu, image menu, file menu. To add a parameter to the dialog you use one of the following member functions of Dialog:
void AddStatic(name)
void AddCheck(name, initial_value)
void AddFloat(name, initival_value)
void AddInt(name, initial_value)
void AddString(name, initial_value)
void AddChoice(name, inital value, choices)
void AddFile(name, initial value, openfile,  default extension)
void AddPanoramicFormat(initial_panoramic_index)
void AddImage(name, initial_image_index)

Behavoirs are enforced rules/actions that relate multiple parameters. An example of a behavoir would be to make sure a width and height parameter combine to have the correct aspect ratio. To create a behavoir you need to provide the index of the involved parameters, and the desired behavoir setting. These are set using the following Dialog memeber functions:
void EnsureAspectRatio(index_of_width_parameter, index_of_height_parameter, index_of_checkbox, restore_on_click, rounding_offset)
void EnsurePanoramicAspectRatio(index_of_width_parameter, index_of_height_parameter, index_of_checkbox, round_offset)
Now that we have designed our dialog, we need to display it. There are two different methods. Modal, and Non-Modal. A Modal call will display the dialog and waits for the user to press OK or Cancel. A Non-Modal call will display the dialog, then continue with the script. The corresponding memeber functions are:
int DoModal()
void DoNonModal()
For now we will assume that you display the window using DoModal. If the user selects OK then the DoModal function will return a value of 1.

The final step is to retrieve the parameter values. For this you call a function requesting the desired data type and provide the index of the parameter.
boolean GetCheck(index)
float GetFloat(index)
int GetInt(index)
string GetString(index)
string GetChoice(index)
Return to the scripting
Return to the tutorials