示例#1
0
def attribute_connection_changed_func(callback_msg, plugA, plugB, clientData):
    """
    Callback triggered when an event happens to an attribute on a node.

    One callback handles many attributes and event types for one node.
    The callback is linked to the node, not the attribute.

    :param callback_msg: The type of callback message.
    :type callback_msg: OpenMaya.MNodeMessage.AttributeMessage

    :param plugA: First plug related to callback.
    :type plugA: OpenMaya.MPlug

    :param plugB: Second plug related to callback, may not be used if
                  not relevant to callback type.
    :type plugB: OpenMaya.MPlug

    :param clientData: node_uuid given to the function.
    :type clientData: str

    :return: Nothing.
    :rtype: None
    """
    node_uuid = clientData
    if (callback_msg & OpenMaya.MNodeMessage.kConnectionMade
            or callback_msg & OpenMaya.MNodeMessage.kConnectionBroken
            or callback_msg & OpenMaya.MNodeMessage.kAttributeRemoved):
        event_utils.trigger_event(
            mmapi.EVENT_NAME_ATTRIBUTE_CONNECTION_CHANGED,
            node=node_uuid,
            plug=plugA)
    return
 def remove_attribute(self, attr):
     assert isinstance(attr, attribute.Attribute)
     name = attr.get_name()
     if self._set.member_in_set(name):
         self._set.remove_member(name)
         self._actions_list = []  # reset argument flag cache.
     event_utils.trigger_event(const.EVENT_NAME_COLLECTION_ATTRS_CHANGED,
                               col=self)
     return
 def remove_marker(self, mkr):
     assert isinstance(mkr, marker.Marker)
     node = mkr.get_node()
     if self._set.member_in_set(node):
         self._set.remove_member(node)
         self._actions_list = []  # reset argument flag cache.
     event_utils.trigger_event(const.EVENT_NAME_COLLECTION_MARKERS_CHANGED,
                               col=self)
     return
 def remove_attribute_list(self, attr_list):
     assert isinstance(attr_list, list)
     name_list = []
     for attr in attr_list:
         if isinstance(attr, attribute.Attribute):
             name_list.append(attr.get_name())
     self._set.remove_members(name_list)
     self._actions_list = []  # reset argument flag cache.
     event_utils.trigger_event(const.EVENT_NAME_COLLECTION_ATTRS_CHANGED,
                               col=self)
     return
 def remove_marker_list(self, mkr_list):
     assert isinstance(mkr_list, list)
     node_list = []
     for mkr in mkr_list:
         if isinstance(mkr, marker.Marker):
             node_list.append(mkr.get_node())
     self._set.remove_members(node_list)
     self._actions_list = []  # reset argument flag cache.
     event_utils.trigger_event(const.EVENT_NAME_COLLECTION_MARKERS_CHANGED,
                               col=self)
     return
 def add_marker(self, mkr):
     assert isinstance(mkr, marker.Marker)
     node = mkr.get_node()
     assert isinstance(node, (str, unicode))
     assert len(node) > 0
     if self._set.member_in_set(node) is False:
         self._set.add_member(node)
         self._actions_list = []  # reset argument flag cache.
     event_utils.trigger_event(const.EVENT_NAME_COLLECTION_MARKERS_CHANGED,
                               col=self)
     return
    def create_node(self, name):
        """
        Create a collection set node.
        """
        self._set.create_node(name)
        set_node = self._set.get_node()
        _create_collection_attributes(set_node)

        event_utils.trigger_event(const.EVENT_NAME_COLLECTION_CREATED,
                                  col=self)
        return self
 def clear_attribute_list(self):
     members = self._set.get_all_members(flatten=False, full_path=True)
     rm_list = []
     for member in members:
         object_type = api_utils.get_object_type(member)
         if object_type == const.OBJECT_TYPE_ATTRIBUTE:
             rm_list.append(member)
     if len(rm_list) > 0:
         self._set.remove_members(rm_list)
         self._actions_list = []  # reset argument flag cache.
     event_utils.trigger_event(const.EVENT_NAME_COLLECTION_ATTRS_CHANGED,
                               col=self)
     return
