0

Setting a local path link problems

Hi,

I'm trying to automate a field that links to the shot DIR so artists don't have to traverse the file system. I've got it working through the API but I've noticed something strange is happening. The links work just fine, but they also create references in the Shot Reference tab and if you do a search for all files there's also a link in there too. If I was to manually add the local file link these extra references aren't made. How do I stop my code from generating these extra references?

My code is pretty much the same as the 'Linking to Local Files' post on here. Is anyone else having the same outcome?

Cheers,

D.

4 comments

  • 0
    Avatar
    Alejandro Gutierrez

    Hello,

    I don't have the same problems.., however, this source may help you fix it.

    Hope it helps

    ###########

    from shotgun_api3 import Shotgun

    sg = Shotgun( "https://test.shotgunstudio.com", "Test", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" )

    myFile = {
        'this_file':{
            'local_path': '/Volumes/files/Test_New/images/photo.jpg',
            'name' : 'Test File Local'
        },
        'project': {'type':'Project','id':312},
    }

    result = sg.create("Attachment",myFile)

  • 0
    Avatar
    Dave Goodbourn

    Hi,

    Thanks for the help, but I'm not sure it'll help me, here's where I'm with my code at the moment, like I said it's working but just adding the extra references, which isn't a massive problem, I just wanted to see if I could do it without adding the references.

    ##############

    def main(projectID):
    ### Open connection to Shotgun ###
    sg = Shotgun(SERVER_PATH, SCRIPT_NAME, SCRIPT_KEY)

    ### Find all the shots ###
    fields = ['code','sg_folder_dir','project']
    filters = [
                 ['project','is',{'type':'Project','id':projectID}]
                 ]
    result = sg.find('Shot',filters,fields)

    for x in result:
         if x['sg_folder_dir'] == None:
             project_name = x['project']['name'] ### Get the project name ###
             shotID = x['id'] ### Get the shot ID of the shot ###
             shotName = x['code'] ### Get the shot Name of the shot ###

             ### Make up the individual dictionaries ###
             local_path_windows = {'local_path_windows': 'P:\\' + project_name + '\\shots\\' + shotName + '\\'}
             name = {'name': shotName}
             local_path_linux = {'local_path_linux': None}
             url = {'url': 'file://P:\\' + project_name + '\\shots\\' + shotName + '\\'}
             local_storage = {'local_storage': "{'type': 'LocalStorage', 'name': 'Projects', 'id': 3}"}
             local_path = {'local_path': 'P:\\' + project_name + '\\shots\\' + shotName + '\\'}
             content_type = {'content_type': None}
             local_path_mac = {'local_path_mac': '/Volumes/Projects/' + project_name + '/shots/' + shotName + '/'}
             link_type = {'link_type': 'local'}

             ### Join the individual dictionaries together ###
             local_path_windows.update(name)
             local_path_windows.update(local_path_linux)
             local_path_windows.update(url)
             local_path_windows.update(local_storage)
             local_path_windows.update(local_path)
             local_path_windows.update(content_type)
             local_path_windows.update(local_path_mac)
             local_path_windows.update(link_type)

             ### Update Shotgun with the correct Folder DIRs ###
             data = {'sg_folder_dir': local_path_windows}
             result = sg.update('Shot', shotID, data)

  • 0
    Avatar
    Ben Hadden

    Hi Dave,

    I passed this issue along to our tech team to have a look.  Thanks for your patience while they investigate (and if this is urgent, always feel free to email us directly at support@shotgunsoftware.com).

    Cheers,
    Ben

  • 0
    Avatar
    KP

    There's definitely some inconsistency going on here, we'll have to dig in a bit deeper. If you're uploading files for Shot References, those will always have a value in the 'filename' field. You could create an additional filter condition to filter out any files that don't have a value in that field (which would be any links). Or, as many studios will do, you can use the Type field to classify the files as "Reference" and add a filter to only show those files where type=Reference.

    I should also point out that when you're setting a field to a local path, most of those parameters are ignored. The only ones that are valid are:
    local_path
    name (optional)
    content_type (optional)

    and these are ignored:
    local_path_mac
    local_path_windows
    local_path_linux
    link_type
    local_storage

    There's some documentation about it in the "Modifying local file field values" section on this page https://github.com/shotgunsoftware/python-api/wiki/Working-With-Local-Files

    Shotgun doesn't need anything but the path to figure out the other values. Hopefully that saves you some time. We'll see what we can do about the consistency of how the links are showing up as Files.

    cheers,
    kp

    Follow us on Twitter @shotgunsoftware and @shotgunsupport

Please sign in to leave a comment.