How can I unregister folders when using a distributed config?

With a centralized config, you would normally run the tank unregister_folders command.
If you are using a distributed config however, you won’t have convenient access to a tank command.
In this situation, the easiest thing to do would be to run a simple python script from the Shotgun Python Console.

How to access the Shotgun Python Console

Here are two example snippets of code showing how to unregister folders.

# Unregister by entity
# ====================
import sgtk

# Get the entities that we want to unregister
# In this example we are unregistering all assets on the project.
entities = tk.shotgun.find("Asset",[["project.Project.id","is",86]])

# Grab the unregister command
unreg_cmd = sgtk.get_command('unregister_folders', tk)

for entity in entities:
    # Now execute the unregister command for each entity we found
    parameters = {"entity":entity}
    print "unregistering: ", entity
    unreg_cmd.execute(parameters)

or

# Unregister all
# ==============
import sgtk

#Grab the unregister command
unreg_cmd = sgtk.get_command('unregister_folders', tk)

# Set the path to point to the root of the project dir.
# This would need to be done per root on the project.
params = {"path":"/sg_toolkit/my_project"}
print unreg_cmd.execute(params)
11 Likes

So I had an asset called AssetA, I messed up on this asset and want to remove it completely. Then create a fresh new AssetA. I moved AssetA to the trash through the webUI and then I used the code above thinking that would do the trick. However, when I try to make new model file for AssetA, it gives me an error suggesting something is wrong with my templates and try unregistering folders. What is the correct procedure for removing an asset and then recreating?

2 Likes

Hey sorry I missed this reply.

Unregistering the folder should, in theory, fix it, even if the asset was trashed beforehand.
If you encounter it again, please post a new topic with some more specific details about the error and we can help dig in and understand what happened.

2 Likes

@jspeer,

I’ve also found that running this line in the python console, after you unregister folders, will clear / reset your local cache, which may clear up any issues you’re having with filesystem locations.

tk.synchronize_filesystem_structure(full_sync=True)

2 Likes

Hey folks,

Could someone please share the exact code I need to run to unregister a specific folder in a distributed setup?

Bardon me, I am new to shotgun and I don’t want to break something while I am trying.

Your help is much appreciated!

Cheers,
Osama

1 Like

Hi @Osama.Ali
It’s the same as the last unregister all example, but point it at the sub folder you want to unregister rather than the root of the project.

1 Like

Thanks for your reply @philip.scadding

just to be clear, is ‘asite’ something I need to replace with our site, or is this a hard coded syntax?

and the path is
/Volumes/VFX_Projects/Shotgun/projects/my_project/sequences/my_folder

so should I run the following?
params = {“path”:"/sg_toolkit/asite.shotgunstudio.com/my_project/my_folder"}

Sorry again, I am new to the whole thing

1 Like

The path should be whatever the path is for your folder. I’ve gone back to the original post and edited it to remove the asite.shotgunstudio.com bit, since I agree, it’s a bit confusing. It’s just in my setup I have multiple sites, so I place my roots inside folders named after the site.

If your path is /Volumes/VFX_Projects/Shotgun/projects/my_project/sequences/my_folder then that is the path you should provide.

2 Likes

Thanks again for clarification @philip.scadding

2 Likes

I’ve been having some trouble with this lately as well. I had a case where I needed to change the tank name on a project but then I would get an error when trying to open apps because the project directories were still registered.

I tried to unregister the project level directories as above but that didn’t seem to work.

In the end I found that the project name is cached in the .shotgun folder in a file called pipeline_configuration.yml. I deleted the folder accociated with the specific pipeline config and reloaded the config and everything went through ok.

Fortunately for me it was a new project so I didn’t have a bunch of artists with broken configs.

My take away is don’t edit the tank name after anyone has loaded the config!