示例#9
0
def node_deleted_func(clientData):
    """
    Callback triggered *after* a node is deleted.

    :param clientData: node_uuid given to the function.
    :type clientData: str

    :return: Nothing.
    :rtype: None
    """
    node_uuid = clientData
    LOG.debug('node_deleted: %r', node_uuid)
    event_utils.trigger_event(mmapi.EVENT_NAME_NODE_DELETED, node=node_uuid)
    return
    def set_attribute_list(self, attr_list):
        assert isinstance(attr_list, list)
        before_num = self.get_attribute_list_length()

        self.clear_attribute_list()
        for attr in attr_list:
            if isinstance(attr, attribute.Attribute):
                self.add_attribute(attr)

        after_num = self.get_attribute_list_length()
        if before_num != after_num:
            self._actions_list = []  # reset argument flag cache.
        event_utils.trigger_event(const.EVENT_NAME_COLLECTION_ATTRS_CHANGED,
                                  col=self)
        return
    def set_marker_list(self, mkr_list):
        assert isinstance(mkr_list, list)
        before_num = self.get_marker_list_length()

        self.clear_marker_list()
        for mkr in mkr_list:
            if isinstance(mkr, marker.Marker):
                self.add_marker(mkr)

        after_num = self.get_marker_list_length()
        if before_num != after_num:
            self._actions_list = []  # reset argument flag cache.

        event_utils.trigger_event(const.EVENT_NAME_COLLECTION_MARKERS_CHANGED,
                                  col=self)
        return
示例#12
0
def node_name_changed_func(node, prevName, clientData):
    """
    Callback triggered after a node is renamed.

    :param node: The node that has been renamed.
    :type node: OpenMaya.MObject

    :param prevName: The name of the node before the change happened.
    :type prevName: str

    :param clientData: node_uuid given to the function.
    :type clientData: str

    :return: Nothing.
    :rtype: None
    """
    node_uuid = clientData
    LOG.debug('node_name_changed: %r', node_uuid)
    event_utils.trigger_event(mmapi.EVENT_NAME_NODE_NAME_CHANGED,
                              node=node_uuid,
                              previous_name=prevName)
    return
示例#13
0
    def create_node(self, name='bundle1', colour=None):
        """
        Create a Bundle.

        :param name: The name of the newly created Bundle.
        :type name: str

        :param colour: Colour of bundle as R, G and B.
                       'None' will leave as default.
        :type colour: (float, float, float) or None

        :return: Bundle object attached to newly created node.
        :rtype: Bundle
        """
        assert isinstance(name, pycompat.TEXT_TYPE)
        if colour is not None:
            assert isinstance(colour, (tuple, list))
            assert len(colour) == 3

        # Transform
        tfm = maya.cmds.createNode(const.BUNDLE_TRANSFORM_NODE_TYPE, name=name)
        tfm = node_utils.get_long_name(tfm)

        # Show the bundle transform attributes in the channel box, but
        # the attributes are locked, so this is compatible with
        # versions before v0.3.15.
        lock_rot_scale = True
        display_rot_scale = True
        lock_shear = True
        display_shear = False
        _lock_and_display_bundle_attributes(
            tfm,
            lock_translate=False,
            lock_rotate=lock_rot_scale,
            lock_scale=lock_rot_scale,
            lock_shear=lock_shear,
            display_translate=True,
            display_rotate=display_rot_scale,
            display_scale=display_rot_scale,
            display_shear=display_shear,
        )

        # Shape Node
        shp_name = tfm.rpartition('|')[-1] + 'Shape'
        shp = maya.cmds.createNode(const.BUNDLE_SHAPE_NODE_TYPE,
                                   name=shp_name,
                                   parent=tfm)
        maya.cmds.setAttr(shp + '.localScaleX', 0.1)
        maya.cmds.setAttr(shp + '.localScaleY', 0.1)
        maya.cmds.setAttr(shp + '.localScaleZ', 0.1)

        self.set_node(tfm)

        # Set Colour (default is green)
        if colour is not None:
            self.set_colour_rgb(colour)
        else:
            green = (0.0, 1.0, 0.0)
            self.set_colour_rgb(green)

        event_utils.trigger_event(const.EVENT_NAME_BUNDLE_CREATED, bnd=self)
        return self
