Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

AfterEffect - Clear cache script at shutdown

Community Beginner ,
Mar 04, 2019 Mar 04, 2019

Hello,

I am looking to start a disk cache cleanup script when closing After Effect.

The script is fully functional when I run it from the script executor.

However, when it is started at closing, I have the message displayed but nothing happens at the cache.

I think the problem is in the window that asks for confirmation before deletion (when it is started manually).

Do you have any ideas or solutions?

Here is the script (normally valid for CS6, CC) :

{

app.executeCommand(10200);

alert("Clear cache !");

}

Thank you in advance.

Have a good day.

Guillaume.

TOPICS
Scripting
7.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Mar 15, 2019 Mar 15, 2019

Hello,

Many thanks to justintaylor for his help.

I managed to do what I wanted as follows :

     {

          // After Effect - Cleaner Cache

          // Get the path to the cache folder and convert \ in \\ ;

          var CacheFilePath = app.preferences.getPrefAsString("Disk Cache Controls", "Folder 7")+"\\Adobe*";

          var FullCacheFilePath = CacheFilePath.split('\\').join("\\\\");

   

          // Delete my folder and these sub folders

          system.callSystem('cmd.exe /c "for /d %a in ("'+Ful

...
Translate
Valorous Hero ,
Mar 05, 2019 Mar 05, 2019

Moved to the After Effects Scripting forum.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 11, 2019 Mar 11, 2019

It appears you can't clear disk cache via scripting. You can only clear the image/undo/snapshot caches:

http://docs.aenhancers.com/general/application/?highlight=disk%20cache#app-purge

As a workaround, you could write a script that manually deletes the caches in the cache directory.

On Mac it's: /Users/[username]/Library/Caches/Adobe/After Effects

or you can find it by going to Preferences > General > Media & Disk Cache > Choose Folder

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 12, 2019 Mar 12, 2019

Hello,

Thank you very much for your answer.

The function "app.executeCommand (10200)" is functional when executing the script manually.

In fact, it directly calls the "Clear cache" in preference. (See the list here for example: http://sydefxink.com/AECC2014_MenuIDs_v2_0.pdf)

What I do not explain is that the script does not work at 100% when activating via shutdown.

I have multiple users on the same machine and each user has their own cache. This saturates the machine. I need to find a way to purge the cache after the after effect closure or the user session.

If you have ideas I am listening.

Thank you.

Guillaume.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 12, 2019 Mar 12, 2019

Yes, that command works with user input, selecting the OK button, but shutdown doesn't care about alerts and will just close them since it's shutting down After Effects. A lot of command IDs work this way, unfortunately. If there's not an API that does the same thing, then you have to get creative.

Only workaround that's coming to mind right now is looping through and deleting all the files in the system's cache folder with File.remove() / Folder.remove(), or executing a delete command via the system terminal per OS (rm -r on Mac or mrdir /s on PC) with system.callSystem().

NOTE: Be careful what you're deleting with this method, there is no undo option here.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 13, 2019 Mar 13, 2019

Hello,

Thank you so much. It's clearer to me now.

In this case, I would like to successfully discover the filepath of the cache folder via the following command:

     app.settings.getSetting ("Disk Cache Controls", "Folder 7")

This command does not seem to work and returns an error.

The script can not recover the section and the key.

Am I using the command correctly?

This value should be retrieved to be able to delete the cache via an ossystem regardless of the location setting.

Section of my preference file:

     ["Disk Cache Controls"]

     "Enabled 2" = "0"

     "Folder 7" = "C: \ Users \ AUTOMA ~ 1 \ AppData \ Local \ Temp"

     "Max Size 3" = "22"

Thanks a lot for your help!

Guillaume

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 13, 2019 Mar 13, 2019

Use getPrefAsString() after defining the Pref File:

var pft = PREFType.PREF_Type_MACHINE_SPECIFIC;

app.preferences.getPrefAsString("Disk Cache Controls", "Folder 7", pft);

See here for more details: http://docs.aenhancers.com/other/settings/

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 15, 2019 Mar 15, 2019

Hello,

Many thanks to justintaylor for his help.

I managed to do what I wanted as follows :

     {

          // After Effect - Cleaner Cache

          // Get the path to the cache folder and convert \ in \\ ;

          var CacheFilePath = app.preferences.getPrefAsString("Disk Cache Controls", "Folder 7")+"\\Adobe*";

          var FullCacheFilePath = CacheFilePath.split('\\').join("\\\\");

   

          // Delete my folder and these sub folders

          system.callSystem('cmd.exe /c "for /d %a in ("'+FullCacheFilePath+'") do rmdir "%a" /s /q"');

     }

This script was placed in the "Shutdown Script" in order to be executed at the closing of after effect (and not the closing of a project).

Warning :

Script execution preferences must be enabled.

It may happen that the Directory is not deleted because some files are used: No worry, they will be deleted at the next closing.

I remain available for advice, improvement, question or others.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 26, 2024 Feb 26, 2024

Hello Guillaume,

do you think your last script could work on cc2024? I tried it as a shutdown script but it does not work. I guess i am not understanding the ´´´  in the last line.. Is it " ´? Regards

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 02, 2024 Apr 02, 2024
LATEST

Great script, but how to add Clear Memory (RAM) into this code chain?

// After Effect - Memory

app.executeCommand(10200);

Something like this?

___
Lottie and Rive animation for your web or mobile project.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines