def test_get_as_object(self): # TODO: Add more tests. MObject can be used is so many ways. name = 'myNode1' node = maya.cmds.createNode('transform', name=name) obj = node_utils.get_as_object(node) self.assertEqual(obj.apiType(), OpenMaya.MFn.kTransform) maya.cmds.delete(node) obj = node_utils.get_as_object(node) self.assertEqual(obj, None)
def get_isolated_nodes(model_panel): """ Return nodes that are being isolated for 'model_panel'. """ nodes = [] state = maya.cmds.isolateSelect( model_panel, query=True, state=True) if state is False: return nodes set_node = maya.cmds.isolateSelect( model_panel, query=True, viewObjects=True) obj = node_utils.get_as_object(set_node) set_mfn = OpenMaya.MFnSet(obj) flatten = False full_path = True sel_list = OpenMaya.MSelectionList() try: set_mfn.getMembers(sel_list, flatten) except RuntimeError: return nodes sel_list.getSelectionStrings(nodes) if full_path is True: nodes = maya.cmds.ls(nodes, long=True) or [] return nodes
def __init__(self, node=None, name=None): """ Initialize the SetHelper with the given Maya node. :param node: Maya node to attach to. :type node: str or None :param name: This is a backwards compatible kwarg for 'node'. :type name: None or str """ if name is not None: msg = ("mmSolver.api.SetHelper(name=value), " "'name' is a deprecated flag, use 'node' ") warnings.warn(msg) node = name if node is not None: if isinstance(node, (str, unicode)): obj = node_utils.get_as_object(node) self._mfn = OpenMaya.MFnSet(obj) else: msg = 'node argument must be a string.' raise TypeError(msg) else: self._mfn = OpenMaya.MFnSet() return
def set_node(self, name): obj = node_utils.get_as_object(name) try: self._mfn = OpenMaya.MFnSet(obj) except RuntimeError: raise return
def get_deviation_anim_curve_fn(self): """ Get the MFnAnimCurve object for the deviation attribute animCurve. .. note:: Returned object is Maya API 1.0. :returns: Maya animCurve function set. :rtype: maya.OpenMayaAnim.MFnAnimCurve or None """ animFn = self._MFnAnimCurve_deviation if animFn is None: node = self.get_node() if node is None: msg = 'Could not get Marker node. self=%r' LOG.warning(msg, self) return animFn plug_name = '{0}.{1}'.format(node, const.MARKER_ATTR_LONG_NAME_DEVIATION) animCurves = maya.cmds.listConnections(plug_name, type='animCurveTU') or [] if len(animCurves) > 0: mobj = node_utils.get_as_object(animCurves[0]) animFn = OpenMayaAnim.MFnAnimCurve(mobj) return animFn
def add_callbacks_to_bundle(node_uuid, node_path, update_func): """ Add all callbacks for a node from a 'Bundle' class. """ callback_ids = [] node_mobj = node_utils.get_as_object(node_path) # Attribute Changed (if a marker/bundle relationship is changed.) clientData = (node_uuid, update_func) callback_id = OpenMaya.MNodeMessage.addAttributeChangedCallback( node_mobj, attribute_connection_changed_func, clientData, ) callback_ids.append(callback_id) # Node Name Change clientData = (node_uuid, update_func) callback_id = OpenMaya.MNodeMessage.addNameChangedCallback( node_mobj, node_name_changed_func, clientData, ) callback_ids.append(callback_id) # Node Has Been Deleted clientData = (node_uuid, update_func) callback_id = OpenMaya.MNodeMessage.addNodeDestroyedCallback( node_mobj, node_deleted_func, clientData, ) callback_ids.append(callback_id) return callback_ids
def add_callbacks_to_camera(node_uuid, node_path, update_func): """ Add all callbacks for a node from a 'Camera' class. :return: List of callback ids created. :rtype: list of maya.OpenMaya.MCallbackId """ callback_ids = [] node_mobj = node_utils.get_as_object(node_path) # Node Name Change clientData = (node_uuid, update_func) callback_id = OpenMaya.MNodeMessage.addNameChangedCallback( node_mobj, node_name_changed_func, clientData, ) callback_ids.append(callback_id) # Node Has Been Deleted clientData = (node_uuid, update_func) callback_id = OpenMaya.MNodeMessage.addNodeDestroyedCallback( node_mobj, node_deleted_func, clientData, ) callback_ids.append(callback_id) return callback_ids
def member_in_set(self, name): # NOTE: For attributes, you must use a MPlug, as testing with # an MObject only tests the dependency node if '.' in name: plug = node_utils.get_as_plug(name) ret = self._mfn.isMember(plug) else: obj = node_utils.get_as_object(name) ret = self._mfn.isMember(obj) return ret
def add_callbacks_attribute(node_uuid, node_path, update_func): """ Add all callbacks for a node from a 'Attribute' class. Many callbacks are created for the node given. :param node_uuid: An 'unchanging' unique id for a node, we can refer back to the node without holding a reference to a smart pointer. :type node_uuid: str :param node_path: The full node path for the node. :type node_path: str :param update_func: The function pointer to be called each time the a change is made. :type update_func: Function :return: List of callback ids created. :rtype: list of maya.OpenMaya.MCallbackId """ callback_ids = [] node_mobj = node_utils.get_as_object(node_path) # Attribute Changed clientData = (node_uuid, update_func) callback_id = OpenMaya.MNodeMessage.addAttributeChangedCallback( node_mobj, attribute_changed_func, clientData, ) callback_ids.append(callback_id) # Node Name Change clientData = (node_uuid, update_func) callback_id = OpenMaya.MNodeMessage.addNameChangedCallback( node_mobj, node_name_changed_func, clientData, ) callback_ids.append(callback_id) # Node Has Been Deleted clientData = (node_uuid, update_func) callback_id = OpenMaya.MNodeMessage.addNodeDestroyedCallback( node_mobj, node_deleted_func, clientData, ) callback_ids.append(callback_id) return callback_ids
def add_callbacks_to_collection(node_uuid, node_path, update_func): """ Add all callbacks for a node from a 'Collection' class. """ callback_ids = [] node_mobj = node_utils.get_as_object(node_path) clientData = (node_uuid, update_func) callback_id = OpenMaya.MObjectSetMessage.addSetMembersModifiedCallback( node_mobj, membership_change_func, clientData, ) callback_ids.append(callback_id) return callback_ids
def add_callbacks_to_marker_group(node_uuid, node_path, update_func): """ Add all callbacks for a node from a 'MarkerGroup' class. """ callback_ids = [] node_mobj = node_utils.get_as_object(node_path) # Node Has Been Deleted # TODO: This callback does not seem to be doing anything. clientData = (node_uuid, update_func) callback_id = OpenMaya.MNodeMessage.addNodeDestroyedCallback( node_mobj, node_deleted_func, clientData, ) callback_ids.append(callback_id) return callback_ids
def add_callbacks_to_collection(node_uuid, node_path): """ Add all callbacks for a node from a 'Collection' class. :return: List of callback ids created. :rtype: list of maya.OpenMaya.MCallbackId """ callback_ids = [] node_mobj = node_utils.get_as_object(node_path) clientData = node_uuid callback_id = OpenMaya.MObjectSetMessage.addSetMembersModifiedCallback( node_mobj, membership_change_func, clientData, ) callback_ids.append(callback_id) return callback_ids
def add_callbacks_to_marker(node_uuid, node_path, update_func): """ Add all callbacks for a node from a 'Marker' class. .. todo:: - Add callback when parenting changes (marker may not live under camera anymore), specific to marker objects. :return: List of callback ids created. :rtype: list of maya.OpenMaya.MCallbackId """ callback_ids = [] node_mobj = node_utils.get_as_object(node_path) # Attribute Changed (if a marker/bundle relationship is changed.) clientData = (node_uuid, update_func) callback_id = OpenMaya.MNodeMessage.addAttributeChangedCallback( node_mobj, attribute_connection_changed_func, clientData, ) callback_ids.append(callback_id) # Node Name Change clientData = (node_uuid, update_func) callback_id = OpenMaya.MNodeMessage.addNameChangedCallback( node_mobj, node_name_changed_func, clientData, ) callback_ids.append(callback_id) # Node Has Been Deleted # TODO: This callback does not seem to be doing anything. clientData = (node_uuid, update_func) callback_id = OpenMaya.MNodeMessage.addNodeDestroyedCallback( node_mobj, node_deleted_func, clientData, ) callback_ids.append(callback_id) return callback_ids