1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Query Fields for Sequences and Shots in Shotgrid

Discussão em 'Python' iniciado por Stack, Setembro 11, 2024.

  1. Stack

    Stack Membro Participativo

    I was hoping someone could help me with my code. I'm trying to get the data from the Sequences and Shots from project ID 85 in Shotgrid, specifically from the query fields sg_cut_duration and sg_ip_versions from sequences and sg_latest_version from shots but I'm just getting back None when there should be data. Can someone take a look at my code please?

    I know that you have to use the workaround my_field_config = sg.schema_field_read('Shot', 'sg_latest_version_for_delivery')['sg_latest_version_for_delivery'] since you can't access query fields client side (this is Python accessing the Shotgun API btw). Here is my code so far:

    from shotgun_api3 import Shotgun

    project_id = 85

    my_field_config = sg.schema_field_read('Shot', 'sg_latest_version_for_delivery') ['sg_latest_version_for_delivery']

    def find_sequences(project_id): filters = [['project', 'is', {'type': 'Project', 'id': project_id}]] fields = ['code', 'sg_cut_duration', 'sg_ip_versions']

    sequences = sg.summarize('Sequence', filters, fields)


    return sequences


    def find_shots_and_evaluate_fields(project_id): """ Find all shots in the given project and evaluate specific fields. :param project_id: The Shotgun project ID :return: Shots data """ filters = [['project', 'is', {'type': 'Project', 'id': project_id}]] fields = ['code', 'sg_latest_version'] shots = evaluate_query('Shot', filters, fields) return shots

    def main():

    # Find and evaluate sequences
    sequences = find_sequences_and_evaluate_fields(project_id)

    # Find and evaluate shots
    shots = find_shots_and_evaluate_fields(project_id)

    # Render results in HTML format (to be completed)
    print("Sequences:", sequences)
    print("Shots:", shots)


    if name == "main": main()

    The answer is in this statement, "You can retrieve the configuration of a query field via the API using sg.schema_field_read and then pass that config into an sg.find or sg.summarize call.

    In your case, you’d do: my_field_config = sg.schema_field_read('Shot', 'sg_latest_version_for_delivery')['sg_latest_version_for_delivery']

    Then the configuration of the query field, including the filters and the intended format of the result, will be available as a dict in: my_field_config['properties']

    You’d then need to pop keys out of that result and stuff them into an sg.summarize() call.

    This general approach avoids having to duplicate your query config in your client code, allowing you to reconfigure the query field in the UI and have your code continue to work with it without having to refactor."

    Continue reading...

Compartilhe esta Página