ScriptVisualizationObject

class ScriptVisualizationObject.VisualElementType(value)

Bases: Enum

This enumeration represents the possible element types that can be created.

Example python code:

newElem = elementList.add_element(VisualElementType.Frame)
Version added:

4.7.0.0

Rectangle = 0

A rectangle element

RoundedRectangle = 1

A rounded rectangle element

Ellipse = 2

An ellipse element

Polygon = 3

A polygon element

Polyline = 4

A polyline element

BezierCurve = 5

A bezier curve element

Line = 6

A line element

Button = 7

A button element

Image = 8

An image element

Pie = 9

A pie element

Frame = 10

A frame element

Lamp = 11

A lamp element

RotarySwitch = 12

A rotary switch element

ImageSwitcher = 13

An image switcher element

DipSwitch = 14

A dip switch element

PushSwitch = 15

A push switch element

PushSwitchLed = 16

A push switch led element

RockerSwitch = 17

A rocker switch element

PowerSwitch = 18

A power switch element

class ScriptVisualizationObject.InputActionEventType(value)

Bases: Enum

This enumeration represents the possible input action event types.

Example python code:

inputActionFactory = visu.input_action_factory
inputAction = inputActionFactory.create_change_shown_visualization(ChangeShownVisualizationType.Assignment, "Vis")
visualElem.add_input_action(inputAction, InputActionEventType.OnMouseDown)
Version added:

4.7.0.0

OnMouseClick = 0

The OnMouseClick event.

OnMouseDown = 1

The OnMouseDown event.

OnMouseUp = 2

The OnMouseUp event.

OnMouseMove = 3

The OnMouseMove event.

OnMouseEnter = 4

The OnMouseEnter event.

OnMouseLeave = 5

The OnMouseLeave event.

OnValueChanged = 6

The OnValueChanged event.

OnDialogClosed = 7

The OnDialogClosed event.

class ScriptVisualizationObject.ChangeShownVisualizationType(value)

Bases: Enum

This enumeration represents the possible change shown visualization types.

Version added:

4.7.0.0

Assignment = 0

Switch to a hard coded visualization.

AssignmentExpression = 1

Switch to a visualization, that is specified by a STRING expression.

PreviousShownVisualization = 2

Switch to the previously shown visualization.

NextShownVisualization = 3

Switch to the next visualization. Only possible, if a previously shown visualization has been shown again.

class ScriptVisualizationObject.SwitchFrameVisualizationGloballyType(value)

Bases: Enum

This enumeration represents the possible globally switch frame visualization types.

Version added:

4.7.0.0

Assignment = 0

A hard coded frame element has to be modified.

AssignmentExpression = 1

A frame element, specified by a STRING expression, has to be modified.

class ScriptVisualizationObject.ScriptVisualObjectMarker

Bases: object

Marker object to check whether a ScriptObject is a visual object.

Version added:

4.7.0.0

property is_visualobject

Gets a value indicating whether this object is a visual object.

Return type:

bool

Returns:

True if it is a visual object; otherwise, False

class ScriptVisualizationObject.ScriptVisualObjectContainer

Bases: object

Application Objects are extended with this interface since CODESYS Visualization V4.7.0.0.

Version added:

V4.7.0.0

create_visualobject(name=None)

Creates a new visual object in the current context.(application and POUs).

Parameters:

name (str) – The name of the new visual object. In case of None, a default name will be generated.

Return type:

ScriptVisualObject

Returns:

The created visual object.

class ScriptVisualizationObject.ScriptVisualObject

Bases: ScriptVisualObjectMarker

ScriptObjects which are a visual object are extended with this interface. This object corresponds to a visualization to which changes are made.

Remark: For performance reasons, the modifications should be enclosed in brackets with begin_modify and end_modify. Example python code:

def findApplication(proj):
    apps = proj.find("Application", True)
    if len(apps) <> 1:
        raise Exception("Unexpected number of apps: " + str(len(apps)))
    return apps[0]

def findVisualization(proj, visuName):
    visus = proj.find(visuName, True)
    if len(visus) <> 1:
        raise Exception("Unexpected number of visus: " + str(len(visus)))
    return visus[0]

proj = projects.primary
app = findApplication(proj)
app.create_visualobject("Visualization")
visu = findVisualization(proj, "Visualization")
visu.begin_modify()
elementList = visu.visual_element_list
newElem = elementList.add_element(VisualElementType.Rectangle)
newElem.set_property("Position.X", 5)
newElem.set_property("Position.Y", 5)
visu.end_modify()
Version added:

4.7.0.0

property visual_element_list

Gets the visual element list of the visual object.

Return type:

ScriptVisualElementList

create_frame_reference(name)

Creates a visual reference item which can be added to a frame element.

Parameters:

name (str) – The name of the visualization to reference.

Return type:

ScriptVisualFrameReference

Returns:

The visual frame reference.

begin_modify()

Starts modifying this visualization object.

end_modify()

Ends modifying this visualization object.

class ScriptVisualizationObject.ScriptVisualFrameReference

Bases: ScriptVisualObjectMarker

ScriptObjects which are a visual frame reference are extended with this interface.

Example python code:

