Source code for artv2_components.rig_asset

# -*- coding: utf-8 -*-
"""
This module contains the class for defining a rig asset (character, weapon, etc). The methods in this class are for
operating on an asset-level, such as getting all components of an asset, getting all controls of an asset, etc.

"""

import pymel.core as pm

import artv2_utilities.component_utilities as component_utils
import artv2_utilities.error_utilities as errors
import artv2_utilities.general_utilities as utils


[docs]class RigAsset(object): """ The rig asset class defines the top-level representation of a rig. """ def __init__(self, network_node=None): if network_node is None: self._unique_name = "asset" self._create_asset() else: network_node = pm.PyNode(network_node) self._unique_name = network_node.attr("name").get() # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
[docs] def _create_asset(self): """ Creates a network node and adds metadata to the network node to define the rig asset. """ network_node = self._create_network_node() self._add_metadata(network_node)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
[docs] def _create_network_node(self): """ Creates the metanode to store metadata. :return: Returns the metanode :rtype: PyNode """ network_nodes = pm.ls(type="network") for node in network_nodes: if pm.objExists(node + ".components"): errors.raise_error("An asset node already exists. Cannot create new asset.") return network_node = pm.shadingNode("network", name=self._unique_name + "_metadata", asUtility=True) network_node.lock() return network_node
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
[docs] def _add_metadata(self, network_node): """ Adds attributes for tracking metadata to the asset's network node. :param network_node: The metanode to add attributes onto. :type network_node: PyNode """ network_node.unlock() network_node.addAttr("components", at="message") network_node.addAttr("name", dt="string", keyable=False) network_node.attr("name").set(self._unique_name, type="string") network_node.lock()
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # @property def name(self): """ This property holds the asset name. This could be the name of the character, for example. """ return self.network_node.attr("name").get() @name.setter def name(self, new_name): if component_utils.validate_asset_name(new_name) is True: self.network_node.attr("name").set(new_name, type="string") self._unique_name = new_name pynode = pm.PyNode(self.network_node) utils.rename_object(pynode, self._unique_name + "_metadata") # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # @property def network_node(self): """ This property holds the network node that contains the asset's metadata. """ return_node = None assets = component_utils.get_all_rig_asset_nodes() for asset in assets: if asset.attr("name").get() == self._unique_name: return_node = asset break return return_node