示例#14
0
    def create_node(self,
                    name='marker1',
                    colour=None,
                    cam=None,
                    mkr_grp=None,
                    bnd=None):
        """
        Create a marker node network from scratch.

        :param name: Name of the marker to create.
        :type name: str

        :param colour: Colour of marker as R, G and B.
                       'None' will leave as default.
        :type colour: (float, float, float) or None

        :param cam: The camera to create the marker underneath.
        :type cam: Camera

        :param mkr_grp: The marker group to create the marker underneath.
        :type mkr_grp: MarkerGroup

        :param bnd: The bundle to attach to the newly created marker.
        :type bnd: Bundle

        :return: Marker object with newly created node.
        :rtype: Marker
        """
        assert isinstance(name, (str, unicode))
        if cam is not None:
            if mkr_grp is not None:
                msg = 'Cannot specify both camera and marker group, '
                msg += 'please choose only one.'
                raise excep.NotValid(msg)
            assert isinstance(cam, camera.Camera)
        if mkr_grp is not None:
            if cam is not None:
                msg = 'Cannot specify both camera and marker group, '
                msg += 'please choose only one.'
                raise excep.NotValid(msg)
            assert isinstance(mkr_grp, markergroup.MarkerGroup)
        if bnd is not None:
            assert isinstance(bnd, mmSolver._api.bundle.Bundle)
        if colour is not None:
            assert isinstance(colour, (tuple, list))
            assert len(colour) == 3

        # Transform
        tfm = maya.cmds.createNode(const.MARKER_TRANSFORM_NODE_TYPE, name=name)
        tfm = node_utils.get_long_name(tfm)
        maya.cmds.setAttr(tfm + '.tz', -1.0)
        maya.cmds.setAttr(tfm + '.tz', lock=True)
        maya.cmds.setAttr(tfm + '.rx', lock=True)
        maya.cmds.setAttr(tfm + '.ry', lock=True)
        maya.cmds.setAttr(tfm + '.rz', lock=True)
        maya.cmds.setAttr(tfm + '.sx', lock=True)
        maya.cmds.setAttr(tfm + '.sy', lock=True)
        maya.cmds.setAttr(tfm + '.sz', lock=True)
        maya.cmds.setAttr(tfm + '.shxy', lock=True)
        maya.cmds.setAttr(tfm + '.shxz', lock=True)
        maya.cmds.setAttr(tfm + '.shyz', lock=True)
        maya.cmds.setAttr(tfm + '.tz', keyable=False, channelBox=False)
        maya.cmds.setAttr(tfm + '.rx', keyable=False, channelBox=False)
        maya.cmds.setAttr(tfm + '.ry', keyable=False, channelBox=False)
        maya.cmds.setAttr(tfm + '.rz', keyable=False, channelBox=False)
        maya.cmds.setAttr(tfm + '.sx', keyable=False, channelBox=False)
        maya.cmds.setAttr(tfm + '.sy', keyable=False, channelBox=False)
        maya.cmds.setAttr(tfm + '.sz', keyable=False, channelBox=False)
        maya.cmds.setAttr(tfm + '.shxy', keyable=False, channelBox=False)
        maya.cmds.setAttr(tfm + '.shxz', keyable=False, channelBox=False)
        maya.cmds.setAttr(tfm + '.shyz', keyable=False, channelBox=False)

        # Shape Node
        shp_name = tfm.rpartition('|')[-1] + 'Shape'
        shp = maya.cmds.createNode(const.MARKER_SHAPE_NODE_TYPE,
                                   name=shp_name, parent=tfm)
        maya.cmds.setAttr(shp + '.localScaleX', 0.01)
        maya.cmds.setAttr(shp + '.localScaleY', 0.01)
        maya.cmds.setAttr(shp + '.localScaleZ', 0.0)
        maya.cmds.setAttr(shp + '.localScaleZ', lock=True)

        # Add attrs
        _create_marker_attributes(tfm)

        src = '{0}.{1}'.format(tfm, const.MARKER_ATTR_LONG_NAME_ENABLE)
        dst = '{0}.{1}'.format(tfm, 'lodVisibility')
        maya.cmds.connectAttr(src, dst)

        self.set_node(tfm)

        # Set Colour (default is red)
        if colour is not None:
            self.set_colour_rgb(colour)
        else:
            red = (1.0, 0.0, 0.0)
            self.set_colour_rgb(red)

        # Link to Camera
        if cam is not None:
            self.set_camera(cam)

        # Link to MarkerGroup
        if mkr_grp is not None:
            self.set_marker_group(mkr_grp)

        # Link to Bundle
        if bnd is not None:
            self.set_bundle(bnd)

        event_utils.trigger_event(
            const.EVENT_NAME_MARKER_CREATED,
            mkr=self)
        return self
