def load(asset, version=-1):
"""Load asset
Arguments:
asset ("pyblish-starter:asset-1.0"): Asset which to import
version (int, optional): Version number, defaults to latest
Returns:
Reference node
Raises:
IndexError on no version found
ValueError on no supported representation
"""
assert asset["schema"] == "pyblish-starter:asset-1.0"
assert isinstance(version, int), "Version must be integer"
try:
version = asset["versions"][version]
except IndexError:
raise IndexError("\"%s\" of \"%s\" not found." % (version, asset))
supported_formats = api.registered_formats()
# Pick any compatible representation.
# Hint: There's room to make the user choose one of many.
# Such as choosing between `.obj` and `.ma` and `.abc`,
# each compatible but different.
try:
representation = next(
rep for rep in version["representations"]
if rep["format"] in supported_formats and
rep["path"] != "{dirname}/source{format}"
)
except StopIteration:
formats = list(r["format"] for r in version["representations"])
raise ValueError(
"No supported representations for \"%s\"\n\n"
"Supported representations: %s"
% (asset["name"], "\n- ".join(formats)))
fname = representation["path"].format(
dirname=version["path"],
format=representation["format"]
)
nodes = cmds.file(fname,
namespace=asset["name"] + "_",
reference=True,
returnNewNodes=True)
self.log.info("Containerising \"%s\".." % fname)
containerise(asset["name"], nodes, version)
self.log.info("Container created, returning reference node.")
return cmds.referenceQuery(nodes[0], referenceNode=True)
评论列表
文章目录