API Guide > Command plug-ins >

# Returning results to MEL

Commands can also return results to MEL. This is done using the set of overloaded "setResult" and "appendToResult" methods inherited from MPxCommand. For example, if the command needs to return an integer value of 4, it can be done using code that looks like the following:

    int result =4;
    clearResult();
    setResult( result );

You can return arrays by making multiple calls to the appendToResult method. For example, to return three doubles indicating the position of apoint in three-space, you could do something like the following:

    MPoint result (1.0, 2.0, 3.0);
    ...
    clearResult();
    appendToResult( result.x );
    appendToResult( result.y );
    appendToResult( result.z );

Or, this can also be done by returning an array.

    MDoubleArray result;
    MPoint point (1.0, 2.0, 3.0);
    result.append( point.x );
    result.append( point.y );
    result.append( point.z );
    clearResult();
    setResult( result );