Creating a page or filtering an existing page from the API?

I'm trying to duplicate the built in ability of Shotgun to go the the page of data you have just imported... I want to create a page or filter an existing page to show only certain shots based on what has been processed in an external script.

Does anyone have any insight into a solution?





  • 0
    Tom Stratton

    OK, did some digging interactively (gotta love Python) and I got a good start on a solution.  Here is what I have found:

    page_settings = sg.find('PageSetting', filters=[ ['page', 'is', {'type':'Page', 'id':2107}]],fields=['settings_json'] ) # 2107 was the page ID

    •  got the json settings for the page:
    json_string = page_settings[0]['settings_json']
    • replaced one of the shot codes with a different one...
    • pushed the json back to the PageSettings I took it from...

    data = {'settings_json': json_string}
    sg.update('PageSetting',3453, data) # 3453 was the ID of the PageSetting that was returned by the find

    • went back to shotgun and refreshed the page and the shot HAD been changed!
    So, I've got a place to start with this but if anyone has better methods or a reference for how to be more surgical I'd really appreciate it.
  • 0
    Tom Stratton

    More info (in case anyone else is ever interested in this topic :-)

    You can't use the standard json.dumps and json.loads commands from Python - you need to use the same simplejson that is included with the shotgun_api. Trying to use "normal" json will result in some odd unicode cross contamination that eats your changes.


    If a user makes a change to the filter in use on a page, then new page settings are created for that page - I assume that any other changes to the page would have similar effect. In order to clear back to the settings that you intend for use with the script you need to delete all page settings that link to the page except for the one that you are working with:

    sg.find('PageSetting', filters=[ ['page', 'is', {'type':'Page', 'id':2539}]],fields=[] )


    (you will delete all settings except for the lowest numbered one in the list.)


    With those two things out of the way, I am able to programmatically able to modify the page filter from a script and let the users see the results on a saved page.


    Alos worked out an alternate method where the page search looked for a flag and displayed the shots that were flagged - much simpler than the above but required me to have a multi-entity field that collected users. This made it possible for each user to have separate flags and avoid overwriting a page in use by another user.


    Despite the lack of interest/activity in this page I hope it helps someone one day...




  • 0
    Dave Sullivan

    This is awesome, just what I was looking for. Thanks so much for posting your findings.

  • 0
    Halil Mehmet

    I have been wondering how to do this for some time, so I'm glad it's possible!


    However, how would I do this for an entity detail page with different layouts?

    The URL is https://xxxx.shotgunstudio.com/detail/Asset/xxxx 

    I have no reference to a Page ID...