Unable to create filesystem structure using SGTK

Hi there,

I’m trying to use the create_filesystem_structure() function within SGTK to create and register directories for an asset.

Here’s a bare-bones version of my code:

mgr = sgtk.bootstrap.ToolkitManager()
mgr.base_configuration = DESCRIPTOR_STRING
mgr.plugin_id = "basic.testplugin"
engine = mgr.bootstrap_engine("tk-shell")
tk = engine.sgtk
sg_asset = tk.shotgun.find_one("Asset", [["id", "is", 100]])
tk.create_filesystem_structure("Asset", sg_asset["id"])

I get the following stack trace when attempting to run this code in several different python environments:

Traceback (most recent call last):
  File "testscript.py", line 48, in <module>
    tk.create_filesystem_structure("Asset", sg_asset["id"])

  File "...\cfg\install\core\python\tank\api.py", line 916, in create_filesystem_structure
    folders = folder.process_filesystem_structure(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "...\cfg\install\core\python\tank\folder\operations.py", line 219, in process_filesystem_structure
    folders_created = io_receiver.execute_folder_creation()
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "...\cfg\install\core\python\tank\folder\folder_io.py", line 131, in execute_folder_creation
    rd = path_cache.synchronize()
         ^^^^^^^^^^^^^^^^^^^^^^^^
  File "...\cfg\install\core\python\tank\path_cache.py", line 360, in synchronize
    return self._do_full_sync(c)
           ^^^^^^^^^^^^^^^^^^^^^
  File "...\cfg\install\core\python\tank\path_cache.py", line 639, in _do_full_sync
    data = self._replay_folder_entities(cursor, max_event_log_id)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "...\cfg\install\core\python\tank\path_cache.py", line 909, in _replay_folder_entities
    sg_data = self._get_filesystem_location_entities(folder_ids=None)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "...\cfg\install\core\python\tank\path_cache.py", line 861, in _get_filesystem_location_entities
    "Project id: %s" % project_entity["id"]
                       ~~~~~~~~~~~~~~^^^^^^
TypeError: 'NoneType' object is not subscriptable

I’m probably missing something obvious here :slight_smile:
Any help would be much appreciated!

Your asset needs linked to a project. Check the project field on the asset on the website.

1 Like

Hey Patrick, Thanks for your response!

The asset does appear to have a project assigned to it in the project field:
image

Darren

I was able to get this working by passing in the project id to the bootstrap_engine function.

engine = mgr.bootstrap_engine('tk-shell', {'type': 'Project', 'id': PROJ_ID})

Have a nice day!

Darren