Custom commands are easy to implement and involve
creating a new command, adding it to a toolbar, and responding to
the CommandExecuted
event.
To add a new command and add it to the toolbar as a button:
Once you've done this, you need to write an event
handler for the CommandExecuted
event. This event will be called when the command is executed,
whether by Cicode or by clicking on the respective toolbar button.
The CommandExecuted
event when
triggered has a commandId
parameter
identifying the command executed by the operator.
This example implements a command that displays a message box showing the name of the primary selected pen.
See Also
[VBA]
Sub CPA_E_CommandExecuted(commandId As String)
Select Case commandId
Case "SelectedPen"
Call OnSelectedPen()
End Select
End Sub
Sub OnSelectedPen()
Dim pen As Object
Dim sName As String
Dim sMessage As String
Set pen = test_CPA.LastSelectedPen
If IsNull(pen) = False Then
sName = pen.Name
End If
sMessage = "The name of the selected pen is:" + Chr(13) + sName
MsgBox sMessage, 48, "Citect"
End Sub
[Cicode]
FUNCTION CPA_E_CommandExecuted(OBJECT hPA, STRING commandId)
SELECT CASE commandId
CASE "SelectedPen"
OnSelectedPen(hPA);
END SELECT
END
FUNCTION OnSelectedPen(OBJECT hPA)
OBJECT hPen;
STRING sName;
STRING sMessage;
IF ObjectIsValid(hPA) THEN
hPen = _ObjectGetProperty(hPA, "LastSelectedPen");
IF ObjectIsValid(hPen) THEN
sName = _ObjectGetProperty(hPen, "Name");
END
sMessage = "The name of the selected pen is:^n" + sName;
Message("Citect", sMessage, 48);
END
END