IMELCommand Interface


The IMELCommand interface defines methods and properties used to send commands to the Maya® application through its command port. Note that the command port must first be opened within Maya, using the MEL 'commandPort' command.


IMELCommand::Connect Method

Connects to the Maya command port, if not already connected.

Syntax

HRESULT Connect();

Return Value

Returns S_OK if successful or already connected, or an error value otherwise.


IMELCommand::Connected Property

The Connected property specifies whether there currently is a connection established with the Maya command port. This property is read-only.

Syntax

[Visual Basic]
Property Connected As Boolean

[C++]
HRESULT get_Connected(VARIANT_BOOL* pVal);

Parameters

pVal [out] Returns the whether a connection currently exists as a VARIANT_BOOL.


IMELCommand::Disconnect Method

Closes the connection to the Maya command port; does nothing if not connected.

Syntax

HRESULT Disconnect();

Return Value

Returns S_OK.


IMELCommand::Execute Method

Sends a command to the Maya command port. Connects to the command port if not already connected. The result returned by Maya is stored in the Result parameter.

Syntax

HRESULT Execute(BSTR Command);

Parameters

Command [in] Null-terminated string with the command.

Return Value

Returns S_OK if successful, or an error value otherwise.

Remarks

The return value from this method only indicates whether the command was successfully sent to the Maya command port. It does not indicate if the command was successfully executed by Maya.


IMELCommand::PortName Property

The PortName property specifies the name of the Maya command port.

Syntax

[Visual Basic]
Property PortName As String

[C++]
HRESULT get_PortName(BSTR* pVal);
HRESULT put_PortName(BSTR newVal);

Parameters

pVal [out] Returns the PortName property as a reference to a BSTR.
newVal [in] Sets the value of the PortName property to the value of the BSTR.

Remarks

Changing the PortName property while a connection is established will close that connection. The default/initial value of the PortName property is "mayaCommand".


IMELCommand::Result Property

The Result property specifies the result returned by Maya for the most recent invocation of the Execute method. This property is read-only.

Syntax

[Visual Basic]
Property Result As Variant

[C++]
HRESULT get_Result(VARIANT* pVal);

Parameters

pVal [out] Returns the Result property as a reference to a VARIANT.

Remarks

The Result property can be a LONG (VT_I4), DOUBLE (VT_R8), BSTR (VT_BSTR), or an array (VT_ARRAY) of those types.


Examples

Visual Basic

Dim MEL
Set MEL = CreateObject("Maya.CommandEngine.MEL")
MEL.PortName = "myCommandPortName"
On Error Resume Next
MEL.Connect()
If Not MEL.Connected Then
    MsgBox "Error: " & Err.Description
Else
    MEL.Execute("file -f -new")
    MEL.Execute("sphere -radius 3")
    MEL.Execute("render")
    Dim imagePath
    imagePath = MEL.Result
    MsgBox "Image: " & imagePath
    MEL.Disconnect()
End If