Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA™ Plant SCADA

Enable and Disable a Command

  • Last UpdatedSep 12, 2025
  • 1 minute read

You can also respond to the UpdateCommand event to control the enable/disable state of the command's toolbar button. The example below disables the button if there are no pens.

[VBA]

Sub CPA_E_UpdateCommand(commandId As String)
Select Case commandId
Case "SelectedPen"
Call OnUpdatedSelectedPen()
End Select
End Sub

Sub OnUpdatedSelectedPen()
Dim pen As Object
Dim command As Object
Dim sName As String

On Error Goto errHandler

Set command = test_CPA.CommandSystem.ItemById("SelectedPen")
Set pen = test_CPA.LastSelectedPen

sName = pen.Name
command.Enabled = True
Exit Sub

errHandler:
command.Enabled = False
End Sub

[Cicode]

FUNCTION CPA_E_UpdateCommand(OBJECT hPA, STRING commandId)
SELECT CASE commandId
CASE "PaneLock"
OnUpdatePaneLock(hPA);
CASE "SelectedPen"
OnUpdateSelectedPen(hPA);
END SELECT
END

FUNCTION OnUpdateSelectedPen(OBJECT hPA)
OBJECT hPen = _ObjectGetProperty(hPA, "LastSelectedPen");
OBJECT hCommandSystem = _ObjectGetProperty(hPA,"CommandSystem");
OBJECT hCommand = _ObjectCallMethod(hCommandSystem,"get_ItemById", "SelectedPen");
INT iError = 0;

ErrSet(1);
_ObjectGetProperty(hPen, "Name");
iError = IsError();

IF (iError <> 0) THEN
_ObjectSetProperty(hCommand, "Enabled", 0);
ELSE
_ObjectSetProperty(hCommand, "Enabled", -1);
END
ErrSet(0);
END

See Also

UpdateCommand [Event]

In This Topic
TitleResults for “How to create a CRG?”Also Available in