8
$\begingroup$

How do I get blenders temp folder via python (bpy).

I want to store temporary cache files while running Blender and when closing Blender I want them to be removed on exit.

$\endgroup$

1 Answer 1

9
$\begingroup$

Python's tempfile module.

First of all, Python has its own tempfile module, which is quite comprehensive and can likely do what you need
(handles creating, temp files, directories and optionally - cleaning up when you're done).

Blender's User Preference

If you want to access the temp user preference, you can do so via.
bpy.context.user_preferences.filepaths.temporary_directory
... which is initialized based on environment variables (See Environment Variables in the manual).

Blender's 'session' Temp Directory

However Blender crease a sub-directory within the temp directory, for each session, which is cleared on exit (even in the case of a crash).

And this is accessed via bpy.app.tempdir, in the case you describe, this sounds like it may be a good option.


Note that it may work well to use the tempfile module, even if you access Blender's temp directory using Blender's API.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .