0

Finding assets by project code (or ID) instead of name?

We're using the "Code" column to indicate the name of the project inside Pipeline, so I'm rewriting the ShotgunConnectionExt (pipeline plugin) to look up assets by this column instead of "name".

 

What's the filter syntax for finding assets (or shots) by project code (or ID)? I tried ["project", "is", projectID] but this fails.

 

thanks

-Mark

9件のコメント

  • 0
    Avatar
    KP

    Hey Mark,

    The syntax for filtering for Projects is a little different from how you would filter on other entities. It only requires the project name as a string (where most other entity types you would need to provide an object with the 'type' and 'id' parameters). So this should work for you:

    filters = [ ['project','is','MyProject'], ]
    result = sg.find("Asset",filters)

     

    cheers,

    kp

  • 0
    Avatar
    Mark Visser

    So to look up an asset using the project code (not the project name) I'd have to do something like this:

    [code]filters = [ ['code', 'is', 'MyProjectCode'], ]

    result = sg.find_one('Project', filters, columns=['name'])

    filters = [['project', 'is', result['name']], ]

    result = sg.find_one('Asset', filters, ...)[/code]

     

  • 0
    Avatar
    Mark Visser
    filters = [ ['code', 'is', 'MyProjectCode'], ]
    result = sg.find_one('Project', filters, columns=['name'])
    filters = [['project', 'is', result['name']], ]
    result = sg.find_one('Asset', filters, ...)
  • 0
    Avatar
    Mark Visser

    meh, how do you do preformatted on here?

  • 0
    Avatar
    KP

    Hey Mark,

    I think the syntax you are looking for is:

        filters = [ ['code', 'is', 'MyProjectCode'], ]
        project = sg.find_one('Project', filters, fields=['id'])
        filters = [ ['project', 'is', {'type':'Project', 'id':project['id']}], ]
        result = sg.find('Asset', filters)

    When filtering by entities, you need to use the syntax above to provide the 'type' and 'id'. Just a note though, the method above is going to return ALL assets for the project which is probably way more than you may need and not the best for performance. We recommend filtering as much as you sensibly can to make sure your queries results are nice and lean. If you need more guidance just let us know.


    (oh and preformatted works in the blockquote)

    cheers,
    kp

  • 0
    Avatar
    Hugh Macdonald

    And you could also do (and maybe this is new since August):

     

        filters = [ ['project.Project.code', 'is', 'MyProjectCode'] ]

        result = sg.find('Asset', filters)

  • 0
    Avatar
    marc dubrois

    Thanks for your tips Hugh. Did you know how to make a request like so :

    filters = [ ['entity.Shot.Sequence.sg_sequence', 'is', 'sequenceName'] ]
    result = sg.find('Version', filters)

    To get the version linked to a shot, linked to a sequence with the name 'sequenceName'.

  • 0
    Avatar
    Isaac Reuben

    Hey Marc,

    Try this:

    filters = [ ['entity.Shot.sg_sequence', 'name_contains', 'sequenceName'] ]
    result = sg.find('Version', filters)
    The only caveat there is that it will match any sequence that *contains* that "sequenceName" text, so if you have "seq001" and "seq001A" you wouldn't be able to search for *only* "seq001".
    Long term we want to let you do filters like this more than one link away, so in that case it would look like this:
    filters = [ ['entity.Shot.sg_sequence.Sequence.code', 'is', 'sequenceName'] ]
    But we don't support that yet!  It's on the list though.

    filters = [ ['entity.Shot.sg_sequence', 'name_contains', 'sequenceName'] ]

    result = sg.find('Version', filters)

    The only caveat there is that it will match any sequence that *contains* that "sequenceName" text, so if you have "seq001" and "seq001A" you wouldn't be able to search for *only* "seq001".

    Long term we want to let you do filters like this more than one link away, so in that case it would look like this:

    filters = [ ['entity.Shot.sg_sequence.Sequence.code', 'is', 'sequenceName'] ]

    But we don't support that yet!  It's on the list though.

  • 0
    Avatar
    marc dubrois
    thanks isaac
ログインしてコメントを残してください。