示例#1
0
    def path(self):
        """
        Returns the full path of the DCC object in current DCC scene
        :return: str, current full path of the DCC object
        """

        return node_utils.get_name(mobj=self._dcc_native_object, fullname=True)
示例#2
0
    def _dcc_native_copy(self):
        """
        Internal function that returns a copy/duplicate of the wrapped DCC object
        :return: variant
        """

        node_name = node_utils.get_name(self._dcc_native_object, fullname=True)
        return dcc.duplicate_node(node_name)
示例#3
0
    def name(self):
        """
        Returns the name of the DCC object in current DCC scene
        :return: str, current name of the DCC object
        """

        return node_utils.get_name(mobj=self._dcc_native_object,
                                   fullname=False)
示例#4
0
    def has_attribute(self, attribute_name):
        """
        Returns whether or not wrapped native DCC object has an attribute with the given name
        :param attribute_name: str, name of the attribute we are looking for
        :return: bool, True if the attribute exists in the wrapped native DCC object; False otherwise.
        """

        node_name = node_utils.get_name(self._dcc_native_object, fullname=True)
        return dcc.attribute_exists(node_name, attribute_name)
示例#5
0
    def _set_dcc_native_attribute(self, attribute_name, value):
        """
        Sets the value of the property defined by the given attribute name
        :param attribute_name: str, name of the attribute we want to set the value of
        :param value: variant, new value of the attribute
        :return: bool, True if the operation was successful; False otherwise.
        """

        node_name = node_utils.get_name(self._dcc_native_object, fullname=True)

        return dcc.set_attribute_value(node_name, attribute_name, value)
示例#6
0
    def namespace(self):
        """
        Returns DCC object namespace
        :return: str
        """

        node_name = node_utils.get_name(self._dcc_native_object,
                                        fullname=False)
        split = node_name.split(':')[0]
        if len(split) > 1:
            return ':'.join(split[:-1])

        return ''
示例#7
0
    def _dcc_native_attribute(self, attribute_name, default=None):
        """
        Internal function that returns the value of the attribute of the wrapped DCC object
        :param attribute_name: str, name of the attribute we want retrieve value of
        :param default: variant, fallback default value if attribute does not exists in wrapped DCC object
        :return:
        """

        node_name = node_utils.get_name(self._dcc_native_object, fullname=True)
        try:
            return dcc.get_attribute_value(node_name, attribute_name)
        except Exception:
            return default
示例#8
0
    def attribute_names(self, keyable=False, short_names=False, unlocked=True):
        """
        Returns a list of the attributes names linked to wrapped native DCC object
        :param keyable: bool, Whether or not list keyable attributes (animatable properties)
        :param short_names: bool, Whether or not to list attributes with their short name
        :param unlocked: bool, Whether or not list unlocked properties
        :return: list
        """

        node_name = node_utils.get_name(self._dcc_native_object, fullname=True)
        return dcc.list_attributes(node_name,
                                   keyable=keyable,
                                   unlocked=unlocked,
                                   shortNames=short_names)
示例#9
0
    def unique_id(self):
        """
        Returns the unique identifier of the wrapped native DCC object in current DCC scene
        :return: int or str
        """

        if dcc.get_version() >= 2016:
            node_name = node_utils.get_name(self._dcc_native_object,
                                            fullname=True)
            return maya.cmds.ls(node_name, uuid=True)[0]
        else:
            property_value = self._dcc_native_attribute('uuid', default=None)
            if property_value is None:
                return self._native_handle.hashCode()
示例#10
0
    def _dcc_objects(self,
                     from_selection=False,
                     wildcard='',
                     object_type=None):
        """
        Returns DCC objects from current scene
        :param from_selection: bool, Whether to return only selected DCC objects or all objects in the scene
        :param wildcard: str, filter objects by its name
        :param object_type: int
        :return: list(variant)
        """

        expression_regex = name_utils.wildcard_to_regex(wildcard)

        if from_selection:
            objects = helpers.get_selection_iterator()
        else:
            if python.is_string(object_type):
                objects = maya.cmds.ls(type=object_type, long=True)
            else:
                maya_type = dcc.node_types().get(
                    object_type, (maya.api.OpenMaya.MFn.kDagNode,
                                  maya.api.OpenMaya.MFn.kCharacter))
                objects = list(
                    helpers.get_objects_of_mtype_iterator(maya_type))

        if (object_type is not None and object_type != 0) or wildcard:
            objects_list = list()
            for obj in objects:
                if python.is_string(object_type):
                    type_check = True if not object_type else dcc.node_tpdcc_type(
                        obj, as_string=True) == object_type
                else:
                    type_check = True if not object_type else dcc.node_tpdcc_type(
                        obj) == object_type
                if wildcard:
                    obj_name = node_utils.get_name(mobj=obj, fullname=False)
                    wildcard_check = expression_regex.match(obj_name)
                else:
                    wildcard_check = False
                if type_check and wildcard_check:
                    if python.is_string(obj):
                        obj = node_utils.get_mobject(obj)
                    objects_list.append(obj)
            objects = objects_list

        return objects
示例#11
0
    def set_namespace(self, namespace):
        """
        Sets DCC object namespace
        :param namespace: str, new namespace for the DCC object
        """

        node_name = node_utils.get_name(self._dcc_native_object,
                                        fullname=False)
        display_name = node_name.split(':')[-1]
        if not namespace:
            maya.cmds.rename(self.path(), self.display_name())
        else:
            if not maya.cmds.namespace(exists=namespace):
                maya.cmds.namespace(add=namespace)
            maya.cmds.rename(self.path(), ':'.join([namespace, display_name]))

        return True