本文整理汇总了Python中cache.Cache.set_network_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Cache.set_network_by_id方法的具体用法?Python Cache.set_network_by_id怎么用?Python Cache.set_network_by_id使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cache.Cache
的用法示例。
在下文中一共展示了Cache.set_network_by_id方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: export_network
# 需要导入模块: from cache import Cache [as 别名]
# 或者: from cache.Cache import set_network_by_id [as 别名]
def export_network(data, cache=None, **kwargs):
if cache is None:
from cache import Cache
cache = Cache()
#log.debug('CreateNetwork {0}'.format(data))
# We'll deal with two additional attributes, '_network' and '_uid'.
# Thoses two attributes allow us to find the network from the value and vice-versa.
# Note that since the '_uid' refer to the current python context,
# it's value could be erroned when calling import_network.
# However the change of collisions are extremely improbable so checking the type of the python variable
# is sufficient.
# Please feel free to provide a better design if any if possible.
# todo: after refactoring, the network cache will be merged with the import cache
data_id = id(data)
result = cache.get_network_by_id(data_id)
if result is not None:
return result
# Create network
# Optimisation: Use existing network if already present in scene
#if hasattr(data, '_network') and is_valid_PyNode(data._network):
# network = data._network
#else:
# Automaticly name network whenever possible
try:
network_name = data.__getNetworkName__()
except (AttributeError, TypeError):
network_name = data.__class__.__name__
network = pymel.createNode('network', name=network_name)
# Monkey patch the network in a _network attribute if supported.
if isinstance(data, object) and not isinstance(data, dict):
data._network = network
# Ensure the network have the current python id stored
if not network.hasAttr('_uid'):
pymel.addAttr(network, longName='_uid', niceName='_uid', at='long') # todo: validate attributeType
# network._uid.set(id(_data))
# Cache as soon as possible since we'll use recursivity soon.
cache.set_network_by_id(data_id, network)
# Convert _pData to basic data dictionary (recursive for now)
data_dict = core.export_dict(data, recursive=False, cache=cache, **kwargs)
assert (isinstance(data_dict, dict))
fnNet = network.__apimfn__()
for key, val in data_dict.items():
if _can_export_attr_by_name(key):
_add_attr(fnNet, key, val, cache=cache)
return network