示例#15
0
def membership_change_func(node_obj, clientData):
    node_uuid = clientData
    LOG.debug('membership_changed: %r', node_uuid)
    event_utils.trigger_event(mmapi.EVENT_NAME_MEMBERSHIP_CHANGED,
                              node=node_uuid)
    return
示例#16
0
 def flushing_scene_func():
     LOG.debug('MM Solver Flushing Scene...')
     event_name = mmapi.EVENT_NAME_MAYA_SCENE_CLOSING
     event_utils.trigger_event(event_name)
示例#17
0
    def create_node(self, name='bundle1', colour=None):
        """
        Create a Bundle.

        :param name: The name of the newly created Bundle.
        :type name: str

        :param colour: Colour of bundle as R, G and B.
                       'None' will leave as default.
        :type colour: (float, float, float) or None

        :return: Bundle object attached to newly created node.
        :rtype: Bundle
        """
        assert isinstance(name, (str, unicode))
        if colour is not None:
            assert isinstance(colour, (tuple, list))
            assert len(colour) == 3

        # Transform
        tfm = maya.cmds.createNode(const.BUNDLE_TRANSFORM_NODE_TYPE, name=name)
        tfm = node_utils.get_long_name(tfm)
        maya.cmds.setAttr(tfm + '.rx', lock=True)
        maya.cmds.setAttr(tfm + '.ry', lock=True)
        maya.cmds.setAttr(tfm + '.rz', lock=True)
        maya.cmds.setAttr(tfm + '.sx', lock=True)
        maya.cmds.setAttr(tfm + '.sy', lock=True)
        maya.cmds.setAttr(tfm + '.sz', lock=True)
        maya.cmds.setAttr(tfm + '.shxy', lock=True)
        maya.cmds.setAttr(tfm + '.shxz', lock=True)
        maya.cmds.setAttr(tfm + '.shyz', lock=True)
        maya.cmds.setAttr(tfm + '.rx', keyable=False)
        maya.cmds.setAttr(tfm + '.ry', keyable=False)
        maya.cmds.setAttr(tfm + '.rz', keyable=False)
        maya.cmds.setAttr(tfm + '.sx', keyable=False)
        maya.cmds.setAttr(tfm + '.sy', keyable=False)
        maya.cmds.setAttr(tfm + '.sz', keyable=False)
        maya.cmds.setAttr(tfm + '.shxy', keyable=False)
        maya.cmds.setAttr(tfm + '.shxz', keyable=False)
        maya.cmds.setAttr(tfm + '.shyz', keyable=False)

        # Shape Node
        shp_name = tfm.rpartition('|')[-1] + 'Shape'
        shp = maya.cmds.createNode(const.BUNDLE_SHAPE_NODE_TYPE,
                                   name=shp_name,
                                   parent=tfm)
        maya.cmds.setAttr(shp + '.localScaleX', 0.1)
        maya.cmds.setAttr(shp + '.localScaleY', 0.1)
        maya.cmds.setAttr(shp + '.localScaleZ', 0.1)

        self.set_node(tfm)

        # Set Colour (default is green)
        if colour is not None:
            self.set_colour_rgb(colour)
        else:
            green = (0.0, 1.0, 0.0)
            self.set_colour_rgb(green)

        event_utils.trigger_event(const.EVENT_NAME_BUNDLE_CREATED, bnd=self)
        return self