Created
February 8, 2021 16:39
-
-
Save BigRoy/c7bd3d76b0f21df21518e65dabe9afdc to your computer and use it in GitHub Desktop.
Avalon example for colorbleed-config on how to load latest version of an asset's `modelDefault` solely from the `cbId` attribute.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example on how to load latest `modelDefault` of an asset by `cbId` value using `AbcLoader` (alembic) | |
import avalon.io as io | |
import avalon.api as api | |
from maya import cmds | |
node = "my_node" | |
cbid = cmds.getAttr("%s.cbId" % node) | |
# Get asset object id from cbId | |
object_id = cbid.split(":", 1)[0] # The part before the : is the asset id | |
object_id = io.ObjectId(object_id) # Make sure it's a pymongo.ObjectId to query the database | |
asset = io.find_one({"_id": object_id, | |
"type": "asset"}) | |
subset = io.find_one({"name": "modelDefault", | |
"parent": asset["_id"], | |
"type": "subset"}) | |
version = io.find_one({"parent": subset["_id"], | |
"type": "version"}, sort=[("name", -1)]) | |
representation = io.find_one({"name": "abc", | |
"parent": version["_id"], | |
"type": "representation"}) | |
# From all loader get the AbcLoader | |
loaders = api.discover(api.Loader) | |
loader = {loader.__name__: loader for loader in loaders}.get("AbcLoader") | |
api.load(loader, representation) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To not use a Loader but just get the Representation path use
avalon.api.get_representation_path()