Dialogs definable in Python scripts
In Python scripts, dialogs can be defined and shown by the script.
It is important to note the following:
Make sure that there is an interface where the user can also reply to the dialog. In event scripts, scheduled tasks or via web service, for example, this is not the case. You can check this with the OCL operator .hasGUI in the script:
if vtcapp.evalocl("Session.allInstances->first.hasGUI"): vtcapp.msgbox("Dies ist mein Text")
Dialogues must not be displayed shown within the SystemContext, i.e. with extended user rights. These are system-wide, and as long as such a dialog is not closed, the extended user rights would apply throughout Vertec.
The dialog is called using the feature
vtcapp.showcustomdialog(Dialogdefinition, Initialwerte)
To create the dialog, there is an element called Dialog with the following properties:
| Title | Sets the title of the dialog |
| Width | Specifies the width of the dialog. For example, the dialog in the example below has set Width=”500”. The height of the dialog is determined by the quantity of controls placed on it. |
| InitialFocus | Here you can specify where the focus is when the dialog is opened. The options First, Last and None are available. If nothing is set, First applies. |
| Buttons | Buttons can be placed on the dialog to which dialog commands can be linked. The dialog offers the following commands:
OkCommand and CancelCommand are usually placed in the Dialog.Button. CloseCommand can be used to close the dialog with its own button. The dialog result is 'OK’ and in the Values Dictionary the corresponding button has the value 'True’. |
As in customizing, the required controls are placed on the dialog. Basically, the same controls can be used as in UI Customizing. Each control, for which values are to be set or queried, needs a unique name within the dialog.
For controls that have more than one property, secondary properties are separated by a period, e.g. ListBox.Items, SelectionBox.Items.
The following remarks apply:
The initial values of the feature are passed as arguments and the result values are returned as results. Both the initial values and the return values are passed in each case as a Python dictionary. The keys in the dictionary correspond to the control names, e.g.
initValues = {}
initValues["AuswahlBox.Items"] = ("Option 1", "Option 2", "Option 3")
initValues["Value1"] = "Default 1"
It is also possible to assign a default value (e.g. if the form is not completely filled in and you have to call it again with already entered data), e.g.
initValues["Projekt.SelectedValue"] = Projekt.eval("boldid")SelectedValue is a property of the UI control being used.

This dialog call looks like this in Python:
# Python Script für Custom Dialog
dlgDefinition="""
<Dialog Title="Test Dialog" Width="500">
<TextBlock Text="Bitte geben Sie folgende Werte ein:" Appearance="Info"/>
<Group Label="Auswahl" ShowLabel="True">
<ListBox Name="AuswahlBox" Lines="6"/>
</Group>
<ProjectComboBox Name="Projekt" Label="Projekt"/>
<TextBox Name="Value1" Label="Wert 1"/>
<CheckBox Name="Check1" Label="Option 1"/>
<Group Appearance="NoSpacing" FlexWidth="0" Width="300" HorizontalAlignment="Left">
<Button Name="Option21" FlexWidth="0" Width="100" Text="Option21" Command="{Binding CloseCommand}" />
<Button Name="Option22" FlexWidth="0" Width="100" Text="Option22" Command="{Binding CloseCommand}" />
<Button Name="Option23" FlexWidth="0" Width="100" Text="Option23" Command="{Binding CloseCommand}" />
</Group>
<Dialog.Buttons>
<Button Text="OK" IsAccept="True" Command="{Binding OkCommand}" />
<Button Text="Cancel" IsCancel="True" Command="{Binding CancelCommand}" />
</Dialog.Buttons>
</Dialog>
"""
initValues = {}
initValues["AuswahlBox.Items"] = ("Option 1", "Option 2", "Option 3")
initValues["Value1"] = "Default 1"
ok, values = vtcapp.showcustomdialog(dlgDefinition, initValues)
if ok:
vtcapp.msgbox('Dialog OK, Werte: %s' % values)The showcustomdialog feature returns a tuple of Return-Value and Values-Dictionary. Return-Value is true for OK and false for Cancel. For each control with a name there is an entry (name/value) in the Values-Dictionary. The controls return the following values:
Certain input controls (e.g. ComboBox, ReferenceBox, etc.) do not provide the object, but its internal ID.
Example of a return value from the above example:

The reading of the individual values from the Values Dictionary is done as follows, e.g.:
ProjektID = values["Projekt"]