The primary differences between the Maya .NET API and the Maya C++ API are:
Properties instead of getters and setters – Many of the getter and setter functions in the C++ API have been mapped to C# properties. For instance, the methods isInstanceable
and setInstanceable
of the class MFnDagNode
are now exposed as a C# property called isInstanceable
(with get and set accessors).
Getter functions are functions that return a value, have no arguments, and that have no observable effect on the state of the application. Getter function names start with the prefix get, is, has, or can; or are qualified as a “const” function in the C++ header files. Setter functions are void functions that have a single argument, start with the prefix set, and that have the same root name as a getter function. Getter functions with a corresponding setter function (same root name) are mapped to read-write properties; otherwise, they are mapped to read-only properties. Properties have the same name as the getter function but with the prefix removed.
In certain cases, the names of the properties had to be changed because the new property name conflicted with an existing method name. The word Property
was added to the new property name. For example, index()
became indexProperty
.
For more information regarding C# properties, see MSDN at http://msdn.microsoft.com/en-us/default.aspx and C# properties.
Events instead of function pointers – The C# event pattern replaces the message registration mechanism of the MMessage
derived classes (for example, MSceneMessage
, MNodeMessage
, and so forth). Therefore, you can register or unregister your callbacks by simply adding or removing them to/from the corresponding event handler of the MMessage
derived class.
For instance, do MDagMessage.ParentAddedEvent += callback
instead of MDagMessage::addParentAddedCallback(callback)
.
For the MSceneMessage
class, each message identified by a value of the enum Message
now has an independent event handler; therefore, the enum is no longer meaningful. For instance, do MSceneMessage.SceneUpdate += callback
instead of MSceneMessage::addCallback( MSceneMessage::kSceneUpdate, callback )
.
For callbacks related to an instance of an object (MDagPath
, MPlug
, and so forth), the event handler can be found directly in the class of that object. For instance, do obj.NodeAddedToModel += callback
(with obj
of type MObject
) instead of MModelMessage::addNodeAddedToModelCallback(obj, callback)
.
To avoid memory leaks, you must deregister your callbacks (by removing them from the corresponding event handler) when the callbacks are no longer needed. A new mechanism has been added to automatically deregister the callbacks when the plug-in is unloaded from Maya.
To see how events are used, refer to the pluginCallbacks
example in the devkit\dotnet\examples
folder of your Developer Kit installation. For more information on C# events see C# events in MSDN.
Exceptions instead of MStatus failure codes – In case of failure or exceptional cases, a plug-in should raise an exception instead of returning an MStatus
. With this pattern adopted, most functions of the SDK return void
instead of MStatus
, which does not exist in the C# SDK. The only exceptions to this rule are those methods that must return information to Maya that did so via MStatus
in C++. For more information, see Removal of MStatus return codes from .NET API.
Usage of IEnumerableIEnumerable<T>
, which facilitates the usage of LINQ. For more information on IEnumerable
, see Using IEnumerable and LINQ with the Maya .NET API and IEnumerable Interface in MSDN.
Support for .NET collections – Specialized collection classes in the Maya API (such as MPointArray
, MIntArray
, and so forth) support the C# interfaces IEnumerable
and IList
. In addition, they have constructors that accept a C# array and a method that returns a C# array. For more information on C# arrays, see Arrays in MSDN.
MDockStation
, you can also embed any HWND in Maya (not only WPF's, but for example, a WF window). For more information on WPF controls, see Introduction to WPF in MSDN.