Shotgrid: filters and fields

Hey People, hope you’ll are doing fine.

Last time we checked entity type in – https://wordpress.com/post/digdeeperts.wordpress.com/1028

in this post we’ll check about the second position in sg.find i.e. filters and fields.

Filters give more narrowed down result. Below is the syntax reference, one needs to write everything in a list.

syntax – [<field>, <relation>, <value(s)>]

field of entity_type – https://developer.shotgridsoftware.com/python-api/reference.html?highlight=schema_field_read#shotgun_api3.shotgun.Shotgun.schema_field_read

just for reference, how to find entity types.

Note: Below are just keys. If you remove the .keys(), you’ll get the dictionary key:values.

from pprint import pprint

entities = sg.schema_entity_read().keys()  # entity_type
pprint(entities)

Below are the entity_type keys

dict_keys([‘ActionMenuItem’, ‘ApiUser’, ‘ApiUserProjectConnection’, ‘AppWelcomeUserConnection’, ‘Asset’, ‘AssetAssetConnection’, ‘AssetBlendshapeConnection’, ‘AssetElementConnection’, ‘AssetEpisodeConnection’, ‘AssetLevelConnection’, ‘AssetMocapTakeConnection’, ‘AssetSceneConnection’, ‘AssetSequenceConnection’, ‘AssetShootDayConnection’, ‘AssetShotConnection’, ‘Asset_linked_projects_Connection’, ‘Attachment’, ‘BannerUserConnection’, ‘Booking’, ‘Camera’, ‘CameraMocapTakeConnection’, ‘ClientUser’, ‘Composition’, ‘CustomEntity01’, ‘CustomEntity01_sg_published_file_Connection’, ‘CustomEntity02’, ‘CustomEntity03’, ‘CustomEntity04’, ‘CustomEntity05’, ‘CustomEntity06’, ‘CustomEntity07’, ‘CustomEntity07_sg_shots_Connection’, ‘CustomEntity08’, ‘CustomEntity10’, ‘CustomEntity11’, ‘CustomEntity12’, ‘CustomNonProjectEntity01’, ‘CustomNonProjectEntity36’, ‘CustomThreadedEntity01’, ‘Cut’, ‘CutItem’, ‘CutVersionConnection’, ‘Delivery’, ‘Delivery_sg_asset_Connection’, ‘Delivery_sg_sent_version_Connection’, ‘Department’, ‘Element’, ‘ElementShotConnection’, ‘Episode’, ‘EventLogEntry’, ‘FilesystemLocation’, ‘Group’, ‘GroupUserConnection’, ‘HumanUser’, ‘Icon’, ‘LaunchSceneConnection’, ‘LaunchShotConnection’, ‘LocalStorage’, ‘MimEntity’, ‘MimField’, ‘MimProject’, ‘MocapTakeRangeShotConnection’, ‘Note’, ‘Page’, ‘PageHit’, ‘PageSetting’, ‘PerformerMocapTakeConnection’, ‘PerformerRoutineConnection’, ‘PerformerShootDayConnection’, ‘PermissionRuleSet’, ‘Phase’, ‘PhysicalAssetMocapTakeConnection’, ‘PipelineConfiguration’, ‘PipelineConfigurationUserConnection’, ‘Playlist’, ‘PlaylistShare’, ‘PlaylistVersionConnection’, ‘Project’, ‘ProjectTaskTemplateConnection’, ‘ProjectUserConnection’, ‘PublishedFile’, ‘PublishedFileDependency’, ‘PublishedFileType’, ‘ReleaseTicketConnection’, ‘Reply’, ‘RevisionRevisionConnection’, ‘RevisionTicketConnection’, ‘RvLicense’, ‘Scene’, ‘Sequence’, ‘Sequence_sg_scene_Connection’, ‘ShootDaySceneConnection’, ‘Shot‘, ‘ShotShotConnection’, ‘Shot_sg_bid_categories_Connection’, ‘Shot_sg_lens_grid_Connection’, ‘Shot_sg_library_tags_Connection’, ‘Shot_sg_linked_slates_Connection’, ‘Slate’, ‘Software’, ‘Status’, ‘Status_sg_tags_Connection’, ‘Step’, ‘Tag’, ‘Task’, ‘TaskDependency’, ‘TaskTemplate’, ‘TaskTemplate_sg_tags_Connection’, ‘Task_sg_vendors_being_used_Connection’, ‘Ticket’, ‘TicketTicketConnection’, ‘TimeLog’, ‘Version’, ‘Version_sg_client_package_name_Connection’, ‘Version_sg_shot_plate_link_Connection’])

