-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance add-on preferences with new options
- Add new preferences UI with: - An option to use another directory for images instead of the temporary directory, including another option to force use it. - An option to use subdirectory in the `.blend` file path. - An option to disable debug message. - Split multiple utilities code to to `helper.py` module. - Rewrite the `get_save_directory()` function to adapt with the new preferences and fix the "not existent directory" bug.
- Loading branch information
1 parent
5cbaed5
commit 2a99d8c
Showing
4 changed files
with
152 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import bpy | ||
|
||
|
||
ADDON_NAME = __package__.split(".")[0] | ||
|
||
|
||
def get_addon_preferences() -> bpy.types.AddonPreferences: | ||
"""Get the addon preferences. | ||
Returns: | ||
bpy.types.AddonPreferences: The addon preferences. | ||
""" | ||
import bpy | ||
|
||
return bpy.context.preferences.addons[ADDON_NAME].preferences | ||
|
||
|
||
def get_save_directory() -> str: | ||
"""Get the path to the directory where the images are saved. | ||
Returns: | ||
str: The path to the directory where the images are saved. | ||
""" | ||
from os import makedirs | ||
from os.path import exists | ||
from os.path import dirname | ||
from os.path import join | ||
|
||
preferences = get_addon_preferences() | ||
|
||
if bpy.data.filepath and not preferences.is_force_use_another_directory: | ||
directory_path = dirname(bpy.data.filepath) | ||
if preferences.is_use_subdirectory and preferences.subdirectory_name: | ||
subdirectory_path = join(directory_path, preferences.subdirectory_name) | ||
if not exists(subdirectory_path): | ||
makedirs(subdirectory_path) | ||
return subdirectory_path | ||
return directory_path | ||
if preferences.is_use_another_directory and preferences.another_directory: | ||
return preferences.another_directory | ||
return bpy.app.tempdir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters