Hi there,
        I’m trying to make our add-on work when its enabled from blender 
starting up (safe as enabled in user prefs). But for some reason this doesn’t 
work. It works fine when enabled after blender has started. 
The add-on is comprised of a package with sub-packages. The parent package at 
the upper most level has its __init__ file simply import and call register on 
the sub packages as required by the environment. We have binaries in our 
package and so the sub-packages contain different builds for different 
operating systems. 

The issue is that the top level __init__ file imports the sub package it needs 
when it is registered (not when its imported), it then calls the imported 
packages register method (see package structure and code below).
The problem comes when the package is being loaded at run time, its seems that 
the package is first imported and then register is run, then unregister is run. 
This causes an issue since the cr_platform object doesn’t seem to exist when 
the package is unregistered during the enabling of the add-on at load time of 
blender. 

I wasn’t really expecting the enable process for an add-on to first load then 
unload and then load the add-on again. I really need to understand this whole 
process better to be able to either work around the issue or maybe redesign the 
package if its not compatible? I thought that what I had built didn’t violate 
anything in the python blender api as far as I can tell. 

Help would be most appreciated!!

James


Package structure 

top_level of package

__init__.py
Darwin
        __init__.py
        bl_2_78
                lib
        bl_2_79
                lib
Linux
        __init__.py
        bl_2_78
                lib
        bl_2_79
                lib
Wind64
        __init__.py
        bl_2_78
                lib
        bl_2_79
                lib
        


### contents of __init__.py at the top level

import bpy, imp, subprocess, sys, os

def select_platform():
    """ checks python/blender versions and sets import paths accordingly
    """
    
                    
    global cr_platform
    
    if sys.platform.startswith('darwin'):
        from . import Darwin as cr_platform
    elif sys.platform.startswith('linux'):
        from . import Linux as cr_platform
    elif sys.platform.startswith('win'):
        from . import Win64 as cr_platform
    else:
        raise RuntimeError(" unsupported version of python, you have :" +\
                python_version +" supported versions are 3.5.2 and 3.5.3") 
        
    

def register():
    
    select_platform()
    
    cr_platform.register()
    
    
def unregister():
    
    if 'cr_platform' in locals():
    
        cr_platform.unregister()
        
    else:
        raise RuntimeError("could not find the cr_platform while 
unregistering!")

 


if __name__ == '__main__':
    register()
_______________________________________________
Bf-python mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-python

Reply via email to