1
$\begingroup$

Background

I have some add-on preferences in the modular tree add-on I have been contributing to.

Problem

They show up fine on my macbook with blender 2.77, but they appear to be missing on windows and linux computers using the same blender version. Any ideas as to why?

Extra Info

I have personally tested it on a windows 7 box: there are no errors and all the functionality works fine (so the add-on prefs are registering correctly). It is just impossible to change the add-on prefs without a knowledge of scripting because it doesn't show up in blender's UI.

Github repo:

https://github.com/MaximeHerpin/modular_tree

Blender Artists thread:

https://blenderartists.org/forum/showthread.php?405377-Addon-Modular-Tree&p=3101211#post3101211

What it should look like (the rest don't show anything past the "Internet: Docs Report Remove" line):

enter image description here

$\endgroup$

1 Answer 1

2
$\begingroup$

When you install the add-on from the zip provided by GitHub, Blender unpacks the zip's contents, a folder called modular_tree-master, into Blender's local add-on storage folder (the exact location varies between operating systems). The main point is that the add-on folder is no longer modular_tree, that's also the problem.

There's an assumption in this section of the code.

class TreeAddonPrefs(AddonPreferences):
    bl_idname = "modular_tree"

Hardcoding bl_idname like that assumes that the folder name (or "package name") is still "modular_tree".

There are many solutions, some more convoluted than others..

0. Renaming the content of the zip.

(don't do this, only included for completeness).

You can rename the folder inside the zip to simply modular_tree (using something like 7zip) before installing, it will display the add-on preferences correctly. But doing that is kind of a hassle, most of your users will need to do it if they aren't getting your add-on as a GIT project. you should be fixing it in one place for everyone.

1. "Monkey Patching" the __package__ name

One way to force the package name is:

# somewhere at the start of your __init__
if __name__ != "modular_tree":
    sys.modules["modular_tree"] = sys.modules[__name__]

then you can do

class TreeAddonPrefs(AddonPreferences):
    bl_idname = __package__

2. using basename and dirname of __file__

# somewhere at the top of your __init__.py
from os.path import basename, dirname

then

class TreeAddonPrefs(AddonPreferences):
    bl_idname = basename(dirname(__file__))  # directory name containing this file

The result is that it doesn't matter what the zip was called / or the eventual folder.

$\endgroup$
2
  • $\begingroup$ I am actually one of the developers as I mentioned :) The problem is that I can't use name because it is a multi-file add-on...I have not yet tried what you mentioned, but it sounds right so I'll accept your answer. I actually made the add-on preferences code that you cited, and I thought that the bl_idname for the add-on prefs would actually set the idname instead of require an existing idname. $\endgroup$
    – Jake Duth
    Commented Sep 22, 2016 at 18:25
  • $\begingroup$ Thanks for the idea, I actually already made a hot fix for the project by adding an "addon_name" module to handle this. (It saves a text file with the name it decides on for reference from other modules.) I will look into using your idea as well. $\endgroup$
    – Jake Duth
    Commented Sep 22, 2016 at 21:29

You must log in to answer this question.

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