code for field for entity types

Note: Below are just keys. If you remove the .keys(), you’ll get the dictionary key:values.

from pprint import pprint

entity_fields= sg.schema_field_read('Shot').keys()
pprint(entity_fields)

Below are the field keys of entity type “Shot”

dict_keys([‘sg_delivery_resolution’, ‘sg_original_plate_resolution’, ‘open_notes_count’, ‘open_notes’, ‘notes’, ‘sg_bid_categories’, ‘sg_client_status’, ‘sg_offline_approved’, ‘step_4’, ‘created_at’, ‘smart_tail_out’, ‘sg_shot_type’, ‘image’, ‘smart_cut_out’, ‘tail_in’, ‘tail_out’, ‘head_in’, ‘head_duration’, ‘tasks’, ‘smart_head_duration’, ‘tags’, ‘sg_cut_duration’, ‘sg_cut_in’, ‘sg_cut_out’, ‘description’, ‘cut_in’, ‘cut_out’, ‘cut_duration’, ‘smart_working_duration’, ‘sg_sequence’, ‘updated_by’, ‘smart_head_out’, ‘sg_status_list’, ‘head_out’, ‘smart_cut_summary_display’, ‘project’, ‘created_by’, ‘assets’, ‘smart_head_in’, ‘tail_duration’, ‘code’, ‘smart_cut_in’, ‘smart_tail_duration’, ‘smart_duration_summary_display’, ‘updated_at’, ‘smart_tail_in’, ‘smart_cut_duration’, ‘sg_sound_dependent’, ‘step_271’, ‘step_37’, ‘step_35’, ‘step_32’, ‘step_28’, ‘step_27’, ‘step_25’, ‘step_21’, ‘step_19’, ‘step_18’, ‘step_17’, ‘step_16’, ‘step_15’, ‘step_13’, ‘step_8’, ‘step_7’, ‘step_6’, ‘step_5’, ‘step_3’, ‘step_2’, ‘step_273’, ‘step_1’, ‘sg_extra_time_requests’, ‘sg_last_version_sent’, ‘sg_status_report_notes’, ‘sg_next_schedule_delivery’, ‘sg_client_approved_for_temp’, ‘sg_prio__1’, ‘sg_prio__2’, ‘sg_latest_bt_note’, ‘sg_bt_status’, ‘sg_stephen_qc_notes’, ‘sg_dual_strip_continuity_notes’, ‘sg_sent_proposed_final_’, ‘sg_cody_qc_notes’, ‘sg_bg_character_position_check’, ‘sg_dual_strip_position’, ‘sg_need_tech_fixes’, ‘sg_need_finger_nub_eye_scar__cosmetic_updates’, ‘sg_need_lamppost_continuity_’, ‘sg_need_sky_updates’, ‘sg_need_cobblestone_updates’, ‘sg_need_blood_refinements’, ‘sg_ltd’, ‘sg_sent_for_dec__15’, ‘sg_need_embedded_mattes’, ‘sg_contextual_review_notes’, ‘sg_sent_for_wip_di’, ‘sg_need_wip_di_version’, ‘sg_workahead_notes’, ‘sg_cg_stairs_and_fence’, ‘sg_sent_temp_to_client_’, ‘sg_trailer_temp_needed’, ‘sg_comp_due’, ‘sg_keystone_shot_due’, ‘sg_cg_due’, ‘sg_dmp_due’, ‘sg_dmp_notes’, ‘sg_temp_notes’, ‘sg_oct__21_temp_updates_needed’, ‘sg_oct__21_temp_update_needed’, ‘sg_comp_notes’, ‘sg_ground_render’, ‘sg_dmp_parent’, ‘sg_dmp_parent_shot’, ‘sg_shots’, ‘sg_dmp_path’, ‘sg_production_notes’, ‘sg_framing’, ‘sg_cg_trees’, ‘sg_cg_cobblestone’, ‘sg_latest_comp_thumbnail’, ‘sg_missing_due_date’, ‘sg_missing_description’, ‘sg_screening_temp_needed’, ‘sg_angle_view’, ‘sg_bid_confirmed’, ‘sg_netflix_final’, ‘sg_sent_to_content_hub’, ‘sg_bid_check’, ‘sg_temp_due_date’, ‘sg_temp_delivered_to_client’, ‘sg_latest_client_note’, ‘sg_latest_internal_note’, ‘sg_lens_grid’, ‘sg_percent_complete’, ‘sg_client_hours’, ‘sg_sticky_notes’, ‘sg_edit_ref_nuke_nodes’, ‘sg_library_tags’, ‘sg_retime_out’, ‘sg_retime_in’, ‘sg_cg_notes’, ‘sg_task_bid_hours’, ‘sg_time_logged’, ‘sg_retime’, ‘sg_complexity_’, ‘image_blur_hash’, ‘custom_entity07_sg_shots_custom_entity07s’, ‘sg_render_resolution’, ‘sg_due_date’, ‘sg_client_code’, ‘sg_scene’, ‘sg_est_percent_complete’, ‘sg_cut_order’, ‘filmstrip_image’, ‘image_source_entity’, ‘parent_shots’, ‘shots’, ‘sg_overscan_reference_frame_number’, ‘sg_nuke_delivery_template’, ‘sg_overscan_resolution’, ‘task_template’, ‘sg_published_files’, ‘sg_vfx_description’, ‘sg_quoted_total_amount_cad’, ‘sg_overscan_comments’, ‘sg_overscan__’, ‘cached_display_name’, ‘step_0’, ‘sg_spotting_notes’, ‘addressings_cc’, ‘sg_versions’, ‘sg_working_duration’, ‘sg_tail_out’, ‘sg_head_in’, ‘sg_editorial_note’, ‘sg_shot_level’, ‘sg_annontation_main’, ‘sg_linked_slates’, ‘elements’, ‘sg_quoted_total_bid_hours’, ‘id’, ‘sg_turnover_date’, ‘sg_latestversion’, ‘sg_quoted_total_amount_usd’, ‘sg_bidhours’, ‘sg_total_bid_hours’])

