Merged in Aardschok/config/0021 (pull request #34)

0021
This commit is contained in:
Wijnand Koreman 2017-09-25 13:05:58 +00:00
commit 78d438efe1
3 changed files with 44 additions and 30 deletions

View file

@ -1,5 +1,4 @@
import os
import uuid
from maya import cmds
@ -18,6 +17,7 @@ PUBLISH_PATH = os.path.join(PLUGINS_DIR, "maya", "publish")
LOAD_PATH = os.path.join(PLUGINS_DIR, "maya", "load")
CREATE_PATH = os.path.join(PLUGINS_DIR, "maya", "create")
LOAD_AT_START = ["AbcImport", "AbcExport"]
# This is a temporary solution with the http.py clash with six.py
# Maya has added paths to the PYTHONPATH which are redundant as
@ -73,6 +73,12 @@ def install():
menu.install()
# Add any needed plugins
for plugin in LOAD_AT_START:
if cmds.pluginInfo(plugin, query=True, loaded=True):
continue
cmds.loadPlugin(plugin, quiet=True)
print("Installing callbacks ... ")
avalon.on("init", on_init)
avalon.on("new", on_new)
@ -90,31 +96,6 @@ def uninstall():
menu.uninstall()
def _set_uuid(asset_id, node):
"""Add cbId to `node`
Unless one already exists.
"""
attr = "{0}.cbId".format(node)
if not cmds.attributeQuery("cbId", node=node, exists=True):
cmds.addAttr(node, longName="cbId", dataType="string")
_, uid = str(uuid.uuid4()).rsplit("-", 1)
cb_uid = "{}:{}".format(asset_id, uid)
cmds.setAttr(attr, cb_uid, type="string")
def _copy_uuid(source, target):
source_attr = "{0}.cbId".format(source)
target_attr = "{0}.cbId".format(target)
if not cmds.attributeQuery("cbId", node=target, exists=True):
cmds.addAttr(target, longName="cbId", dataType="string")
attribute_value = cmds.getAttr(source_attr)
cmds.setAttr(target_attr, attribute_value, type="string")
def on_init(_):
avalon.logger.info("Running callback on init..")
@ -149,6 +130,5 @@ def on_save(_):
projection={"_id": True})
# generate the ids
for node in nodes:
_set_uuid(str(asset_id["_id"]), node)
lib.set_id(str(asset_id["_id"]), node)

View file

@ -2,6 +2,8 @@
import re
import os
import uuid
import bson
import json
import logging
@ -677,6 +679,30 @@ def get_id(node):
return cmds.getAttr("{}.cbId".format(node))
def set_id(asset_id, node):
"""Add cbId to `node` unless one already exists.
Args:
asset_id (str): the unique asset code from the database
node (str): the node to add the "cbId" on
Returns:
None
"""
attr = "{0}.cbId".format(node)
if not cmds.attributeQuery("cbId", node=node, exists=True):
cmds.addAttr(node, longName="cbId", dataType="string")
_, uid = str(uuid.uuid4()).rsplit("-", 1)
cb_uid = "{}:{}".format(asset_id, uid)
cmds.setAttr(attr, cb_uid, type="string")
def remove_id(node):
if cmds.attributeQuery("cbId", node=node, exists=True):
cmds.deleteAttr("{}.cbId".format(node))
def get_representation_file(representation, template=TEMPLATE):
"""
Rebuild the filepath of the representation's context

View file

@ -1545,6 +1545,14 @@
"title": "Remove User Defined Attributes",
"tooltip": ""
},
{
"type": "action",
"command": "$COLORBLEED_SCRIPTS\\cleanup\\update_asset_id.py",
"sourcetype": "file",
"tags":["cleanup", "update", "database", "asset", "id"],
"title": "Update Asset ID",
"tooltip": "Will replace the Colorbleed ID with a new one (asset ID : Unique number)"
},
{
"type": "action",
"command": "$COLORBLEED_SCRIPTS\\cleanup\\removeUnknownNodes.py",
@ -1744,13 +1752,13 @@
},
{
"type": "action",
"command": "$COLORBLEED_SCRIPTS\\cleanup\\",
"command": "$COLORBLEED_SCRIPTS\\others\\instanceLeafSmartTransform.py",
"sourcetype": "file",
"tags": ["others", "instance","leaf", "smart", "transform"],
"title": "Instance Leaf Smart Transform",
"tooltip": ""
},
{
{
"type": "action",
"command": "$COLORBLEED_SCRIPTS\\others\\instanceSmartTransform.py",
"sourcetype": "file",