pipeline.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:pyblish-starter 作者: pyblish 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号