Viewpoints may be offered to the user via the context menu of objects in the model. This way you can select one or more objects, and then choose to execute an appropriate viewpoint on this selection. The viewpoint's script is able to retrieve the selected object(s) via the predefined variable selection. To which object(s) the viewpoint should be applicable can be determined by an additional script with the special name contextMenu.
There are two variants of the contextMenu script: one that outputs to "true" and one that outputs to "false". Which one you use depends on your prefererence.
if statement in the script specifies on what elements the viewpoint should be available in the context menu. For example, if you want a viewpoint to be available in the context menu of a view, specify the object "AbstractView". If a viewpoint should only be available on Business actors, specify "BusinessActor" as the object.
header statement in the script defines the viewpoint title that is actually shown to the user in the Execute Viewpoint on Selection window. If no
header statement is present, the name of the viewpoint is displayed.
Below are two examples of a contextMenu script.
Please take note of the following: Currently, presenting a viewpoint in an object's context menu only works when creating a new viewpoint. Including the contextMenu script in existing scripts does not work. A workaround would be recreating the existing viewpoint and saving it including the contextMenu script.
- Open the (newly created and unsaved) viewpoint in the Query tool.
- Right-click the current script tab and select Insert script.
- Right-click the new script tab and select Properties.
- Enter the name contextMenu and click OK. The new tab now has the name contextMenu.
- Paste the contextMenu script on the new script tab.
- In Output type, specify the output of the viewpoint.
- Click Save as, and save the viewpoint in the model.
- Close the Query tool.
Depending on where the viewpoint should be available, right-click it and select Execute Viewpoint. In the window that appears the viewpoint should be available to execute.
The following example defines a table type viewpoint that counts all objects in the selection. The script looks under all objects in selection for child objects and keeps a total per object type. These totals are output at the end.
By adding the contextMenu script "Count object per type" (as shown above), the viewpoint will be available when you select the object and/or one or more layers in it. Right-clicking this selection and then selecting Execute viewpoint should show the viewpoint.
Example of a viewpoint available in the context menu of a layer