entity_from_path returning None

I am having a problem getting a list from entity_from_path. Is there a reason my path_cache.db would not find a path I am giving it? I am simply running the following(the file is loaded file from Nuke from the file manager):

import sgtk
fileName = nuke.root()['name'].value()
tk = sgtk.sgtk_from_path(fileName)
entity = tk.entity_from_path(fileName)
print entity
# Result:

I can launch from the Shotgun website. Also, I can use sgtk.sgtk_from_path() fine, returns api object and i can use sgkt_api_obj.project_path to get project path. 


  • 0
    Anthony Scudese

    Is the problem that my path coming from nuke.root()['name'].value() contains drive name etc. above the project's folder?

  • 0
    Ryan Mayeda

    Hi Anthony!

    The big thing to note here is that entity_from_path() only returns a value if the path you give it is an entity folder.  But, in your case, you're giving it the full path to a working file, so it's not returning anything.

    I ran your code snippet and got the same (expected) results.

    >>> import sgtk
    >>> fileName = nuke.root()['name'].value()
    >>> print fileName
    >>> tk = sgtk.sgtk_from_path(fileName)
    >>> entity = tk.entity_from_path(fileName)
    >>> print entity

    But, let's compare the results when you pass entity_from_path() an actual entity folder:

    >>> print tk.entity_from_path('/tkstudio/hosted/qa/sequences/QQ')
    {'type': 'Sequence', 'id': 45, 'name': 'QQ'}
    >>> print tk.entity_from_path('/tkstudio/hosted/qa/sequences/QQ/QQ0010')
    {'type': 'Shot', 'id': 939, 'name': 'QQ0010'}
    >>> print tk.entity_from_path('/tkstudio/hosted/qa/sequences/QQ/QQ0010/Anm')
    {'type': 'Step', 'id': 5, 'name': 'Anm'}
    >>> print tk.entity_from_path('/tkstudio/hosted/qa/sequences/QQ/QQ0010/Anm/work')

    Note how it works up until we give it the 'work' folder (i.e. a static folder), and the entity returned is the leaf folder (if it's an entity folder), which in this case is the Sequence, then the Shot, then the Step.

    Getting back to your original question though, are you expecting the entity returned to be the Shot in the example?  If so, you might try this instead:

    >>> entity = tk.context_from_path(fileName).entity
    >>> print entity
    {'type': 'Shot', 'id': 939, 'name': 'QQ0010'}

    The context_from_path() method can take your full path and split it out into the linked entity and the Step.  Then you can grab the entity from the context.

    Let me know if I'm on the right track in answering this!


Please sign in to leave a comment.