- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Examples

- Class List
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Member Functions

# MPxEditData Class Reference
OpenMaya - API module for common classes | Proxy classes

This reference page is linked to from the following overview topics: Autodesk Maya 2014.

Search for all occurrences

## Detailed Description

Base class used to associate user-defined data with edits.

MPxEditData is a pure virtual base class, used to derive custom data objects which can be associated with individual MEdit objects.

A small set of comparison methods need to be defined to support query operations and use of associative data structures. The base class defines no other data or behavior.

Derived classes are free to add data members and methods as required.

## Use in Python

### Python Accessor Methods _setValue and _getValue

It is expected that classes derived from MPxEditData will define one or more data members to store the object's value and this data will be used by the virtual methods performIsEqual and performIsLessThan for comparison.

In Python, derived class objects passed to the virtual comparison method implementations will only be visible as MPxEditData base class objects, not the actual derived class objects.

For this reason, Python classes derived from MPxEditData have two additional methods, _setValue and _getValue that provide a mechanism for the derived class to access its custom data value using the base class interface.

Since these interfaces are defined directly in Python, the data value can be any valid Python type.

    def _setValue(data):
       # Called by the class to store the data value of the object
       # The data value can be of any valid Python type

    def _getValue():
       # Called by the class to retrieve the data value that was
       # previously set using _setValue

### Ownership of the MPxEditData Object

MPxEditData objects associated with an MEdit must be dynamically allocated. Ownership of the editData will be assumed by Maya and subsequent management of the data object, including its eventual deletion will be handled along with the edit it is associated with. For this reason, an editData object should only be associated with a single edit, the same object should not be shared or associated with other edits. If multiple edits have editData of the same value, each edit must have its own unique copy.

In Python, the OpenMayaMPx asMPxPtr method is used to transfer ownership of a dynamically allocated object to Maya. The Python example below demonstrates how this could be implemented.

### Python Example

    # Example MPxEditData class implemented in Python

    import Maya.OpenMayaMPx as OpenMayaMPx

    class testEditDataType(OpenMayaMPx.MPxEditData):
        """
        Simple tag class that is intended to store a string value
        """
        _tagValue = ''
        def __init__(self, tagValue):
            OpenMayaMPx.MPxEditData.__init__(self)
            # Python derived classes need to use _setValue() here
            # and then _getValue() in performIsEqual/performIsLessThan methods
            # (because python does not have a dynamic_cast like C++ to use
            # on variable 'other' to get access to the derived class data)
            self._tagValue = tagValue
            self._setValue(self._tagValue)

        def performIsEqual(self, other):
            # Note: use of _getValue is not actually necessary for accessing
            # data members of 'self'. It is however necessary for 'other'
            # since 'other' is only available here as a base class MPxEditData object.
            thisValue = self._getValue()
            otherValue = other._getValue()
            return bool(thisValue == otherValue)

        def performIsLessThan(self, other):
            thisValue = self._getValue()
            otherValue = other._getValue()
            return bool(thisValue < otherValue)

        @staticmethod
        def creator(tagValue):
            """
            Create a tag with the given value.
            This creator method correctly returns pointer whose ownership
            has been transferred to maya.
            """
            return OpenMayaMPx.asMPxPtr(testEditDataType(tagValue))

`#include <MPxEditData.h>`

List of all members.

## Public Member Functions
| MPxEditData ()
| Class constructor.
virtual | ~MPxEditData ()
| Class destructor.
bool | isEqual (const MPxEditData *other) const
| Compares two MPxEditData objects for equality.
bool | isLessThan (const MPxEditData *other) const
| Compares two MPxEditData objects to determine their relative order for sorting purposes.
## Static Public Member Functions
static const char * | className ()
| Returns the name of this class.

## Member Function Documentation

bool isEqual | ( | const MPxEditData * | other | ) | const

Search for all occurrences

Compares two MPxEditData objects for equality.

The base class method makes use of the derived class performIsEqual to determine the equality of two objects. Note that the base method will simply return false if the two MPxEditData objects are of different types.

Parameters:

  [in] | other | An editData object to compare with this object

Returns:
  True if both MPxEditData objects refer to the same value, false otherwise.

bool isLessThan | ( | const MPxEditData * | other | ) | const

Search for all occurrences

Compares two MPxEditData objects to determine their relative order for sorting purposes.

The base class method makes use of the derived class implementation of performIsLessThan to determine the ordering of two MPxEditData objects. Note that the base method will simply order the values by typeid if the two objects are not of the same type.

Parameters:

  [in] | other | An editData object to compare with this object

Returns:
  True if this object value is less than the specified MPxEditData object value, false otherwise.

const char * className | ( |  | ) | `[static]`

Search for all occurrences

Returns the name of this class.

Returns:
  The name of this class.

MPxEditData MPxEditData MPxEditData MPxEditData MPxEditData MPxEditData MPxEditData MPxEditData MPxEditData MPxEditData
MPxEditData MPxEditData MPxEditData MPxEditData MPxEditData MPxEditData MPxEditData MPxEditData MPxEditData MPxEditData