Added set_id and remove_id

This commit is contained in:
aardschok 2017-09-25 14:17:47 +02:00
parent d5cdf22156
commit a73f529d03

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