Find and get last link animation attachement mov in python

41 Views Asked by At

i’m trying to ‘save to’ a specific link in shotgun (the last animation mov founded linked in shotgun of chosen shots)

the final adress i’d like to save is: 15.22.180.80/file_serve/attachement/9430064/ALCM_552-001_025_Anim_001_003.mov

first i don’t know how to find the last animation link (the second link in page 2)

also, as you can see the adress of the mov is a bit strange for me as i doesn’t know how i can guess this part: 9430064 (last link in page 3)

i’d tryed many way to do that without any succes at all, i understand python but not shotgun, so any help or idea is welcome

enter image description here

1

There are 1 best solutions below

0
Rangoli Thakur On
def find_last_anim_link():
    entity_type = "Shot"
    entity_id = 1234
    link_field_name = "animation"
    
    #find last animation link
    filters = [
        ["entity", "is", {"type": entity_type, "id": entity_id}],
        ["sg_task", "is_not", None],
        ["type", "is", "Task"],
        ["content", "contains", "Animation"],
        ["entity.Shot.animation", "is_not", None]
    ]
    fields = ["id", "entity", "sg_task", link_field_name]
    order = [{"field_name": "created_at", "direction": "desc"}]
    result = sg.find(link_field_name, filters, fields=fields, order=order, limit=1)
    
    if result:
        last_animation_link = result[0][link_field_name]
        print("Last animation link:", last_animation_link)
    else:
        print("No animation links found.")

find_last_anim_link()