visu.begin_modify()
elementList = visu.visual_element_list
visuRef1 = visu.create_frame_reference("Vis1")
visuRef2 = visu.create_frame_reference("Vis2")
visuRef3 = visu.create_frame_reference("Vis3")
visuRef3.set_parameter("pou", "PLC_PRG.inst1")
visualElemFrame = elementList[0]
visualElemFrame.set_frame_references([visuRef1, visuRef2, visuRef3])
visu.end_modify()
Version added:

4.7.0.0

property name

Gets the name of the visualization of the visual reference.

Return type:

str

set_parameter(parameter, value)

Sets a parameter at a visualization reference.

Parameters:
  • parameter (str) – The frame reference parameter.

  • value (str) – The value to set at the frame reference parameter.

class ScriptVisualizationObject.ScriptVisualElementList

Bases: ScriptVisualObject

ScriptObjects which are a visual element list are extended with this interface.

Version added:

4.7.0.0

add_element(elementType)

Adds a new element to the element list.

Parameters:

name – The element type to create.

Return type:

ScriptVisualElement

Returns:

The new created and added element.

add_element_copy(element)

Adds a copy of the given element to the element list.

Parameters:

element (ScriptVisualElement) – The element from which a copy is created and added.

Return type:

ScriptVisualElement

Returns:

The new copied and added element.

remove_at(index)

Removes the element at index from the element list.

Parameters:

index (int) – The index of the element that is removed.

remove_id(id)

Removes the element with the id from the element list.

Parameters:

id (int) – The id of the element that is removed.

remove(element)

Removes the element from the element list.

Parameters:

element (ScriptVisualElement) – The element that is removed.

class ScriptVisualizationObject.ScriptVisualElement

Bases: ScriptVisualObject

ScriptObjects which are a visual element are extended with this interface.

Version added:

4.7.0.0

property id

Gets the id of the visual element.

Return type:

int

set_property(property, value)

Sets a property value on the visual element.

Parameters:
  • property (str) – The path to the property, f. e. ‘Text variables.Text variable’.

  • value (object) – The property value. Currently str and int properties are possible to set.

get_property(property)

Gets a property value from the visual element.

Parameters:

property (str) – The path to the property, f. e. ‘Text variables.Text variable’.

Return type:

object

Returns:

The property value.

set_frame_references(visuList)

Sets the referenced visualizations of a frame element.

Parameters:

visuList (str) – The list of ScriptVisualFrameReference .

class ScriptVisualizationObject.ScriptInputActionFactory

Bases: ScriptVisualObjectMarker

ScriptObjects, which are a factory for visual input actions, are represented with this interface.

Version added:

4.7.0.0

create_change_shown_visualization(type, assignment)

Creates a change shown visualization input action.

Parameters:
  • type (ChangeShownVisualizationType) – The type of the change shown visualization input action.

  • assignment (string) – The value to assign to the change shown visualization input action.

Return type:

ScriptInputAction

Returns:

The created input action.

create_switch_frame_visualization_locally(localFrameElement, selectedIndex)

Creates a switch frame visualization input action.

Parameters:
  • localFrameElement (ScriptVisualElement) – The frame element that must be content in the same visualization.

  • selectedIndex (int) – The index to switch to.

Return type:

ScriptInputAction

Returns:

The created input action.

create_switch_frame_visualization_globally(type, assignment, index)

Creates a switch frame visualization input action.

Parameters:
  • type (SwitchFrameVisualizationGloballyType) – The type of the globally switch frame visualization input action.

  • assignment (str) – The value to assign to the globally switch frame visualization input action.

  • index (str) – The index expression to assign to the globally switch frame visualization input action.

Return type:

ScriptInputAction

Returns:

The created input action.

create_write_variable_default()

Creates a write variable input action where the input type is set to default.

Return type:

ScriptInputAction

Returns:

The created input action.

create_write_variable(variable, inputType, minimumValue, maximumValue, dialogTitle, passwordInput, useTextoutputVariable)

Creates a write variable input action input action with the given parameters.

Parameters:
  • variable (str) – The variable when another variable is used.

  • inputType (str) – The input type.

  • minimumValue (str) – The minimum value.

  • maximumValue (str) – The maximum value.

  • dialogTitle (str) – The dialog title.

  • passwordInput (bool) – If password input is used.

  • useTextoutputVariable (bool) – If the text output variable is used.

Return type:

ScriptInputAction

Returns:

The created input action.

create_execute_st_code(stCode)

Creates an execute st code input action.

Parameters:

stCode (str) – The st code of the execute st code input action.

Return type:

ScriptInputAction

Returns:

The created input action.

create_open_dialog(dialog, parameters, results, openModal, openCentered, positionX, positionY)

Creates a switch frame visualization input action.

Parameters:
  • dialog (str) – The dialog to open.

  • parameters (dict[str, str]) – The parameters to pass to the dialog, f. e. dialogArgs = {‘paramInt’: ‘PLC_PRG.iParam’, ‘paramString’: ‘PLC_PRG.sParam’}

  • results (list[int]) – The result values that are allowed.

  • openModal (bool) – If the dialog is opened modal.

  • openCentered (bool) – If the dialog is opened centered.

  • positionX (str) – The x position at which the dialog is opened.

  • positionY (str) – The y position at which the dialog is opened.

Return type:

ScriptInputAction

Returns:

The created input action.

create_close_dialog(dialog, result)

Creates a close dialog input action.

Parameters:
  • dialog (str) – The dialog to close.

  • result (str) – The dialog result.

Return type:

ScriptInputAction

Returns:

The created input action.