Simple scripts

Build 1501 on 14/Nov/2017  This topic last edited on: 25/Aug/2014, at 11:42

A script is considered to be 'simple' if the entire code is enclosed within its body. Otherwise, it belongs to the category of scripts that call other scripts, or even to category of scripts where the main action is executed elsewhere.

1. An example of a simple script

Public Sub EditRedo()

   Page.EditRedo()

End Sub

The EditRedo() script (sub) calls a built-in command Page.EditRedo(), and that's all.

The only reason of existence of such trivial scripts is that you cannot attach built-in commands directly to a menu, keyboard or mouse shortcut, or icon - you have to put them in a 'script' container.

2. Another example of a simple script

Public Sub ObjDuplicateDlg()

   Page.ObjDuplicate(1, 1, 0, 0, 0, 0)

   Page.ObjSelectLast()

End Sub

This is still simple, but not as simple as the first example, as it executes two built-in commands in a sequence.

3. A simple script with a conditional branching

Public Sub AddBoxPageBack()

  If CanModifyLayer() Then

     Page.AddBoxEx(0, 0, Page.GetPageWidth, Page.GetPageHeight, 0)

     Page.ObjToBottom()

  End If

End Sub

This script executes two built-in commands in a sequence, but only if the condition, specified in If CanModifyLayer() Then is satisfied, otherwise it won't do anything.

Now, here the CanModifyLayer() is actually a call to another script, but the main action is however performed in the body of the current script, and not elsewhere.

See also

Scripts with enablers