Here is the workflow for the add-on I’m designing:
- User download, installs, and activates add-on.
- User sets a path variable in the add-on preferences section, here the StringProperty is labeled
Environment Path
:
3. Example.zip file is installed to Environment Path
when user clicks the Install dependencies
button.
4. User quits Blender
My question: How do I store the Environment Path
string that the user just inputted so I can call it in the register() function when the user starts Blender again?
I need to check that Example.zip is installed every time the add-on is booted up, restarted, or when Blender starts so that I can display the correct panels: One panel when Example.zip isn’t installed, instructing the user on how to install it. And another panel that has the normal add-on functionality when Example.zip is installed.
I’ve tried the following methods, yet each one has it’s gotchas:
- Using Environment Variables with
os.enviorn
oros.getenv
: Environment variables are temporary to the current shell Python is running, meaning that they disappear from system memory when Blender is shutdown. - Using StringProperty() as outlined in this post: python - How do you save a variable in blender addon? - Blender Stack Exchange Unable to reference the StringProperty with
context.preferences.addons[__name__].preferences.environment_path
since context is restricted until the add-on is registered. - Storing the path in a
path_log.json
file: it’s unreliable and messy, the user must start Blender with admin permissions if the log is to be saved within the add-ons directory.
Here is an example of what I’m trying to do:
def register():
for cls in pre_dependency_classes:
bpy.utils.register_class(cls)
environment_path = some_method_to_get_var() # This is what I'm looking for
if environment_path and os.path.exists(environment_path):
for cls in classes:
bpy.utils.register_class(cls)
Thank you for reading, I’d appreciate any help I can get. Please let me know if I can further clarify anything!