0

Query All Asset names for project into string list

I'm new to shotgun and I'm looking to do something rather simple. I was wondering if someone could help me get started. 

How can I query all the asset names for a project into a string list?

In this case I'm using the demo project AAA Game, so the list returned should look something like this...

fast_run_male_01
Soldier_Crouch_Nav_FWD_839938_MocapPass
Soldier_Nav_IdleBase_MocapPass
gear_jiggle_SFX
male_infantry01_base_model
crashed_icebreaker...etc

2 comments

  • 0
    Avatar
    Sergio Fernandez

    #!/usr/bin/env python

    # --------------------------------------
    # Imports
    # --------------------------------------
    import shotgun_api3
    from shotgun_api3 import Shotgun
    import shotgun_api3 as api
    import os
    import sys
    import subprocess
    import time
    from ConfigParser import ConfigParser
    from pprint import pprint # useful for debugging

    SERVER_PATH = "your url"
    SCRIPT_NAME = 'scriptnamehere'
    SCRIPT_KEY = 'script key here'

    if __name__ == '__main__':

    sg = shotgun_api3.Shotgun(SERVER_PATH, SCRIPT_NAME, SCRIPT_KEY)

    project_name = 'your project name'

    sg_shots = sg.find("Task", [['project.Project.name', 'is', project_name]])

    result = sg_shots

    pprint(result)

  • 0
    Avatar
    Tony Aiello

    How about:

    import shotgun_api3
    from pprint import pprint as pprint

    SERVER_PATH = "your url"
    SCRIPT_NAME = "scriptnamehere" # or your shotgun login name
    SCRIPT_KEY = "script key here" # or your shotgun login password

    if __name__ == '__main__':

    sg = shotgun_api3.Shotgun(SERVER_PATH, SCRIPT_NAME, SCRIPT_KEY)

    project_name = "your project name"

    all_assets = sg.find(
    "Asset",
    filters=[
    ('project.Project.name', 'is', project_name),
    ],
    fields=[
    'code',  # 'code' is the API field name for 'Asset Name'
    ],
    )

    all_asset_names = sorted([asset.get('code', "(no name)") for asset in all_assets])
    pprint(all_asset_names)

     

Please sign in to leave a comment.