relationshttps://developer.shotgridsoftware.com/python-api/reference.html?highlight=schema_field_read#operators-and-arguments

relations are used to bridge the field and your requirement in filters, you’ll see below.

full code – without fields

import shotgun_api3
from pprint import pprint

SERVER_PATH = 'https://<company>.shotgunstudio.com' #shotgun company link
LOGIN = 'bghuntla'
PASSWORD = 'password'

sg = shotgun_api3.Shotgun(SERVER_PATH, login=LOGIN, password=PASSWORD)
if __name__ == '__main__':
    entities = sg.schema_entity_read()['Shot']  # entity_type
    # pprint(entities)
    entity_field = sg.schema_field_read('Shot')
    # pprint(entity_field)
filters = [['project', 'is', {'type': 'Project', 'id': 1234}], ['created_by', 'name_contains', 'Blossom Ghuntla']]
    # since the fields are not added we can not see much
    pprint(sg.find('Shot, filters, []))  # examples
    # pprint(sg.find('Status', [], []))  # examples

[{‘id’: 38377, ‘type’: ‘Shot’},
{‘id’: 38378, ‘type’: ‘Shot’},
{‘id’: 38428, ‘type’: ‘Shot’},
{‘id’: 38429, ‘type’: ‘Shot’},
{‘id’: 38446, ‘type’: ‘Shot’},

The reason why fields and filters are in one post because they both work hand in hand.

In the above example the – pprint(sg.find('Shot, filters, [])) – last part i.e. the list is empty and it needs a field

for eg: pprint(sg.find(‘Shot’, filters, [‘created_by’])) – it would list the shot i have worked on

[{‘created_by’: {‘id’: 123, ‘name’: ‘Blossom Ghuntla’, ‘type’: ‘HumanUser’},
‘id’: 12111,
‘type’: ‘Shot’},
{‘created_by’: {‘id’: 123, ‘name’: ‘Blossom Ghuntla’, ‘type’: ‘HumanUser’},
‘id’: 12222,
‘type’: ‘Shot’},
{‘created_by’: {‘id’: 123, ‘name’: ‘Blossom Ghuntla’, ‘type’: ‘HumanUser’},
‘id’: 12333,
‘type’: ‘Shot’},
{‘created_by’: {‘id’: 123, ‘name’: ‘Blossom Ghuntla’, ‘type’: ‘HumanUser’},
‘id’: 12444,
‘type’: ‘Shot’}]

full code with fields and filters

import shotgun_api3
from pprint import pprint

SERVER_PATH = 'https://<company>.shotgunstudio.com' #shotgun company link
LOGIN = 'bghuntla'
PASSWORD = 'password'

sg = shotgun_api3.Shotgun(SERVER_PATH, login=LOGIN, password=PASSWORD)
if __name__ == '__main__':
    entities = sg.schema_entity_read()['Shot']  # entity_type
    # pprint(entities)
    entity_field = sg.schema_field_read('Shot')
    # pprint(entity_field)
filters = [['project', 'is', {'type': 'Project', 'id': 1234}], ['created_by', 'name_contains', 'Blossom Ghuntla']]
    # since the fields are not added we can not see much
    pprint(sg.find('Shot, filters, ["created_by"]))  # examples
    # pprint(sg.find('Status', [], []))  # examples

NOTE: One can use just the fields to get bulk information sg.find('Shot, [], ["created_by"])

NOTE: But one cannot just use filters to get specific results sg.find('Shot, filters, [])

Whatever field is mentioned in filter syntax, that needs to be mentioned in field as well

filters = [['project', 'is', {'type': 'Project', 'id': 1234}], ['created_by', 'name_contains', 'Blossom Ghuntla']] # since the fields are not added we can not see much pprint(sg.find('Shot, filters, ["created_by"]))

Example with multiple filters and fields

import shotgun_api3
from pprint import pprint

SERVER_PATH = 'https://<company>.shotgunstudio.com' #shotgun company link
LOGIN = 'bghuntla'
PASSWORD = 'password'

sg = shotgun_api3.Shotgun(SERVER_PATH, login=LOGIN, password=PASSWORD)
if __name__ == '__main__':
    entities = sg.schema_entity_read()['Shot']  # entity_type
    # pprint(entities)
    entity_field = sg.schema_field_read('Shot')
    # pprint(entity_field)
    filters = [['project', 'is', {'type': 'Project', 'id': 1234}], ['created_by', 'name_contains', 'Blossom Ghuntla'], ['sg_versions', 'name_contains', 'version_name']]
    # since the fields are not added we can not see much
    pprint(sg.find('Shot, filters, ['created_by', 'code', 'task_template', 'tail_duration', 'sg_versions']))  # examples
    # pprint(sg.find('Status', [], []))  # examples

Note: replace version_name with your version name

If you don’t know the version name just remove the filter, run the info with just fields and you’ll notice the version name, use the same name in the filter. You’ll get the most narrowed down results.

This is a long one. Hope this helps you to get started with fields and filters.

Shotgrid: entity_type

Hey all,

Shotgrid entity_type are really helpful to fetch data from Shotgun web.

Entity_type, Filters and fields are referred from this post. It is an amazing post, I would recommend you to read it- http://yamagishi-2bit.blogspot.com/2020/01/shotgun-shotgun-python-api-quickstart.html

One of my Colleagues from my studio Michael H, gave alot of code snippets to understand this topic.

You’ll find i have mentioned entity_type, filters and fields in the earlier post – https://digdeeperts.wordpress.com/2023/09/22/shotgrid-how-to-access-api/

This topic is related to CRUD method,

once we get access to api with the below code, we’ll try to find some data regarding the show, shot, seq, etc.

sg = shotgun_api3.Shotgun(SERVER_PATH, login=LOGIN, password=PASSWORD)
Shotgun.find(entity_type, filters, fields=None, order=None, filter_operator=None, limit=0, retired_only=False, page=0, include_archived_projects=True, additional_filter_presets=None)

Shotgun.find(entity_type, filters, fields=None) first 3 arguments will help you get almost whatever you’re looking for from Shotgun web. (arguments – entity_type, filters, fields)

Question is – How do we find the entity_type?

from pprint import pprint

entities = sg.schema_entity_read()  # entity_type
pprint(entities)

https://developer.shotgridsoftware.com/python-api/reference.html?highlight=schema_entity_read#shotgun_api3.shotgun.Shotgun.schema_entity_read

As per the docs you can provide the show entity or project entity dictionary as argument as well – {'type': 'Project', 'id': 3}

incase you don’t know the project id, you can just run the sg.find to list type project and its id

full code

import shotgun_api3
from pprint import pprint

SERVER_PATH = 'https://<company>.shotgunstudio.com' #shotgun company link
LOGIN = 'bghuntla'
PASSWORD = 'password'

sg = shotgun_api3.Shotgun(SERVER_PATH, login=LOGIN, password=PASSWORD)
if __name__ == '__main__':
    entities = sg.schema_entity_read().keys()  # entity_type
    pprint(entities)
    print(sg.find('Project', [], []))
    print(sg.find('Shot, [], []))  # examples
    print(sg.find('Status', [], []))  # examples
[{'type': 'Project', 'id': 4}, {'type': 'Project', 'id': 63}, {'type': 'Project', 'id': 64}, {'type': 'Project', 'id': 65}, {'type': 'Project', 'id': 66}, {'type': 'Project', 'id': 67}, {'type': 'Project', 'id': 70}, {'type': 'Project', 'id': 75}, .......

I have consolidated of the important aspects to get started with find and entity_type.

Useful links

https://developer.shotgridsoftware.com/python-api/_modules/shotgun_api3/shotgun.html#Shotgun.schema_entity_read

https://developer.shotgridsoftware.com/python-api/reference.html?highlight=schema_entity_read#shotgun_api3.shotgun.Shotgun.schema_entity_read

https://developer.shotgridsoftware.com/python-api/reference.html?highlight=schema_entity_read#crud-methods

https://developer.shotgridsoftware.com/python-api/reference.html?highlight=schema_entity_read#working-with-the-shotgrid-schema

Shotgrid: How to access api?

Hallo allerseits, wie geht’s?

In vfx or feature animation small to mid size studios depend on Autodesk Shotgrid. It is a management system on web and desktop. Below is the link for the page.

NOTE: (I’ll try to avoid jargon’s as much as possible or explain a little bit what the jargon is in a bracket. )

Autodesk Shotgrid

Shotgrid stores alot of artists and its files/data, we as developers at times need to access those data.(Assuming you are working with a show(show is a term used in companies which means – movie or tv series))

Again i am assuming you are working on a project and Shotgrid is your project management system

There are 2 ways to access api, that I am aware,

One is through the DCC environment i.e. – If you launch any application like Maya, Houdini, etc. and load a shot through SG(shotgrid) window, import SG module it, SG recognizes the context(basically shot info).

The other one is outside of DCC environment i.e. – without launching any application we need to access SG.

I’ll be emphasizing on the second one – outside of DCC.

Exact video that explains all of this, watch it till the end.

PERSONAL ACCESS TOKEN

import shotgun_api3

SERVER_PATH = 'https://<company>.shotgunstudio.com' #shotgun company link
LOGIN = 'bghuntla'
PASSWORD = 'password'

sg = shotgun_api3.Shotgun(SERVER_PATH, login=LOGIN, password=PASSWORD)
if __name__ == '__main__':
    filters = [['sg_status_list', 'is', 'act']]
    fields = ['id']
    users = sg.find('HumanUser', filters, fields)

    print('Total active Users:{}'.format(len(users)))

This is a small read to get you started with SG context

Some useful links to refer

https://developer.shotgridsoftware.com/python-api/cookbook/examples/basic_sg_instance.html

https://developer.shotgridsoftware.com/python-api/authentication.html#setting-up-shotgrid

https://developer.shotgridsoftware.com/python-api/reference.html?highlight=shotgun_api3#shotgun