item的用法


https://developer.shotgunsoftware.com/tk-multi-publish2/api.html#publish-api-item

sgtk中的items.context 获取到的实体只包含code与id,详细信息需要用findone


print item
# zhongkui.mod.mod_lo.v019.ma (Maya Session)

print dir(item)
# ['__class__', '__del__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__slots__', '__str__', '__subclasshook__', '_active', '_allows_context_change', '_children', '_context', '_created_temp_files', '_current_temp_file_path', '_description', '_enabled', '_expanded', '_get_image', '_get_local_properties', '_get_type', '_global_properties', '_icon_path', '_icon_pixmap', '_local_properties', '_name', '_parent', '_persistent', '_set_type', '_tasks', '_thumbnail_enabled', '_thumbnail_explicit', '_thumbnail_path', '_thumbnail_pixmap', '_traverse_item', '_type_display', '_type_spec', '_validate_image', '_visit_recursive', 'active', 'add_task', 'checked', 'children', 'clear_tasks', 'context', 'context_change_allowed', 'create_item', 'descendants', 'description', 'display_type', 'enabled', 'expanded', 'from_dict', 'get_property', 'get_thumbnail_as_path', 'icon', 'is_root', 'local_properties', 'name', 'parent', 'persistent', 'properties', 'remove_item', 'set_icon_from_path', 'set_thumbnail_from_path', 'tasks', 'thumbnail', 'thumbnail_enabled', 'thumbnail_explicit', 'to_dict', 'type', 'type_display', 'type_spec']

print type(item)
# <class 'tkimpf9aed5621a0d422c868ea101422c485d.tk_multi_publish2.api.item.PublishItem'>

print item.context
# mod_lo, Asset zhongkui

print dir(item.context)
# ['_Context__additional_entities', '_Context__entity', '_Context__project', '_Context__source_entity', '_Context__step', '_Context__task', '_Context__tk', '_Context__user', '__class__', '__deepcopy__', '__delattr__', '__dict__', '__doc__', '__eq__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_cleanup_entity', '_entity_fields_cache', '_fields_from_entity_paths', '_fields_from_shotgun', '_fields_from_template_tree', '_from_dict', '_get_project_roots', 'additional_entities', 'as_template_fields', 'create_copy_for_user', 'deserialize', 'entity', 'entity_locations', 'filesystem_locations', 'from_dict', 'project', 'serialize', 'sgtk', 'shotgun_url', 'source_entity', 'step', 'tank', 'task', 'to_dict', 'user']

print type(item.context)
# <class 'tank.context.Context'>


print item.context.task
# {'type': 'Task', 'name': 'mod_lo', 'id': 6148}

print type(item.context.task)
# <type 'dict'>

# item.context下的属性为对应实体字典与find_one返回字典相同

print item.properties
# <tkimpf9aed5621a0d422c868ea101422c485d.tk_multi_publish2.api.data.PublishData object at 0x000001691105AB00>

print dir(item.properties)
# ['_MutableMapping__marker', '__abstractmethods__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dict__', '__doc__', '__eq__', '__format__', '__getattribute__', '__getitem__', '__hash__', '__init__', '__iter__', '__len__', '__metaclass__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_abc_cache', '_abc_negative_cache', '_abc_negative_cache_version', '_abc_registry', 'clear', 'from_dict', 'get', 'items', 'iteritems', 'iterkeys', 'itervalues', 'keys', 'pop', 'popitem', 'project_root', 'setdefault', 'to_dict', 'update', 'values', 'work_template']

print type(item.properties)
# <class 'tkimpf9aed5621a0d422c868ea101422c485d.tk_multi_publish2.api.data.PublishData'>

print type(item.properties.items())
# <type 'list'>


# task向上获取资产
# item只能获取到task,其他实体只能获取id、code、type

asset_id = item.context.entity['id']
asset_object = sg.find_one('Asset', [['id', 'is', asset_id]], ['sg_asset_type'])
# sgtkd engine 与 item 的区别
import sgtk

engine = sgtk.platform.current_engine()

print engine
print item
# <Sgtk Engine 0x17e98059358: tk-maya, env: asset_step>
# lanternbird_c.rig.rig_lay.v002.ma (Maya Session)

print engine.context
print item.context

# rig_lay, Asset lanternbird_c
#rig_lay, Asset lanternbird_c

评论
  目录