nanoCAD Platform Help

Interaction of the form with the script

The form and the design elements located on it interact with the script using properties and events.

Properties

All form properties start with a prefix "Form."

Control properties (design elements) start with a prefix "Form.$$$", where $$$ — name of the control on the properties panel of the form editor, case-sensitive.

Example:

Form.editbox.Value = "";

When accessing the control value (design element), the ".Value" parameter can be skipped.

Example:

Form.editbox = "";

For controls associated with script variables, the value can be passed through a variable.

Example:

// Bind the variable
Form.editbox.Field = "strType";
//...
OnDialogChanged {
// The next three lines do same.
// If values conflict,
// priority is taken into account.
// Priority decreases from top to bottom:
  Form.editbox.Value = "";
  Form.editbox = "";
  strType = "";
}

While the form is active, you can work with its properties and the properties of its controls as with ordinary variables. In this case, the changes made in the script will be applied to the form after exiting the reactor function.

function OnDialogChanged
{
  if (Mode == 1) {
    Form.groupbox.Visible = FALSE;
    Form.Lable1.Left = 50;
  } else {
    Form.groupbox.Visible = TRUE;
    Form.Lable1.Left = 10;
  }
  Form.editbox.Left = Form.Label1.Left + 40;
  Form.Label1.Right = Form.Label1.Right + 38;
}
Property Access Note
Form.Count read The number of controls on the form.
Form.Width read The width of the form's client area.
Form.Height read The height of the form's client area.
Form.Help full

Link to the reference manual. If the path is relative, it is padded relative to the path to the project's Help folder.

May be:

- the path to the chm-file with or without the chapter (don't specify the protocol).

- link to file

- NormaCS page or document: http://help.spds.ru (Protocol is obligatory).

- help index

Form.$$$ full The value of the control.
Form.$$$.Value full

The value of the control.

Form.$$$.Enabled full Control enabled/disabled.
Form.$$$.Visible full Control visible/invisible.
Form.$$$.Field full The name of the script variable associated with the control.
Form.$$$.Tooltip full Hint text.
Form.$$$.Left full

Control size - indent on the left.

If a binding was set in the form editor, after changing the dimensions, the coordinates of all controls will be recalculated taking into account these changes.

Form.$$$.Top full

Control size - indent from above.

Form.$$$.Right

full

Control size - indent on the right.
Form.$$$.Bottom full

Control size - indent from below.

Form.$$$.Count full The number of items in the list or dropdown list.
Form.$$$.Items[#] full The #-th element of the list or dropdown list.

Eventы

An event handler in this context is a script function that is called in response to an event on the form. Events will be called form properties that store the names of event handlers. There are events of the form itself and events of its controls. You can work with them as with normal form properties.

Example:

//Assign the OnChange event to the OnEditChange function
Form.editbox.OnChange = "OnEditChange";
Event When called
Form.OnShow Before showing the form. All form properties are already defined.
Form.OnClose Before closing the form.
Form.$$$.OnChange After changing the value of the control by the user. Changing a control from a script does not generate this event.
Form.$$$.OnEnter When the control receives input focus.
Form.$$$.OnLeave When the control loses input focus.

Switches

The logic of the switches is somewhat different from other design elements. Multiple radio buttons are bound to the same script variable. Each of them is set to some value. The variable is set to the value of the enabled switch. The value is of type string. If "-1" is set, the value is assigned automatically, starting from 1, in TAB order. In this case, the value type will be numeric.

Radio buttons associated with a single variable are considered a group. Only one radio button can be enabled in a group. If the variable is not assigned, radio buttons located inside the same control are grouped. This is usually a Group or Panel.

Examples

Event handling. In the script code, bind the Edit control to the script variable d. When the Edit value changes, update the text in the Static label.

  • Solution 1. When the EditBox value changes from the form, the OnDialogChanged function will be called. Assign EditBox control Field name = d. The EditBox control will automatically synchronize its value with the d variable.

    function OnDialogChanged
    {
      Form1.editbox1.Field = "d";
      Form1.static1 = "Hole diameter: " + d + "mm";
    }
  • Solution 2. Assign an OnChange event handler to the EditBox control.

    function OnDialogChanged
    {
      Form1.editbox1.OnChange = "OnEditChanged";
      Form1.editbox1 = d;
    }
    function OnEditChanged
    {
      d = Form1.editbox1;
      Form1.static1 = "Hole diameter: " + d + "mm";
    }
  • Solution 3. Let's combine both previous solutions. The d variable will be synchronized with the EditBox control automatically, and the text of the Static label will be updated from the OnChange event handler.

    function OnDialogChanged
    {
    Form1.editbox1.OnChange = "OnEditChanged";
    Form1.editbox1.Field = "d";
    }
    function OnEditChanged
    {
    Form.Label = "Hole diameter:" + d + "mm";
    }

List management. Build a list of values in a combo dropdown list.

function OnDialogChanged
{
// You can set the number after the values, but before the values - somehow clearer.
Form.Combo.Count = 5;
// Elements are numbered from 1.
Form.Combo.Items[1] = “(нет)”;
Form.Combo.Items[2] = “Item1”;
Form.Combo.Items[3] = “Item2”;
Form.Combo.Items[4] = “Item3”;
Form.Combo.Items[5] = “Item4”;
// This command will fail because there are only 5 items in the list.
Form.Combo.Items[6] = “Item5”;
}