OnCommand

OnCommand is used here as a placeholder for a function that is called when a user clicks a button on the user toolbar or selects the function from a menu.

OnCommand()

Return Value

OnCommand does not return a value.

Comment

Creating a new command

This is an example for creating a new command:

We would like to to add a command that can be used to rename a text object. All objects in UniPlot have names. The command should be inserted into the text object menu that is displayed if the user right clicks a text object.

Here is the function that will be used to rename a text object:

def ObjRenameDlg(handle)
{
    ssName = ObjGetName(handle);

    svRet = DialogBox("Name:  |                           |", ssName, "Rename");
    if (svRet[1] == "DLG_CANCEL") {
        return FALSE;
    }
    return ObjSetName(handle, svRet[1]);
}

The first parameter of ObjRenameDlg is the handle of the object. The function is using the handle to retrieve the object name (ObjGetName). The name is displayed in a dialog box and can be edited (DialogBox). If the user clicks on the OK button the new name is assigned to the text object, using the ObjSetName function.

The next function is the OnCommand function. We choose the name OnRename. The function retrieves the object handle of all selected drawing objects of the active page.

def OnRename()
{
    handle = GetSelectedObjects();
    ObjRenameDlg(handle[1]);
}

The MenuInsertCommands function inserts the new function OnRename into the text object menu.

MenuInsertCommands("OBJ_TB", "OnRename", -1);

The MnSetCommand function specifies the text that will be displayed for the command OnRename.

MnSetCommand(("OnRename", "Rename");
def OnOleRenameUI()
{
    handle = GetSelectedObjects();
    if (len(handle) > 1) {
        return "@g";
    }
    return "";
}

id-1145178